0

I am working on a script which needs to read and write a certain value to the HKLM registry hive. While it works fine when running as a script, registry access is denied when I am running the same code as a service using SRVANY utility. The service created using SRVANY runs under the Local System context which I belive should have full access to the HKLM registry hive. When running the code as a script, it is running under an administrator account.

REG_KEY_PATH = "HKLM\SOFTWARE\AppName\ServiceConfig"
strFilename = objWshShell.RegRead(REG_KEY_PATH)

The error that I get for the above code is

Invalid root in registry key "HKLM\SOFTWARE\AppName\ServiceConfig"

ngn
  • 101
  • 3
  • SRVANY is very old, it will run the 32-bit version of the script interpreter. Which cause your script to read HKLM\SOFTWARE\Wow6432Node\AppName\ServiceConfig. Kaboom. Guessing without you posting the command line: start c:\windows\sysnative\cscript.exe instead. – Hans Passant Jul 08 '15 at 11:25
  • Thank you for a push in the right direction! I had read about registry redirection, but I did not realize even cscript had a 64-bit version. I was almost certain this would make it work, but I get the same error from both "C:\Windows\SysWOW64\cscript.exe" and "C:\Windows\System32\cscript.exe". – ngn Jul 08 '15 at 12:10
  • Can you read _any_ HKLM keys? Try something like `HKLM\SYSTEM\RNG\Seed`, which shouldn't be 32/64-bit dependent. – Bond Jul 08 '15 at 12:26
  • @HansPassant It works! I just changed it to c:\windows\sysnative\cscript.exe. Did not know that sysnative is not really an actual folder. Thank you so much for your help! EDIT: Not sure how I can mark your comment as the answer :( – ngn Jul 08 '15 at 12:32

1 Answers1

0

The trick was to use "c:\windows\sysnative\cscript.exe" to launch cscript via srvany. Full credit to Hans Passant for the answer.

Community
  • 1
  • 1
ngn
  • 101
  • 3