mr-es335 Posted February 12 Posted February 12 (edited) Hello, I have the following...first, the AddMe.reg file I am attempting to import: Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\First_Level] [HKEY_CURRENT_USER\Software\First_Level\Second_Level] "Third_Level"="The Third_Level data..." Second, the script: #include <MsgBoxConstants.au3> $sResult = Run('REGEDIT /S "C:\Working\AddMe.reg"') ConsoleWrite($sResult & @CRLF) If $sResult = 0 Then MsgBox($MB_OK, "", "The RegKey WAS NOT imported successfully!") Else MsgBox($MB_OK, "", "The RegKey WAS imported successfully!") EndIf The result: "The RegKey WAS imported successfully!" However, this update to the filename also generates the same end result!! #include <MsgBoxConstants.au3> $sResult = Run('REGEDIT /S "C:\Working\AddMe1.reg"') ; Changed the filename! ConsoleWrite($sResult & @CRLF) If $sResult = 0 Then MsgBox($MB_OK, "", "The RegKey WAS NOT imported successfully!") Else MsgBox($MB_OK, "", "The RegKey WAS imported successfully!") EndIf Removing the /S shows that the import was NOT successful!! How do I error check the above?? PS: Should I be error checking the result of "Run" [...which is what I thought that I was supported to be doing...] ...or to employ some "other" method? Edited February 12 by mr-es335 Addition mr-es335 Sentinel Music Studios
mr-es335 Posted February 12 Author Posted February 12 An attempt... ; ----------------------------------------------- AddRegKey() DoesRegKeyExist() ; ----------------------------------------------- Func AddRegKey() RunWait('REGEDIT /S "C:\Working\AddMe.reg"') EndFunc ;==>AddRegKey ; ----------------------------------------------- Func DoesRegKeyExist() Local $sKeyname = "HKEY_CURRENT_USER\Software\First_Level" ; ----------------------------------------------- RegRead($sKeyname, "") ; ----------------------------------------------- If @error = 1 Then SplashTextOn("NOTICE!!", "The $sKeyname " & $sKeyname & " DOES NOT exist!", 800, 50, -1, -1) Sleep(3000) SplashOff() Else SplashTextOn("NOTICE!!", "The $sKeyname " & $sKeyname & " DOES exist!", 800, 50, -1, -1) Sleep(3000) SplashOff() EndIf EndFunc ;==>DoesRegKeyExist ; ----------------------------------------------- However, why is it that I am apparently unable to error check the result of the "Run" command? mr-es335 Sentinel Music Studios
water Posted February 12 Posted February 12 (edited) I suggest to use functions provided by AutoIt as long as they do the job. AutoIt returns enough information to debug the script in case of an error. Implementing external programs into your script is - most of the time - much harder and time consuming. I had a quick look at your script and will post my reply as a quiz: @error is set to 0 whenever a function is entered. ConsoleWrite is a function Can you find the error in your script? Edited February 12 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
IronFine Posted February 12 Posted February 12 23 minutes ago, water said: I suggest to use functions provided by AutoIt as long as they do the job. AutoIt returns enough information to debug the script in case of an error. Implementing external programs into your script is - most of the time - much harder and time consuming. I had a quick look at your script and will post my reply as a quiz: @error is set to 0 whenever a function is entered. ConsoleWrite is a function Can you find the error in your script? According to the help from ConsoleWrite: The @error and @extended are not set on return leaving them as they were before calling. Usefull when debugging with the SciTE debugging output. 1 hour ago, mr-es335 said: #include <MsgBoxConstants.au3> $sResult = Run('REGEDIT /S "C:\Working\AddMe1.reg"') ; Changed the filename! ConsoleWrite($sResult & @CRLF) If $sResult = 0 Then MsgBox($MB_OK, "", "The RegKey WAS NOT imported successfully!") Else MsgBox($MB_OK, "", "The RegKey WAS imported successfully!") EndIf Change Run with RunWait and it will be okay.
water Posted February 12 Posted February 12 Oops, my mistake! Consolewrite seems to be the famous exception to the rule My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
mr-es335 Posted February 12 Author Posted February 12 (edited) IronFine, So, I did as yo suggested, however, when I say that I "Changed the filename!"...I meant that I changed the name in the script only...not the actual filename. The filename is still AddMe.reg. Changing Run to RunWait still tells me that the import was successful? • I DID notice however, that changing Run to RunWait does display what I believe to be the actual return code from Run! • If this IS TRUE, then how do I check the return code from "Regedit"? Wait a minute... Return Value Success: The exit code of the program that was run. So, the exit code is being displayed as "0" - which infers that Regedit is returning "success"?!? • I came across this: "regedit doesn't return a status code. Use reg.exe with the import subcommand instead". • So, where is the "0" coming from? Edited February 12 by mr-es335 mr-es335 Sentinel Music Studios
mr-es335 Posted February 12 Author Posted February 12 Hello, Well, I just may have "...fig'urd tis owt fer meslf!" Apparently regedit.exe does not return error codes...but reg.exe does! [Click_Me1] and [Click_Me2] So, this is what I came up with: #cs reg.exe return codes (ERRORLEVEL) 0 = Success, the result is identical 1 = Failed 2 = Success, the result is different #ce #include <MsgBoxConstants.au3> ;$sResult = RunWait('reg import "C:\Working\AddMe.reg"') ; Generates a "0" ;$sResult = RunWait('reg import "C:\Working\AddMe1.reg"') ; Generates a "1" ConsoleWrite("Error code is: " & $sResult & @CRLF) If $sResult = 0 Then MsgBox($MB_OK, "", "The RegKey WAS imported successfully!") Else MsgBox($MB_OK, "", "The RegKey WAS NOT imported successfully!") EndIf Note: Simply uncomment the appropriate line to get the appropriate error code. Question: Is the above a workable solution? mr-es335 Sentinel Music Studios
mr-es335 Posted February 12 Author Posted February 12 (edited) Even better: #include <MsgBoxConstants.au3> $sRegKey = "C:\Working\AddMe.reg" ;$sResult = RunWait('reg import ' & $sRegKey) $sResult = RunWait('reg import ' & $sRegKey, "", @SW_HIDE) ConsoleWrite("Error code is: " & $sResult & @CRLF) If $sResult = 0 Then MsgBox($MB_OK, "", "The RegKey WAS imported successfully!") Else MsgBox($MB_OK, "", "The RegKey WAS NOT imported successfully!") EndIf So far...all appears to be working as it should!! Main take-away...I AM beginning to see the importance and|or significance of error checking!!! Edited February 12 by mr-es335 mr-es335 Sentinel Music Studios
IronFine Posted February 12 Posted February 12 Sorry, when I was testing I was using reg instead of regedit. Didn't see that, when I was commenting. Make sure to put the filename in quotes, in case you have a whitespace in the filename.
mr-es335 Posted February 13 Author Posted February 13 (edited) IronFine, So, can regedit be employed then? I have been unable to get regedit /s to work! As far as I have been able to ascertain, regedit does not have a return code. Edited February 13 by mr-es335 mr-es335 Sentinel Music Studios
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