Search code examples
batch-filevbscriptcmdregistrywinrs

winrs reg query works but reg query hostname does not


I am trying to verify that the usbstor driver is set to disabled on a remote machine in my domain in a vbscript but I'm having issues. I've turned to troubleshooting from the command line.

Using plain old reg query fails.

reg query \\hostname\hklm\system\currentcontrolset\services\usbstor /v start
ERROR: The network path was not found.

But if I run essentially the same command with winrs, it works fine.

winrs -r:hostname reg query hklm\system\currentcontrolset\services\usbstor /v start

HKEY_LOCAL_MACHINE\system\currentcontrolset\services\usbstor
    start    REG_DWORD    0x4

Both commands work fine on other computers. What gives with this one?

Regardless of the computer I'm running the commands against, I open the firewall with this command:

winrs -r:hostname netsh advfirewall firewall set rule 
   group="Windows Management Instrumentation (WMI)" new enable=yes

Solution

  • The service RemoteRegistry is not running (or not accessible) on the remote host. You should be able to start it like this:

    sc \\hostname config RemoteRegistry start= auto
    sc \\hostname start RemoteRegistry
    

    If the service is running but still not accessible, check that the Windows Firewall allows RPC.