I need a simple way to retroactively disable/enable all USB devices in Windows 7 through a c++/c#/powershell script WITHOUT having to reboot the machine.
I understand that changing the GPO is an option but I can't seem to find any implementation that does this without a reboot.
Please explain your solution in detail, I'm new to Administration on Windows.
Using PowerShell you can do it as below
Open registry and navigate to the following registry key and see what value the reg key start has in it If its set to '3' means that USB Drive is enabled on the PC.
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\services\USBSTOR" -name start
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services
PSChildName : USBSTOR
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
Start : 3
If you want to disable it you can set the value to 4 using below command
Set-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\services\USBSTOR" -name start -Value 4
If i again check the reg key value i see that it has been modified to 4 and if i plug in a USB drive it wont get detected
Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\services\USBSTOR" -name start
PSPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\USBSTOR
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services
PSChildName : USBSTOR
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.Core\Registry
Start : 4