Reputation: 51
First of all, sorry if my description of the problem is off. The problem I'm having is that when I run a command within my batch file, it opens another console window, displays the result for a fraction of a second, then closes again. I would like to have the result of the command (devcon status) displayed in that window with something like a "pause" option.
Here's the code:
@ECHO off
cls
:start
ECHO.
ECHO What would you like to do?
ECHO 1. Disable Bluetooth
ECHO 2. Enable Bluetooth
ECHO 3. Check status
ECHO 4. Quit
ECHO.
set /p choice=Type the first word of the option you want.
ECHO.
if %choice%==Disable (
goto :DBt
) else if %choice%==Enable (
goto :EBt
) else if %choice%==Check (
goto :CS
) else if %choice%==Quit (
goto :end
) else (
echo Invalid choice.
pause
goto start
)
:DBt
devcon disable *REV_7869
goto end
:Ebt
devcon enable *REV_7869
goto end
:CS
devcon status *REV_7869
goto end
:end
exit
When I type in "Check," it will open another console window, run the devcon status command correctly, but immediately close the window when it has the result.
When I run "devcon status [my adapter id]" through the command prompt, it will return "1 device found.... driver running." When I do it from the batch file, however, it opens a new window which closes instantly after the command has run, not allowing me to see the result of it.
Adding "pause" after "devcon status *REV" didn't help the problem. It just put "Press any key to continue" in the original command window after the other one had run the command and closed.
So my question is how can I keep that second window open after the command has run?
Upvotes: 4
Views: 4390
Reputation: 30504
devcon.exe
requires elevated privileges. If you run your script from a non-elevated command window you may receive a UAC prompt ("Do you want to run this?"). When you confirm then a new Administrator command window is opened, devcon.exe
runs to completion, and the command window closes.
Run your script from an already-elevated prompt. Then you will see the output from devcon.exe
directly in your console.
Upvotes: 0
Reputation: 37
Can't you just put "pause" after the commands, to show the output? If it ignores the pause, then it most likely is a bug. If it is a bug, put pause after every command, and slowly go past everything to find the error.
Upvotes: 1
Reputation: 37569
you might try to use the start
command and not to use :start
as a jump label:
start "" /b "devcon" disable *REV_7869
I do not know defcon
and also not know why you get a second cmd
window.
Upvotes: 0