I made a batch file with the following line
net stop audiosrv & net start audiosrv
It just flashes and closes, not actually doing the command. I think I saw something about administrator privileges in the command window but it flashed too fast to tell. What is wrong?
Create a new text file.
Then, paste the following code into it.
#echo off
net stop audiosrv
pause
net start audiosrv
pause
Save the file as a bat file.
Open the bat file as admin.
Here find a script for running a batch file as an admin
#echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
net stop audiosrv
pause
net start audiosrv
pause
A more comprehensive batch file approach:
#echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit /b)
net stop audiosrv
pause
net stop AudioEndpointBuilder
pause
net start AudioEndpointBuilder
pause
net start audiosrv
pause
The audio service is started by Windows using local system account and therefore it is not possible to stop this service without administrator privileges as command net outputs.
The solution is clicking with right (secondary) mouse button on batch file and click with left (primary) mouse button in context menu on Run as Administrator as Magoo already suggested before.
For testing a batch file just created, it is always useful to open a command prompt window and run the batch file from within this window by entering name (with path if needed) and hitting RETURN. A shortcut for opening a command prompt window can be found in Accessories menu of Windows start menu, or the command cmd.exe is executed which also opens a console window.
Related
I need to start an application with admin rights from an user account in win 10. I use a batch file to start the command window cmd.exe with admin rights and pass a batch file to this one. Unfortunately I'm not able to minimize the cmd window (needs to stay open). It is always displayed in the middle of the screen. Is there a way to show the window minimized?
batch file: start.bat:
C:\Windows\System32\runas.exe /user:administrator /savecred "C:\Windows\System32\cmd.exe /k """C:\Program Files (x86)\test.bat""" "
I have an Inno Setup installation which successfully run a batch file when finished. The batch asks for admin rights, gets them and does things.
I've been asked to completely hide the prompt window, so I've added "Flags: runhidden" in Inno Setup and #echo off and >nul 2>nul in the batch. But the batch still flash a prompt window, because of this:
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & goto
batch & exit /b)
EXIT /b
:batch
---MyCodeHere---
I have not written this code by myself and I'm not expert about batch programming, but I'm pretty sure that these lines open a new prompt with admin permissions, and that's the prompt flashing.
Does anyone know if there's a solution to this? Maybe some flag to add to "powershell start", or another completely different way to do this task.
Thank you all in advance
Don't make the batch file ask for Administrator permissions.
Run the batch file with Administrator permissions straight away:
Run process (net.exe or sc.exe) with Administrator privileges at the end of an installation in Inno Setup
[Run]
Filename: "{app}\my.bat"; Description: "Run my batch file"; \
Flags: postinstall runascurrentuser runhidden
I made a .bat file which is supposed to run Thunderbird minimized.
Here's what I put in it so far:
start /min "" C:\"Program Files (x86)"\"Mozilla Thunderbird"\thunderbird.exe runas /user:Administrator
I tried several tests:
- Removing /min
- Adding the runas option for administrator rights
- Adding the first empty quotes after start
- Writing the whole path into quotes
- ...etc.
Everything that happens is the .bat launches, but nothing furthermore happens.
I have no error in the CMD window.
Why isn't it working ??
My purpose is to put that .bat in startup folder so that Thunderbird launches minimized on startup.
I used to use an extension (MinimizeOnStartup) for Thunderbird, but it's no longer compatible with latest version and I couldn't manage to find any alternative.
I read through here, it wasn't enough to help:
A batch file to minimize other applications
Can you help me?
Thank you.
Using Windows 10.
Try the following (modify it accordingly)
cd C:\Program Files (x86)\Mozilla Thunderbird\
start /min thunderbird.exe runas /user:Administrator
A solution posted on reddit https://www.reddit.com/r/Thunderbird/comments/bnt6u3/ive_created_a_small_script_to_minimize/ ...
This is Windows only. You'll need NirCMD for this. NirCMD will trigger the "Minimize" Event after we've started Thunderbird. Get it here: https://www.nirsoft.net/utils/nircmd.html
The script:
START "" "C:\Program Files\Mozilla Thunderbird\thunderbird.exe"
timeout /T 3 /nobreak
"nircmd.exe" win min process "thunderbird.exe"
im tyring to write a bat file to ensure i am logged into a remote pc by a certain time so that some other auto processes can run on that pc.
heres where i am
cmdkey /generic:TERMSRV/server /user:**** /pass:*****
mstsc /v:server
ping 8.8.8.8 -n 10
taskkill /im mstsc.exe /f
problem im facing is that after lauching the remote pc is doesnt move to the ping until i manually close the cmd window
seems really simple, im just blanking. and if i could schedule it and save my creds in task scheduler i would, current gp doesnt allow me to.
thanks in advance.
You can call mstsc with start to run mstsc independently of the batch script.
start "" mstsc /v:server
I want to write simple Batch file will click on the batch file
I should go to my directory path should be D:\DS\Install
At present i am doing every 1hr go to
RUN command and typing to cmd and connect to D:\DS\Install
Instead of this I want short cut option.. :-)
If I understand your question correctly,
You want a shortcut on desktop which will open a command prompt and change directory to D:\DS\Install
This is pretty straight forward:
Go to C:\windows\system32 and copy cmd.exe to D:\DS\Install folder
Now right click on the cmd.exe in D:\DS\Install folder and send it to desktop create shortcut.
You will have a shortcut on desktop which will take you to the required folder everytime..
Just FYI... cmd.exe will always open from the directory where it is placed.
Just create a shortcut in your desktop, and when asked for the location, type this command
cmd.exe /k "cd /d "d:\ds\install""
This shortcut will call cmd to execute the cd to change the drive/folder and keep the window open to continue working with it.
You can also make a batch file called ds.bat and put it in c:\windows or any other folder that is on the path.
You can then use the WIN+R hotkey and type ds and enter.
#echo off
cd /d "d:\ds\install"
cmd /k
#echo off
cd /d "d:\ds\install"
cmd /k