Sign in to follow this  
Followers 0
nikink

RunAsWait does not change the user account?

3 posts in this topic

Hi folks,

A year ago or so, I was able to use the following code to re-run an installation script with admin rights

; AutoRun "Script.exe" as Admin; By MHz on AutoIt Forums
Func OnAutoItStart()
    
    Local $user = _StringEncrypt(0,"xxxxxxxxxxxxxxxxxxxxxxxxx1", "YYY", "1")
   
    Local $domain = _StringEncrypt(0,"xxxxxxxxxxxxxxxxxxxxxxxxx2", "YYY", "1")
    
    Local $pw = _StringEncrypt(0,"xxxxxxxxxxxxxxxxxxxxxxxxx3", "YYY", "1")
   ;
; Set a working directory for the script.
    FileChangeDir(@TempDir)
    
   ; Check incoming parameters
    If Not $CMDLINE[0] Then
        
        RunAsSet($user, $domain, $pw)
        RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /mapprintershare', @TempDir)
        RunAsSet()
        
        Exit
    ElseIf $CMDLINE[1] <> '/mapprintershare' Then
       ; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc

Since the latest version of AutoIt changed RunAsSet commands, I updated that snippet to:

; AutoRun "Script.exe" as Admin; By MHz on AutoIt Forums
Func OnAutoItStart()

    Local $user = _StringEncrypt(0, "xxxxxxxxxxxxxxxxxxxxxxxxx1", "YYY", "1")

    Local $domain = _StringEncrypt(0, "xxxxxxxxxxxxxxxxxxxxxxxxx2", "YYY", "1")

    Local $pw = _StringEncrypt(0, "xxxxxxxxxxxxxxxxxxxxxxxxx3", "YYY" "1")
    
;
; Set a working directory for the script.
    FileChangeDir(@TempDir)

; Check incoming parameters
    If Not $CMDLINE[0] Then

        RunAsWait($user, $domain, $pw, 2, '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /mapprintershare', @TempDir)
        
        Exit
    ElseIf $CMDLINE[1] <> '/mapprintershare' Then
    ; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc  ;==>OnAutoItStart

But it doesn't seem to be working, as in, it doesn't re-run the script with the $user account.

What have I missed?

Anyone? Please? :P

Share this post


Link to post
Share on other sites



Hi folks,

A year ago or so, I was able to use the following code to re-run an installation script with admin rights

; AutoRun "Script.exe" as Admin; By MHz on AutoIt Forums
Func OnAutoItStart()
    
    Local $user = _StringEncrypt(0,"xxxxxxxxxxxxxxxxxxxxxxxxx1", "YYY", "1")
   
    Local $domain = _StringEncrypt(0,"xxxxxxxxxxxxxxxxxxxxxxxxx2", "YYY", "1")
    
    Local $pw = _StringEncrypt(0,"xxxxxxxxxxxxxxxxxxxxxxxxx3", "YYY", "1")
  ;
; Set a working directory for the script.
    FileChangeDir(@TempDir)
    
  ; Check incoming parameters
    If Not $CMDLINE[0] Then
        
        RunAsSet($user, $domain, $pw)
        RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /mapprintershare', @TempDir)
        RunAsSet()
        
        Exit
    ElseIf $CMDLINE[1] <> '/mapprintershare' Then
      ; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc

Since the latest version of AutoIt changed RunAsSet commands, I updated that snippet to:

; AutoRun "Script.exe" as Admin; By MHz on AutoIt Forums
Func OnAutoItStart()

    Local $user = _StringEncrypt(0, "xxxxxxxxxxxxxxxxxxxxxxxxx1", "YYY", "1")

    Local $domain = _StringEncrypt(0, "xxxxxxxxxxxxxxxxxxxxxxxxx2", "YYY", "1")

    Local $pw = _StringEncrypt(0, "xxxxxxxxxxxxxxxxxxxxxxxxx3", "YYY" "1")
    
;
; Set a working directory for the script.
    FileChangeDir(@TempDir)

; Check incoming parameters
    If Not $CMDLINE[0] Then

        RunAsWait($user, $domain, $pw, 2, '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /mapprintershare', @TempDir)
        
        Exit
    ElseIf $CMDLINE[1] <> '/mapprintershare' Then
; Exit script with exit code 1
        Exit 1
    EndIf
EndFunc ;==>OnAutoItStart

But it doesn't seem to be working, as in, it doesn't re-run the script with the $user account.

What have I missed?

Anyone? Please? :P

You are using the logon_flags = 2 for "Network credentials only". Try it with 0, and only if that doesn't work, with 1 (see the help file).

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You are using the logon_flags = 2 for "Network credentials only". Try it with 0, and only if that doesn't work, with 1 (see the help file).

:P

Hm, ok I will give that a try. As it's a dedicated software install account, I'm not sure if it has any more to it than network credentials... thanks for the advice! :P

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