deltron Posted February 3, 2006 Posted February 3, 2006 (edited) Is it possible to use RunWait with Send() to send keys? I can use Run, but I need to get the exit code of the program for logging purposes. If I use Run(), I am able to send keys, which I need to send keys, since I cannot do this uninstall unattended. If I replace Run with RunWait, I'm not able to send any keys, because RunWait is expecting the app to close before continuing on the script. The reason I'd prefer to use RunWait, is so that I can capture the correct exit code for logging purposes, in case of any problems. Here's an example, not my whole code. expandcollapse popup$myapp = "Mozilla Firefox"; see the name of program in Add/Remove? Put it here $PID = ProcessExists("firefox.exe"); Will return the PID or 0 if the process isn't found. If $PID Then ProcessClose($PID) $UNINSTALLSTRING = GetUninstallString($myapp) If Not @error Then $ReturnCode = RemoveApp($UNINSTALLSTRING) EndIf Func RemoveApp($removeapp) RunWait($removeapp) WinWaitActive("Mozilla Firefox Uninstaller", "&Yes") Send("!y") If WinWaitActive("Attention", "&Yes") Then Send("!y") EndIf EndFunc Func GetUninstallString($app) $key = "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" $i = 0 While 1 $i = $i + 1 $subkey = RegEnumKey($key, $i) If @error Then ExitLoop $displayname = RegRead($key & "\" & $subkey, "DisplayName") If @error Then ContinueLoop If StringLeft($displayname, 15) == $app Then Return RegRead($key & "\" & $subkey, "UninstallString") EndIf WEnd SetError(1) Return "" EndFunc ;==>GetUninstallString thanks edit: clarifying a little more. Edited February 7, 2006 by Ryan Grelck
cdkid Posted February 3, 2006 Posted February 3, 2006 well uhh probably not muuch help here but where u have if StringLeft($displayname, 15) == $app then ... u might want if StringLeft($displayname, 15) = $app then ... --hope this helps a bit ~cdkid AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!
BigDod Posted February 7, 2006 Posted February 7, 2006 anyone?If you look at the RunWait example in the help file you will see how to get the exit code. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
deltron Posted February 7, 2006 Author Posted February 7, 2006 well my issue is that I cannot use send() while using RunWait, as stated in my first post
BigDod Posted February 7, 2006 Posted February 7, 2006 well my issue is that I cannot use send() while using RunWait, as stated in my first post If you are looking to send the exit codes then that means that the RunWait has to finish before there are any exit codes. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
deltron Posted February 7, 2006 Author Posted February 7, 2006 I clarified my original post, hopefully this will explain more.
BigDod Posted February 7, 2006 Posted February 7, 2006 Here is an example of what I meant $val=RunWait("calc.exe") MsgBox(0,"Exit Code", $val) Run("notepad.exe") WinWaitActive("Untitled") Send("The exit code was " & $val) Run script then close the calculator. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
deltron Posted February 7, 2006 Author Posted February 7, 2006 RunWait works fine with the unattended installs, but since this is for an uninstall that needs to have buttons pushed, that is why I'm looking for a solution/advice to try and get it working. The uninstall function in my script works just fine if you replace RunWait with Run, which then pushes the necessary buttons. I'm really looking for this in the future, because RunWait works fine with my unattended installs, but the ones that need to have buttons pushed are the ones that I am looking for a solution for. thanks BD
Danny35d Posted February 7, 2006 Posted February 7, 2006 (edited) I have not tested but give it a try... expandcollapse popup;Check for any parameters pass to the script If $CmdLine[0] > 0 Then For $x = 1 To $CmdLine[0] If $CmdLine[$x] == '/Remove' Then RunWait($CmdLine[$x + 1]) Next Exit EndIf $myapp = "Mozilla Firefox"; see the name of program in Add/Remove? Put it here $PID = ProcessExists("firefox.exe"); Will return the PID or 0 if the process isn't found. If $PID Then ProcessClose($PID) $UNINSTALLSTRING = GetUninstallString($myapp) If Not @error Then $ReturnCode = RemoveApp($UNINSTALLSTRING) EndIf Func RemoveApp($removeapp) If @Compiled Then Return(Run(@ScriptFullPath & ' /Remove "' & $removeapp & '"')) Else Return(Run(@AutoItExe & ' "' & @ScriptFullPath & '" /Remove "' & $removeapp & '"')) EndIf WinWaitActive("Mozilla Firefox Uninstaller", "&Yes") Send("!y") If WinWaitActive("Attention", "&Yes") Then Send("!y") EndIf EndFunc Func GetUninstallString($app) $key = "HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall" $i = 0 While 1 $i = $i + 1 $subkey = RegEnumKey($key, $i) If @error Then ExitLoop $displayname = RegRead($key & "\" & $subkey, "DisplayName") If @error Then ContinueLoop If StringLeft($displayname, 15) == $app Then Return RegRead($key & "\" & $subkey, "UninstallString") EndIf WEnd SetError(1) Return "" EndFunc;==>GetUninstallString Edit: Fixed typo Edited February 7, 2006 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
DaveF Posted February 7, 2006 Posted February 7, 2006 Example, uses Win32 calls to get process handle from PID and check exitcode afterward. Dim $placeholder ; Run child process and save PID $process = Run(@ScriptDir & "\whatever.exe") ; Get a process handle for the PID ; THIS MUST BE DONE BEFORE THE PROCESS EXITS $ourCall = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", 0x400, "int", 0, "int", $process) MsgBox(0, "Debug", "Obtaining exit code for PID: " & $process) If Not IsArray($ourCall) Then ;Failure, bad DLL or function name Else If Not $ourCall[0] Then ;Failure, OpenProcess failed Else ; Handle to process was returned in array index 0 $ourHandle = $ourCall[0] ; Do whatever you need to do... ; Finish... ; Then get Exit code $ourCall = DllCall("kernel32.dll", "ptr", "GetExitCodeProcess", "ptr", $ourHandle, "int_ptr", $placeholder) MsgBox(0, "Debug", "Process exited with code: " & $ourCall[2]) EndIf EndIf Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.
seandisanti Posted February 7, 2006 Posted February 7, 2006 if you can't think of anything else, you could have one script that sends the key presses, and one that does the runwait. example: ;this one sends keys WinWaitActive("installer window title","and text") ;then code for sends etc and: Run("OtherScript.exe") RunWait("Installer") ;then other code, including the exit code handler that will go to work when the other script finishes the install
deltron Posted February 7, 2006 Author Posted February 7, 2006 Example, uses Win32 calls to get process handle from PID and check exitcode afterward. Dim $placeholder ; Run child process and save PID $process = Run(@ScriptDir & "\whatever.exe") ; Get a process handle for the PID ; THIS MUST BE DONE BEFORE THE PROCESS EXITS $ourCall = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", 0x400, "int", 0, "int", $process) MsgBox(0, "Debug", "Obtaining exit code for PID: " & $process) If Not IsArray($ourCall) Then ;Failure, bad DLL or function name Else If Not $ourCall[0] Then ;Failure, OpenProcess failed Else ; Handle to process was returned in array index 0 $ourHandle = $ourCall[0] ; Do whatever you need to do... ; Finish... ; Then get Exit code $ourCall = DllCall("kernel32.dll", "ptr", "GetExitCodeProcess", "ptr", $ourHandle, "int_ptr", $placeholder) MsgBox(0, "Debug", "Process exited with code: " & $ourCall[2]) EndIf EndIf this worked for me now to figure out the actual exit codes (hopefully they're documented somewhere) and add more error checking in my code.
skippynz Posted February 7, 2006 Posted February 7, 2006 (edited) is it just firefox you want to uninstall silently ? if so - heres my code for it. i had to do this for work last week. If Not FileExists( @UserProfileDir & "\Application Data\Mozilla\Firefox\profiles.ini" ) Then Exit EndIf FileChangeDir ( @WindowsDir ) RunAsSet ("admin username", @computername, "admin password",0 ) sleep(1000) RunWait ( "UninstallFirefox.exe -ms" ) sleep(1000) DirRemove( @UserProfileDir & "\Application Data\Mozilla\Firefox",1 ) sleep(1000) DirRemove( @ProgramFilesDir & "\Mozilla Firefox",1 ) sleep(1000) as far as im aware thats the only fully silent uninstall string for firefox around. Edited February 7, 2006 by craig.gill
deltron Posted February 8, 2006 Author Posted February 8, 2006 (edited) is it just firefox you want to uninstall silently ? if so - heres my code for it. i had to do this for work last week. If Not FileExists( @UserProfileDir & "\Application Data\Mozilla\Firefox\profiles.ini" ) Then Exit EndIf FileChangeDir ( @WindowsDir ) RunAsSet ("admin username", @computername, "admin password",0 ) sleep(1000) RunWait ( "UninstallFirefox.exe -ms" ) sleep(1000) DirRemove( @UserProfileDir & "\Application Data\Mozilla\Firefox",1 ) sleep(1000) DirRemove( @ProgramFilesDir & "\Mozilla Firefox",1 ) sleep(1000) as far as im aware thats the only fully silent uninstall string for firefox around. yeah, I actually found that -ms switch yesterday on www.appdeploy.com. I do have several other apps that this is beneficial for, that don't have silent installs. thanks Edited February 8, 2006 by Ryan Grelck
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