Sign in to follow this  
Followers 0
blckpythn

AdlibRegister

20 posts in this topic

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.

 

Share this post


Link to post
Share on other sites



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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

BTW: Don't use Send, use ControlSend to get a reliable script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by blckpythn

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

This means: Problem solved?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (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 by danwilli

Share this post


Link to post
Share on other sites

#18 ·  Posted (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:

eiuhLSu.png

This is with an exact copy of your line, I think the layers of quotes are causing a problem.

Edited by blckpythn

Share this post


Link to post
Share on other sites

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""))"')

Share this post


Link to post
Share on other sites

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!

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