-2

I'm trying to run a simple query on network computers to get their Windows' version. This command runs, and returns expected results, when used from the command line:

psexec \\comp_name reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ReleaseId

but when run from Perl using:

system("psexec \\\\$comp_name reg query 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion' /v ReleaseId")

I get the error from REG ERROR: Invalid key name. Considering that both commands are the same, I cannot figure out why I am getting an error when running it from Perl. My only assumption is the way it's resolving the quotes. Note that this problem persists regardless of whether I use system, exec, or ``. Any suggestions?

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Geoffrey H.
  • 160
  • 2
  • 17

1 Answers1

3

You need to double up all of the backslashes:

system("psexec \\\\$comp_name reg query 'HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion' /v ReleaseId")
Gerhard
  • 22,678
  • 7
  • 27
  • 43