Sign in to follow this  
Followers 0
iceberg

@error = 1

13 posts in this topic

Hi,

I have performed a search on the forum here but the topics covered were not quite relevent. Can someone kindly enlighten me as to why this code is not working?

thanks.

code:

RunWait(@ComSpec & ' /C C:\Windows\Temp\rmvprint.bat')

If @error = 1 Then

MsgBox(16, "Error", "Network Printer was not found in this system!" & @LF & "You can only delete printers which are found in the list.")

Run('RUNDLL32 PRINTUI.DLL,PrintUIEntry /ge /c\\' & @ComputerName)

Else

MsgBox(48, 'System Settings Changes', 'Network Printer has been successfully un-installed!' & @LF & 'Press OK to reboot PC for changes to take effect.')

;Shutdown(2)

EndIf

Exit

end:

the actual problem is, when the bat file does not run properly, i get an error from Windows. My own error does not get displayed.

thank you.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites



RunWait will return the exit code of the bat file, try $ret = RunWait() and then check $ret


Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

hi Ejoc,

i saw a similar answer to yours in the Forums Search. it showed $rc = RunWait()

But I am not sure where to code it. pls help me.

thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Call the bat file directly, then you should get an error return.

RunWait('C:\Windows\Temp\ERROR.bat')
If @error = 1 Then MsgBox(0, '', 'error')

Edit: Ensure you use

Opt("RunErrorsFatal", 0)
as well.

iceberg, Helpfile has a small example.

Edited by MHz

Share this post


Link to post
Share on other sites

hi MHz,

your code works fine. i get the customized error. the code only works if the batch file does not exists.

what i am actually doing is to run a batch file to perform the following :

RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /c\\PCNAME /n\\PRINTSERVER\PRINTQ

i wanna customise the rundll32 error. not the batch file error. pls assist. thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

rundll32 error attached


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

My knowledge of handling %errorlevel% with batch is little. Whether a dllerror can can suppressed with batch language, I am unsure. Perhaps Autoit could see the window with AdlibEnable() being used, and account for it's appearance, and close it ?

Share this post


Link to post
Share on other sites

thanks for the info MHz. I was just wondering if I could just allow the dllerror to continue and at the same time make AutoIt check if "Printer User Interface" window exists.

what do you think? any suggestions?

thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

thanks for the info MHz. I was just wondering if I could just allow the dllerror to continue and at the same time make AutoIt check if "Printer User Interface" window exists.

what do you think? any suggestions?

thanks.

Sure, you could try.

Opt("MustDeclareVars", 1)

AdlibEnable('PrinterError')
RunWait('C:\Windows\Temp\rmvprint.bat')
If @error Then
    MsgBox(16, "Error", "Network Printer was not found in this system!" & @LF & "You can only delete printers which are found in the list.")
    Run('RUNDLL32 PRINTUI.DLL,PrintUIEntry /ge /c\\' & @ComputerName)
Else
    MsgBox(48, 'System Settings Changes', 'Network Printer has been successfully un-installed!' & @LF & 'Press OK to reboot PC for changes to take effect.')
EndIf
AdlibDisable()
Exit

Func PrinterError()
    If WinExists('Printer User Interface', 'Unable to delete the per machine printer connection') Then
        ControlClick('Printer User Interface', 'Unable to delete', 1); Check ControlID
    EndIf
EndFunc
Check the ControlID of the ControlClick(). I would assume something like this may help ?

:(

Edited by MHz

Share this post


Link to post
Share on other sites

hi MHz,

your code works fine. i get the customized error. the code only works if the batch file does not exists.

what i am actually doing is to run a batch file to perform the following :

RUNDLL32 PRINTUI.DLL,PrintUIEntry /gd /c\\PCNAME /n\\PRINTSERVER\PRINTQ

i wanna customise the rundll32 error. not the batch file error. pls assist. thanks.

<{POST_SNAPBACK}>

The error is generated from PrintUI.DLL not rundll32, so I dont think you can customize it.

Start -> Programs -> AutoIt v3 -> AutoIt Help File -> Index -> (The Function you are asking about)----- Links -----DllStruct UDFsRSA Crypto UDFs

Share this post


Link to post
Share on other sites

Thanks for the info MHz and Ejoc!


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

Hi MHz,

you codes didn't work for me. I don't where I went wrong. but i was thinking if its possible to do it in another way:

$var1 = RegEnumVal("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Devices", 1)
    $var2 = RegEnumVal("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Devices", 2)
    $var3 = RegEnumVal("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Devices", 3)
    $var4 = RegEnumVal("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Devices", 4)
    $var5 = RegEnumVal("HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Devices", 5)
    
    If $var1 or $var2 or $var3 or $var4 or $var5 = $PARENT & "\" & $PRINTQ or $SERVERNAME & "\" & $PRINTQ Then

    RunWait('C:\Windows\Temp\rmvprint.bat')
    MsgBox(48, 'End Result', 'Network Printer has been successfully un-installed!' & @LF & 'Press OK to reboot PC for changes to take effect.')
;   FileDelete('C:\Windows\Temp\*.bat')
;   Shutdown(2)
    
    Else
    MsgBox(16, 'Error', 'Specified Network Printer Not Found.')
    Run('RUNDLL32 PRINTUI.DLL,PrintUIEntry /ge /c\\' & @ComputerName)
    EndIf
    Exit

And this is also not working. I guess might need some expert tweaking. Can someone pls help me here?

Thanks.


mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites

hi,

i have managed to resolve this problem finally. kindly ignore earlier post. I managed to figure out Ejoc's code after reading Larry's post in

Thread

Thank you all!


mouse not found....scroll any mouse to continue.

Share this post


Link to post
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
Sign in to follow this  
Followers 0