Sign in to follow this  
Followers 0
xenoputtss

ControlSetText not working with RunAs on server 2008

3 posts in this topic

I think there is a bug with the ControlSetText function when running a process as admin with the runas command. I am running this on a windows 2008 server box.

This is how im launching the application

$InstallerPID = RunAs($LocalAdministratorLogin,$LocalAdministratorDomain,$LocalAdministratorPassword,4,$InstallerRootDirectory&"\2008_"&$VersionNumber&"\setup.exe",$InstallerRootDirectory&"\2008_"&$VersionNumber)
    ;$InstallerPID = Run($InstallerRootDirectory&"\2008_"&$VersionNumber&"\setup.exe",$InstallerRootDirectory&"\2008_"&$VersionNumber)
    if $InstallerPID = 0 Then
        LogError("Installer failed to launch")
        return False
    EndIf

then when my database setup window appears I do this

;Database Setup
        $title="Logos.Net - InstallShield Wizard"
        $message="Server authentication using the Login ID and password below"
        $handle = WinGetHandle($title,$message)
        If not @error Then
            Debug("Database Setup found.")
            WinActivate($handle)
            WinWaitActive($handle,$message,60)
            ControlClick($handle,"","[CLASS:Button; INSTANCE:3]");select radio button
            sleep(500)
            SetTextToControl($handle,"","[CLASS:Edit; INSTANCE:1]",$DatabaseServer, "Database Server")
            SetTextToControl($handle,"","[CLASS:Edit; INSTANCE:2]",$DatabaseLogin, "Database Login")
            SetTextToControl($handle,"","[CLASS:Edit; INSTANCE:3]",$DatabasePassword, "Database Password")
            SetTextToControl($handle,"","[CLASS:Edit; INSTANCE:4]",$DatabaseCatalog, "Database Catalog")


            Debug(@TAB&"*CLICK*")
            ControlClick($handle,"",1);Next Button
            sleep(5*1000)
        EndIf

and here is my SetTextToControl function

func SetTextToControl($WindowHandle,$WindowText,$ControlID,$ControlText, $ControlNameForDebugMessage)
    ;MsgBox(0,$ControlNameForDebugMessage&"---"&$ControlID,$ControlText,3)  
    Debug("Setting focus to "&$ControlNameForDebugMessage)
    ControlFocus($WindowHandle,$WindowText,$ControlID)
    sleep(500)
    Debug("Clicking "&$ControlNameForDebugMessage)
    ControlClick($WindowHandle,$WindowText,$ControlID)
    sleep(500)
    Debug("Setting Text to '"&$ControlText&"'")
    ControlSetText($WindowHandle,$WindowText,$ControlID,$ControlText,1)
    sleep(500)
EndFunc

Now, if i switch to the run command (and not use the runas) this works. (the extra sleep commands are in there to give time for the UI to respond so that their messages can be handled properly)

Share this post


Link to post
Share on other sites



Try something like this :(

func SetTextToControl($WindowHandle, $WindowText, $ControlID, $ControlText, $ControlNameForDebugMessage)
    ;MsgBox(0,$ControlNameForDebugMessage&"---"&$ControlID,$ControlText,3)  
    
    $controlHandle = ControlGetHandle($WindowHandle, $WindowText, "")
    ; or 
    $controlHandle = ControlGetHandle($WindowHandle, "", $ControlID)
    ; Use one or the other, control ID is the preference if it does not change. 
    
    Debug("ControlHandle = " & $controlHandle & @CRLF) ; then compate against the AutoIt tool to ensure you have the correct handle
    
    Debug("Setting focus to "&$ControlNameForDebugMessage)
    ControlFocus($controlHandle, "", "")
    sleep(500)
    
    Debug("Clicking "&$ControlNameForDebugMessage)
    ControlClick($controlHandle, "", "")
    sleep(500)
    
    Debug("Setting Text to '"&$ControlText&"'")
    ControlSetText($controlHandle, "", "", $ControlText,1)
    sleep(500)
    
EndFunc

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

That seemed to have solved the problem.

Try something like this :(

func SetTextToControl($WindowHandle, $WindowText, $ControlID, $ControlText, $ControlNameForDebugMessage)
    ;MsgBox(0,$ControlNameForDebugMessage&"---"&$ControlID,$ControlText,3)  
    
    $controlHandle = ControlGetHandle($WindowHandle, $WindowText, "")
    ; or 
    $controlHandle = ControlGetHandle($WindowHandle, "", $ControlID)
    ; Use one or the other, control ID is the preference if it does not change. 
    
    Debug("ControlHandle = " & $controlHandle & @CRLF) ; then compate against the AutoIt tool to ensure you have the correct handle
    
    Debug("Setting focus to "&$ControlNameForDebugMessage)
    ControlFocus($controlHandle, "", "")
    sleep(500)
    
    Debug("Clicking "&$ControlNameForDebugMessage)
    ControlClick($controlHandle, "", "")
    sleep(500)
    
    Debug("Setting Text to '"&$ControlText&"'")
    ControlSetText($controlHandle, "", "", $ControlText,1)
    sleep(500)
    
EndFunc

Edited by xenoputtss

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