Jump to content

REG EXPORT cannot find 64-bit keys


Go to solution Solved by jguinch,

Recommended Posts

I am creating a program to find and delete extraneous Microsoft Office license keys. As a safety feature, I have the program export each extra key found via this command:

Local $iPID = Run(@ComSpec & " /c REG EXPORT " & $LicensePath64 & " " & Chr(34) & @ScriptDir & "\Logs\" & $arrExtraLicense[$i][1] & ".reg" & Chr(34) & " /y", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

I am running Windows 7 64-bit, so I have test keys in both HKLMSOFTWAREMicrosoft... and HKLMSOFTWAREWow6432NodeMicrosoft... The command exported the keys in Wow6432Node just fine, but the other keys produce this error: "The system was unable to find the specified registry key or value."

To make sure I wasn't making any mistakes, I had the program write the command to the log file:

C:\Windows\system32\cmd.exe /c REG EXPORT HKLM\SOFTWARE\Microsoft\Office\14.0\Registration\{90140000-003A-0000-1000-0000000FF1CE} "C:\Users\tdickinson\Documents\K1000 Scripts\Microsoft Key Remover\Logs\Microsoft Office Project Standard 2010.reg" /y

 and copy/pasted it into a CMD window. It worked perfectly, both with and without admin rights. I have #RequireAdmin included, so I can't think it's a permissions error. What am I doing wrong?

Full loop code below: 

For $i = 0 to $iRows - 1

      $ver = StringMid($arrExtraLicense[$i][0], 3, 2)
      $bit = StringMid($arrLicense_GUID[$i][0], 20, 1)

      If @OSArch <> "X64" Then
         $LicensePath = "HKLM\SOFTWARE\Microsoft\Office\"&$ver&".0\Registration\{"&$arrExtraLicense[$i][0]&"}"
      ElseIf $bit = 1 Then
         $LicensePath = "HKLM64\SOFTWARE\Microsoft\Office\"&$ver&".0\Registration\{"&$arrExtraLicense[$i][0]&"}"
      ElseIf $bit = 0 Then
         $LicensePath = "HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\"&$ver&".0\Registration\{"&$arrExtraLicense[$i][0]&"}"
      EndIf

      RegRead($LicensePath,"")

      If @error = 0 Or @error = -1 Then

         If @OSArch <> "X64" Then
            FileWriteLine($fLog, @CRLF & "Key Found for " & $arrExtraLicense[$i][1] & ": " & $LicensePath & @CRLF)

            Local $iPID = RunWait(@ComSpec & " /c REG EXPORT " & $LicensePath & " " & Chr(34) & @ScriptDir & "\Logs\" & $arrExtraLicense[$i][1] & ".reg" & Chr(34), "", @SW_HIDE)

         Else
            $LicensePath64 = StringTrimLeft($LicensePath, 6)
            $LicensePath64 = "HKLM" & $LicensePath64

            FileWriteLine($fLog, @CRLF & "Key Found for " & $arrExtraLicense[$i][1] & ": " & $LicensePath64 & @CRLF)

            Local $iPID = Run(@ComSpec & " /c REG EXPORT " & $LicensePath64 & " " & Chr(34) & @ScriptDir & "\Logs\" & $arrExtraLicense[$i][1] & ".reg" & Chr(34) & " /y", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

            ;;;;;;;;;;;;;;;;
            ;Error Checking
            ;;;;;;;;;;;;;;;;

            Local $command = @ComSpec & " /c REG EXPORT " & $LicensePath64 & " " & Chr(34) & @ScriptDir & "\Logs\" & $arrExtraLicense[$i][1] & ".reg" & Chr(34) & " /y"
            ProcessWaitClose($iPID, 10)
            Local $msgExport = StdoutRead($iPID)
            Local $msgExportError = StderrRead($iPID)
            If $msgExport <> "" Then
               MsgBox(0, "Stdout Read:", $msgExport)
            ElseIf $msgExportError <> "" Then
               MsgBox(0, "Stderr Read:", $msgExportError & @CRLF & $command)
               FileWriteLine($fLog, $command)
            EndIf

         EndIf

         FileWriteLine($fLog, "Key backup saved to " & @ScriptDir & "\Logs\" & $arrExtraLicense[$i][1] & ".reg")

         RegDelete($LicensePath)

         If @error Then
            FileWriteLine($fLog, @TAB & "RegDelete Error " & @error & ": Problem deleting key." & @CRLF)
            $msgError = $msgError & $arrExtraLicense[$i][1] & @CRLF
         Else
            FileWriteLine($fLog, @TAB & "Key Deleted." & @CRLF)
            $msgDeleted = $msgDeleted & $arrExtraLicense[$i][1] & @CRLF
         EndIf

      EndIf

   Next
Link to comment
Share on other sites

  • Solution

Because your script runs a x86 cmd, the reg query cannot find the x64 hive into the registry.

Try to launch the native cmd, using @WindowsDir & "Sysnativecmd.exe" instead of @ComSpec

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...