DoctorX Posted August 26, 2005 Share Posted August 26, 2005 Hi all- I'm new to this board and to AutoIT but I've been incredibly impressed with its functionality and the ease and speed in which I have been able to learn it. Still having a couple problems with the script that I am writing that I can't find a way around though, related to calling files that may not exist: 1) I need to run a file from the CD drive using the "Run" function. No problem doing so if the CD is there, but if the CD is not inserted the script terminally faults. I've tried prefacing the line in the code with "If FileExists (D:\) ...", but even this causes a fault. Any way around this? 2) I need to access a registry key that may or may not exist. If I try to read the key usind the "RegRead" function, and the key does not exist, the script terminally faults. Any way of checking to see if the key exists before trying to read it (similar to a "FileExists" function)? Thanks in advance for any help and I'm sure these aren't the last questions I will have... -DRX Link to comment Share on other sites More sharing options...
Raindancer Posted August 26, 2005 Share Posted August 26, 2005 Could you post the exact error messages or screenshots of em? Caus regRead tells you in the return value that it wasn't able to read. and so does FileExist. And the Script itself would also help to help you :-) Say: "Chuchichäschtli"My UDFs:_PrintImage UDF_WinAnimate UDFGruess Raindancer Link to comment Share on other sites More sharing options...
/dev/null Posted August 26, 2005 Share Posted August 26, 2005 1) I need to run a file from the CD drive using the "Run" function. No problem doing so if the CD is there, but if the CD is not inserted the script terminally faults. I've tried prefacing the line in the code with "If FileExists (D:\) ...", but even this causes a fault. Any way around this? yes, use DriveStatus( ) to figure out if the cd-rom drive is READY. If so, check with FileExists() if the required binary is on the CD.2) I need to access a registry key that may or may not exist. If I try to read the key usind the "RegRead" function, and the key does not exist, the script terminally faults. RegRead sets the macro @error (see help file). Check @error to figure out if the key exists or not.@error flag: 1 if unable to open requested key -1 if unable to open requested value -2 if value type not supported if @error = 1 then do_something() elsif @error = -1 then do_something_different() elsif @error = -2 then do_something_completely_different() endifCheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
LxP Posted August 26, 2005 Share Posted August 26, 2005 Adding opt("runErrorsFatal", 0) near the beginning of your code will prevent a bad Run() from terminating your script. You can then see if the Run() worked by checking @error:opt("runErrorsFatal", 0) run("nonExistent.exe") if @error then msgBox(0x10, "Error", "Could not run nonExistent.exe!") exit endIf Link to comment Share on other sites More sharing options...
DoctorX Posted August 26, 2005 Author Share Posted August 26, 2005 Thanks Kurt & Alex, both questions answered! -DRX Link to comment Share on other sites More sharing options...
DoctorX Posted August 27, 2005 Author Share Posted August 27, 2005 I've re-written the script, and set RunErrorsFatal to 0, but now this brings up a new question. Here is a snipet of the code I am writing: ; Open RegEdit: Run ("regedit") ActWin ("Registry Editor", "") ; Export existing F4Patch Registry Entry to active version "\F4DP" folder and delete the Registry Entry: RegRead ("HKEY_CURRENT_USER\Software\F4Patch", "") If @error <> (1 OR -1 OR -2) Then Send ("!F") Send ("E") ActWin ("Export Registry File", "Save &in:") Send ($InstDir & "\F4DP\F4Patch.reg") Send ("!E") Send ("HKEY_CURRENT_USER\Software\F4Patch") If FileExists ($InstDir & "\F4DP\F4Patch.reg") Then Send ("{ENTER}") ActWin ("Export Registry File", "&Yes") Send ("!Y") WinWaitClose ("Export Registry File", "&Yes") Else Send ("{ENTER}") EndIf RegDelete ("HKEY_CURRENT_USER\Software\F4Patch") EndIf This goes on and does the same for a few other registry keys, and then exits regedit. So my question is, Where do I place the following line to check if there was a RunError with regedit: If @error = 1 Then ErrorFunc ("Run Error with RegEdit") EndIf Would I put this right after Run ("regedit"), after the line where regedit is closed, or both? (KIM the @error flag could be set by something else in between) -DRX Link to comment Share on other sites More sharing options...
LxP Posted August 27, 2005 Share Posted August 27, 2005 (edited) Welcome to the forums!Yes, you would check the @error macro immediately after the Run() command.One line I noticed in particular:If @error <> (1 OR -1 OR -2) Thenwill not work as you expect. The correct way to code that line would be:if (@error <> 1) and (@error <> -1) and (@error <> -2) thenYou could also do one of these as there are no other error codes:if (@error = 0) then if not(@error) thenOne other thing: you can achieve the same result rather simply by calling RegEdit with some command line switches and then calling RegDelete():; lacks the error handling from your original script $export = $instDir & "\F4DP\F4Patch.reg" $key = "HKEY_CURRENT_USER\Software\F4Patch" $cmdLine = stringFormat('regedit /e "%s" "%s"', $export, $key) runWait($cmdLine) regDelete($key) Edited August 27, 2005 by LxP Link to comment Share on other sites More sharing options...
DoctorX Posted August 28, 2005 Author Share Posted August 28, 2005 Wow! Thanks again Alex, you've been incredibly helpful. -DRX Link to comment Share on other sites More sharing options...
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