HockeyFan Posted December 12, 2008 Posted December 12, 2008 (edited) Hello! I've created a script that tests for a registry key and I want to check the @error value when it fails. I've tested this on a registry key that I know does not exist and the @error value still comes back as zero. Can someone offer some advice as to why or what I'm doing wrong! Thanks! $Log = FileOpen("C:\RegReadTest.txt", 9) $RunOnceRegCheck = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", "Test");Check to see if RunOnce registry entry exists. MsgBox(0,"",$RunOnceRegCheck) MsgBox(0,"",@error) If $RunOnceRegCheck = "C:\Software\Test.exe" Then;Success FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " RunOnce Registry key already exists." & @CRLF) Else;Failure FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " RunOnce Registry key DOES NOT exists." & @CRLF) If @error = 1 Then FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " ...unable to open requested key." & @CRLF) If @error = 2 Then FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " ...unable to open requested main key." & @CRLF) If @error = 3 Then FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " ...unable to remote connect to the registry." & @CRLF) If @error = -1 Then FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " ...unable to open requested value." & @CRLF) If @error = -2 Then FileWriteLine($Log, @YEAR & "/" & @MON & "/" & @MDAY & "-" & @HOUR & ":" & @MIN & ":" & @SEC & " ...value type not supported." & @CRLF) EndIf FileClose($Log) Edited December 12, 2008 by HockeyFan
Kerros Posted December 12, 2008 Posted December 12, 2008 I believe what is happening is that the message box is clearing the error, when I try this code I get an error of -1 in the first message box, and a 0 in the second. ;~ $Log = FileOpen("C:\RegReadTest.txt", 9) $RunOnceRegCheck = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce", "Test");Check to see if RunOnce registry entry exists. MsgBox(0,"",$RunOnceRegCheck&'Error'&@error) MsgBox(0,"",@error) Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.
HockeyFan Posted December 12, 2008 Author Posted December 12, 2008 ...it was the FileWriteLine. Once I moved it down after the If @error statement, I was able to see the @error flag value. Thank you for clearing the fog and pointing me in the right direction.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now