Sign in to follow this  
Followers 0
lyledg

Runas Not working?

12 posts in this topic

#1 ·  Posted (edited)

Hey Guys

Trying to run this simple piece of code but keep on getting prompted with a security gui wanting me to specifiy Admin creds. The account I am using is a domain admin so this step should be negated...

RunAsSet("Admin",@LogonDomain, "password")
    $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
    RunAsSet()

Do I need to map a drive to the machine beforehand or should this command work?

Edited by lyledg

Share this post


Link to post
Share on other sites



Thanks for this Helge, but am I right in thinking that this is not possible under WinxpSp2?

Share this post


Link to post
Share on other sites

Hey Guys

Trying to run this simple piece of code but keep on getting prompted with a security gui wanting me to specifiy Admin creds. The account I am using is a domain admin so this step should be negated...

RunAsSet("Admin",@LogonDomain, "password")
    $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
    RunAsSet()

Do I need to map a drive to the machine beforehand or should this command work?

It does work with WinXpsp2. I use Runasset all the time in my scripts to pass admin rights to functions I do. However the syntax you used would not work for me either.

Try this instead.

RunAsSet("Admin","Domain", "password")
    $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)

When I used the actual domain name and not @LogonDomain it works on W2k and Winxp so try that. You also don't need the extra RunAsSet() just put the first one at the top of the script.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok, here is the function that is still not working..

NOTE: $sSpecifyMachineName is an input box created on the parent GUI

$Adminform = GUICreate("Logon", 251, 145, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
$AdminOkbtn = GUICtrlCreateButton("&OK", 86, 112, 75, 25, 0)
$AdminCancelbtn = GUICtrlCreateButton("&Cancel", 167, 112, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Password:", 8, 52, 53, 17)
$Label1 = GUICtrlCreateLabel("Administrator:", 8, 18, 67, 17)
$ADMININPUT = GUICtrlCreateInput("", 88, 16, 153, 21)
GUICtrlSetState(-1, $GUI_FOCUS)
$ADMINPSWDINPUT = GUICtrlCreateInput("", 88, 48, 153, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Domain", 8, 82, 40, 17)
$DOMAININPUT = GUICtrlCreateInput("", 88, 80, 153, 21, $ES_UPPERCASE)
GUISetState(@SW_SHOW)

Global $sADMININPUTrslt =GUICtrlRead($ADMININPUT)
Global $sPswdinputrslt = GUICtrlRead($ADMINPSWDINPUT)
Global $sDomaininputrslt = GUICtrlRead($DOMAININPUT)


Func _ConnectoCdrv()    


    If $sSpecifyMachineName = "" Then
        MsgBox(16, "Error!", "Machine name is missing.")
    Else

;Ping machine to see if it contactable
        $Pingrslt = Ping($sSpecifyMachineName, 300)
        
        $Errmsg = @error
        
        Select
            
            Case $Errmsg = 0                

                RunAsSet('"' & $sADMININPUTrslt &'"', '"' & $sDomaininputrslt & '"', '"' & $sPswdinputrslt & '"', 2)
                $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
    
            Case $Errmsg = 1
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host is offline")
                Return
            Case $Errmsg = 2
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host is unreachable")
                Return
            Case $Errmsg = 3
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host has a bad destination address")
        EndSelect   

    EndIf


EndFunc

Question: Is the syntax right for using a 2 at the end of this line

RunAsSet('"' & $sADMININPUTrslt &'"', '"' & $sDomaininputrslt & '"', '"' & $sPswdinputrslt & '"', 2)
Edited by lyledg

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ok, here is the function that is still not working..

NOTE: $sSpecifyMachineName is an input box created on the parent GUI

$Adminform = GUICreate("Logon", 251, 145, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
$AdminOkbtn = GUICtrlCreateButton("&OK", 86, 112, 75, 25, 0)
$AdminCancelbtn = GUICtrlCreateButton("&Cancel", 167, 112, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Password:", 8, 52, 53, 17)
$Label1 = GUICtrlCreateLabel("Administrator:", 8, 18, 67, 17)
$ADMININPUT = GUICtrlCreateInput("", 88, 16, 153, 21)
GUICtrlSetState(-1, $GUI_FOCUS)
$ADMINPSWDINPUT = GUICtrlCreateInput("", 88, 48, 153, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Domain", 8, 82, 40, 17)
$DOMAININPUT = GUICtrlCreateInput("", 88, 80, 153, 21, $ES_UPPERCASE)
GUISetState(@SW_SHOW)

Global $sADMININPUTrslt =GUICtrlRead($ADMININPUT)
Global $sPswdinputrslt = GUICtrlRead($ADMINPSWDINPUT)
Global $sDomaininputrslt = GUICtrlRead($DOMAININPUT)
Func _ConnectoCdrv()    
    If $sSpecifyMachineName = "" Then
        MsgBox(16, "Error!", "Machine name is missing.")
    Else

;Ping machine to see if it contactable
        $Pingrslt = Ping($sSpecifyMachineName, 300)
        
        $Errmsg = @error
        
        Select
            
            Case $Errmsg = 0                

                RunAsSet('"' & $sADMININPUTrslt &'"', '"' & $sDomaininputrslt & '"', '"' & $sPswdinputrslt & '"', 2)
                $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
    
            Case $Errmsg = 1
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host is offline")
                Return
            Case $Errmsg = 2
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host is unreachable")
                Return
            Case $Errmsg = 3
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host has a bad destination address")
        EndSelect   

    EndIf
EndFunc

Question: Is the syntax right for using a 2 at the end of this line

RunAsSet('"' & $sADMININPUTrslt &'"', '"' & $sDomaininputrslt & '"', '"' & $sPswdinputrslt & '"', 2)

Try it this way. You don't need to put the quotes in if you declared the information as variables.

$Adminform = GUICreate("Logon", 251, 145, -1, -1, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS))
$AdminOkbtn = GUICtrlCreateButton("&OK", 86, 112, 75, 25, 0)
$AdminCancelbtn = GUICtrlCreateButton("&Cancel", 167, 112, 75, 25, 0)
$Label1 = GUICtrlCreateLabel("Password:", 8, 52, 53, 17)
$Label1 = GUICtrlCreateLabel("Administrator:", 8, 18, 67, 17)
$ADMININPUT = GUICtrlCreateInput("", 88, 16, 153, 21)
GUICtrlSetState(-1, $GUI_FOCUS)
$ADMINPSWDINPUT = GUICtrlCreateInput("", 88, 48, 153, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Domain", 8, 82, 40, 17)
$DOMAININPUT = GUICtrlCreateInput("", 88, 80, 153, 21, $ES_UPPERCASE)
GUISetState(@SW_SHOW)

Global $sADMININPUTrslt =GUICtrlRead($ADMININPUT)
Global $sPswdinputrslt = GUICtrlRead($ADMINPSWDINPUT)
Global $sDomaininputrslt = GUICtrlRead($DOMAININPUT)


Func _ConnectoCdrv()    


    If $sSpecifyMachineName = "" Then
        MsgBox(16, "Error!", "Machine name is missing.")
    Else

;Ping machine to see if it contactable
        $Pingrslt = Ping($sSpecifyMachineName, 300)
        
        $Errmsg = @error
        
        Select
            
            Case $Errmsg = 0                

                RunAsSet($sADMININPUTrslt, $sDomaininputrslt, $sPswdinputrslt, 2)
                $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
    
            Case $Errmsg = 1
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host is offline")
                Return
            Case $Errmsg = 2
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host is unreachable")
                Return
            Case $Errmsg = 3
                MsgBox(16, "Error!", $sSpecifyMachineName & " Host has a bad destination address")
        EndSelect    

    EndIf


EndFunc
oÝ÷ Ù«­¢+ÙIÕ¹ÍMÐ ÀÌØíÍ5%9%9AUQÉͱаÀÌØíͽµ¥¹¥¹ÁÕÑÉͱаÀÌØíÍAÍÝ¥¹ÁÕÑÉͱаȤ

This line should work as is. Just make sure the inputs you enter are correct.

Edited by EndFunc

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks so much Endfunc for the code, I have tried various methods with the username and still gettting the same result

I have also tried three different accounts which have domain admin rights on this box

The prompt I get is shown in the attachment

Edited by lyledg

Share this post


Link to post
Share on other sites

Apologies for double post of *.jpg, I't won't allow me to delete the second pic...

Share this post


Link to post
Share on other sites

Thanks so much Endfunc for the code, I have tried various methods with the username and still gettting the same result

I have also tried three different accounts which have domain admin rights on this box

The prompt I get is shown in the attachment

I think I see what's happening. You are trying to use RunAsSet which runs the script with admin rights but it won't pass it on to call the remote machine perhaps. What I would do to see if it worked is

Case $Errmsg = 0                

                ;RunAsSet($sADMININPUTrslt, $sDomaininputrslt, $sPswdinputrslt, 2)
                $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
                Sleep(4000)
                Send($sDomaininputrslt & "\" & $sADMININPUTrslt & "{Tab}" & $sPswdinputrslt & "{Enter}")

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Thanks mate, that is one solution, but the problem that it will bring is the timeout to wait for the security dialog to appear might be longer if going across a WAN for instance, and therefore will error...

Only option I can see at the moment is to run the application as a current logged on Administrator, and not use the "Runas" function. Seems when using this to go across networks, it does not work?

Hopefully someone will be able to prove me wrong... :whistle:

Share this post


Link to post
Share on other sites

Thanks mate, that is one solution, but the problem that it will bring is the timeout to wait for the security dialog to appear might be longer if going across a WAN for instance, and therefore will error...

Only option I can see at the moment is to run the application as a current logged on Administrator, and not use the "Runas" function. Seems when using this to go across networks, it does not work?

Hopefully someone will be able to prove me wrong... :whistle:

Why not just do a WinWaitActive() on the login prompt then Send the info as I mentioned earlier.

Somthing like.

Case $Errmsg = 0                

                ;RunAsSet($sADMININPUTrslt, $sDomaininputrslt, $sPswdinputrslt, 2)
                $Process = Run('Explorer \\' & $sSpecifyMachineName & '\C$', @WindowsDir, @SW_SHOW)
                Sleep(4000)
                 WinWaitActive("Connecting to")
                Send($sDomaininputrslt & "\" & $sADMININPUTrslt & "{Tab}" & $sPswdinputrslt & "{Enter}")

EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites

Thanks Endfunc, that is a possible solution, and will see if that is feasible in our environment

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