I have a specific piece of hardware which I'd like to disable and re-enable each time my Windows restarts. I created a batch script which is supposed to do that, along with running my program afterwards:
cd %~dp0
devcon.exe disable "PCI\VEN_1002&DEV_687F"
timeout /t 3
devcon.exe enable "PCI\VEN_1002&DEV_687F"
runMyWindows.exe --totally-not-virus
I am not sure if devcon.exe
is a proper application for this in the first place because I have no experience with writing Windows scripts at all.
However, I have noticed that those commands don't quite do the job because my runMyWindows.exe
program doesn't work as it should until I go to Windows Device Manager and manually disable and re-enable this device.
I have only 1 user on this machine which is in "Administrator" group and I am not running this script in any special way except double-clicking the .bat
file, or in case of the restart, it is run from the startup folder (C:\Users\oxxo\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
).
Is there a way to do this properly within my batch script which should be run automatically on Windows startup?
Due to security 'improvements' in
Windows 10
and certainly sinceWindows Vista
and the introduction ofUser Account Control
I assume you would need toRun as administrator
, not just be a member of the Administrators group.It should generally be read that
Run as administrator
meansRun as the user with the account name Administrator
notRun as any user who holds membership of the Administrators group
.To
Run as administrator
, right click on the batch file and selectRun as administrator
from the context menu.There are other ways of running as Administrator too.
PowerShell
orWSH
helper function.Task Scheduler
and choose the appropriate triggers and account information, (possibly using the SYSTEM account).Additionally you need to ensure that
DevCon.exe
is either:"%~dp0DevCon.exe" Disable "PCI\VEN_1002&DEV_687F*"
DevCon Disable "PCI\VEN_1002&DEV_687F*"
"C:\Tools\DevCon.exe" Disable "PCI\VEN_1002&DEV_687F*"
In all cases above please note the asterisk which is missing from your examples