blckpythn Posted July 16, 2013 Share Posted July 16, 2013 I'm trying to use AdlibRegister to do a WinWaitActive, and type some credentials for me. I'm only doing it this way because I need to type the credentials into a popup that appears from a previous command that doesn't finish until the credentials are typed. If GUICtrlRead($cAuto) = $GUI_CHECKED Then AdlibRegister("EnterCreds2", 5000) ExecuteCmd("Connect-MsolService") AdlibUnRegister("EnterCreds2") Else ExecuteCmd("Connect-MsolService") EndIf Func EnterCreds2() If WinWaitActive("Enter Credentials", "", 4) <> 0 Then Send(GUICtrlRead($iUsername) & "{TAB}" & GUICtrlRead($iPassword) & "{ENTER}") EndIf EndFunc ;==>EnterCreds2 Is this the wrong way to do it? Or is it not possible? I suppose another way to do it is by running a separate script that I pass the credentials to, but that doesn't appeal to me if there is an alternative. Link to comment Share on other sites More sharing options...
water Posted July 16, 2013 Share Posted July 16, 2013 AdlibRegister only makes sense if you want to call a function every x milliseconds. In your case you register and immediately unregister the function. That's the same as executing the statements in the main script: If GUICtrlRead($cAuto) = $GUI_CHECKED Then If WinWaitActive("Enter Credentials", "", 4) <> 0 Then Send(GUICtrlRead($iUsername) & "{TAB}" & GUICtrlRead($iPassword) & "{ENTER}") EndIf ExecuteCmd("Connect-MsolService") Else ExecuteCmd("Connect-MsolService") EndIf My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted July 16, 2013 Share Posted July 16, 2013 BTW: Don't use Send, use ControlSend to get a reliable script. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
blckpythn Posted July 16, 2013 Author Share Posted July 16, 2013 AdlibRegister only makes sense if you want to call a function every x milliseconds. In your case you register and immediately unregister the function. That's the same as executing the statements in the main script: If GUICtrlRead($cAuto) = $GUI_CHECKED Then If WinWaitActive("Enter Credentials", "", 4) <> 0 Then Send(GUICtrlRead($iUsername) & "{TAB}" & GUICtrlRead($iPassword) & "{ENTER}") EndIf ExecuteCmd("Connect-MsolService") Else ExecuteCmd("Connect-MsolService") EndIf I can't use this because the window doesn't appear until I run ExecuteCmd("Connect-MsolService") But the script doesn't continue until ExecuteCmd finishes. So I was trying to get around it by having AdlibRegister run it simultaneously. BTW: Don't use Send, use ControlSend to get a reliable script. I know, still testing. Link to comment Share on other sites More sharing options...
water Posted July 16, 2013 Share Posted July 16, 2013 I see. What does the script do when the popup is being displayed? Add a MsgBox if WinWaitActive is successful to show that this part of the script is being executed. What does function ExecuteCmd do? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
blckpythn Posted July 16, 2013 Author Share Posted July 16, 2013 (edited) The script is waiting on the Powershell command to return at this point, so it is essentially paused. Powershell is what initiates the prompt. Func ExecuteCMD($sPSCmd) Dim $outtext ; Set the $OUTPUT mode to $BUFFER $ActiveXPosh.OutputMode = $OUTPUT_BUFFER $ActiveXPosh.Execute($sPSCmd) ; <--------------------Frozen here, waiting for user to interact with the popup. ; Get the $OUTPUT line by line and add it to a variable For $str In $ActiveXPosh.OUTPUT() $outtext = $outtext & $str $outtext = $outtext & @CRLF Next ConsoleWrite($outtext & @CR) $ActiveXPosh.ClearOutput() ; Empty the $OUTPUT $BUFFER EndFunc ;==>ExecuteCMD Does AdLibRegister freeze when the script is frozen on something else? For example, if a Msgbox is open and waiting for user input, do registered functions pause and wait for Msgbox to close too? Edited July 16, 2013 by blckpythn Link to comment Share on other sites More sharing options...
water Posted July 16, 2013 Share Posted July 16, 2013 AdlibRegister can't interrupt the execution of the command. Can't you pass the credentials in $sPSCmd? According to MS parameter -Credential should do what you need. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
blckpythn Posted July 16, 2013 Author Share Posted July 16, 2013 AdlibRegister can't interrupt the execution of the command. Can't you pass the credentials in $sPSCmd? According to MS parameter -Credential should do what you need. -Credential can be passed only after my initial usage of Get-Credential(Which is one of the first things I run). Get-Credential will NOT accept passwords, and I have found no way to force it to. Link to comment Share on other sites More sharing options...
water Posted July 16, 2013 Share Posted July 16, 2013 Couldn't you write your own GUI to let the user enter the credentials and then pass it to the other cmdlets? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
blckpythn Posted July 16, 2013 Author Share Posted July 16, 2013 Couldn't you write your own GUI to let the user enter the credentials and then pass it to the other cmdlets? I already have, but "passing it to the cmdlets" isn't an option, it will always prompt. Thus I take what they typed into my GUI and Send it to the window that pops up. I have worked around it for the time being by executing a 6 line script like so. If GUICtrlRead($cAuto) = $GUI_CHECKED Then Run('"' & @ScriptFullPath & '"' & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\EnterCreds.au3" ' & GUICtrlRead($iUsername) & " " & GUICtrlRead($iPassword) & " cmdlet") ExecuteCmd("$LiveCred = Get-Credential") In the EnterCreds.au3 file is: If $CmdLine[0] <> 3 Then Exit If WinWaitActive($CmdLine[3], "", 10) <> 0 Then ControlSetText($CmdLine[3], "", "[NAME:m_UserName]", $CmdLine[1]) ControlSetText($CmdLine[3], "", "[NAME:m_Password]", $CmdLine[2]) ControlClick($CmdLine[3], "", "[NAME:m_OK]", "left") EndIf Link to comment Share on other sites More sharing options...
water Posted July 16, 2013 Share Posted July 16, 2013 This means: Problem solved? My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
blckpythn Posted July 16, 2013 Author Share Posted July 16, 2013 This means: Problem solved? I suppose so, since I can't seem to get around the fact that the whole script freezes. Is there a way to run those six lines in a new process without a second file? I want to deploy the end result of this utility to some clients to use for password resets. Link to comment Share on other sites More sharing options...
jchd Posted July 16, 2013 Share Posted July 16, 2013 You may want to try a beta supporting the new volatile function modifier, it might solve your problem. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
blckpythn Posted July 17, 2013 Author Share Posted July 17, 2013 You may want to try a beta supporting the new volatile function modifier, it might solve your problem. Would that make any difference while the script is frozen on a COM object? Link to comment Share on other sites More sharing options...
jchd Posted July 17, 2013 Share Posted July 17, 2013 Re-reading the firsts posts, probably no but you only know after trying. Else you can also try one of the so-called multi-threading hacks floating around, since the second script is so simple. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
water Posted July 17, 2013 Share Posted July 17, 2013 Create a second script (EnterCreds.au3) that checks for the window in a loop. Pass the processid of the main script to EnterCreds. In EnterCreds check if the process still exists. If not, exit. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
DW1 Posted July 17, 2013 Share Posted July 17, 2013 (edited) I already have, but "passing it to the cmdlets" isn't an option, it will always prompt. Thus I take what they typed into my GUI and Send it to the window that pops up. I have worked around it for the time being by executing a 6 line script like so. If GUICtrlRead($cAuto) = $GUI_CHECKED Then Run('"' & @ScriptFullPath & '"' & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\EnterCreds.au3" ' & GUICtrlRead($iUsername) & " " & GUICtrlRead($iPassword) & " cmdlet") ExecuteCmd("$LiveCred = Get-Credential") In the EnterCreds.au3 file is: If $CmdLine[0] <> 3 Then Exit If WinWaitActive($CmdLine[3], "", 10) <> 0 Then ControlSetText($CmdLine[3], "", "[NAME:m_UserName]", $CmdLine[1]) ControlSetText($CmdLine[3], "", "[NAME:m_Password]", $CmdLine[2]) ControlClick($CmdLine[3], "", "[NAME:m_OK]", "left") EndIf Instead of having to include the au3, just execute it as a single line right before you call ExecuteCmd() Run(@AutoItExe & ' /AutoIt3ExecuteLine "If WinWaitActive("cmdlet") Then ConsoleWrite(ControlSetText("cmdlet", "", "[NAME:m_UserName]", ' & GUICtrlRead($iUsername) & ') & ControlSetText("cmdlet", "", "[NAME:m_Password]", ' & GUICtrlRead($iPassword) & ') & ControlClick("cmdlet", "", "[NAME:m_OK]", "left"))"') ExecuteCmd("$LiveCred = Get-Credential") untested, but looks right. Edited July 17, 2013 by danwilli AutoIt3 Online Help Link to comment Share on other sites More sharing options...
blckpythn Posted July 17, 2013 Author Share Posted July 17, 2013 (edited) Instead of having to include the au3, just execute it as a single line right before you call ExecuteCmd() Run(@AutoItExe & ' /AutoIt3ExecuteLine "If WinWaitActive("cmdlet") Then ConsoleWrite(ControlSetText("cmdlet", "", "[NAME:m_UserName]", ' & GUICtrlRead($iUsername) & ') & ControlSetText("cmdlet", "", "[NAME:m_Password]", ' & GUICtrlRead($iPassword) & ') & ControlClick("cmdlet", "", "[NAME:m_OK]", "left"))"') ExecuteCmd("$LiveCred = Get-Credential") untested, but looks right. I like your style! I didn't realize you could execute a string with ExecuteLine, I thought it had to be in reference to a file. However, I'm getting this error message: This is with an exact copy of your line, I think the layers of quotes are causing a problem. Edited July 17, 2013 by blckpythn Link to comment Share on other sites More sharing options...
Solution DW1 Posted July 17, 2013 Solution Share Posted July 17, 2013 Oops, try this: Run(@AutoItExe & ' /AutoIt3ExecuteLine "If WinWaitActive(""cmdlet"") Then ConsoleWrite(ControlSetText(""cmdlet"", """", ""[NAME:m_UserName]"", ' & GUICtrlRead($iUsername) & ') & ControlSetText(""cmdlet"", """", ""[NAME:m_Password]"", ' & GUICtrlRead($iPassword) & ') & ControlClick(""cmdlet"", """", ""[NAME:m_OK]"", ""left""))"') AutoIt3 Online Help Link to comment Share on other sites More sharing options...
blckpythn Posted July 17, 2013 Author Share Posted July 17, 2013 That helped, still needed additional quotes for the GuiCtrlRead returns, now its working! Run(@AutoItExe & ' /AutoIt3ExecuteLine "If WinWaitActive(""cmdlet"") Then ConsoleWrite(ControlSetText(""cmdlet"", """", ""[NAME:m_UserName]"", ""' & GUICtrlRead($iUsername) & '"") & ControlSetText(""cmdlet"", """", ""[NAME:m_Password]"", ""' & GUICtrlRead($iPassword) & '"") & ControlClick(""cmdlet"", """", ""[NAME:m_OK]"", ""left""))"') Thank you! 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