Sign in to follow this  
Followers 0
mrrlg

Run with elevated permissions

23 posts in this topic

I need to install some software on users machines without granting them administrative rights. I have tried the following command and it doesn't seem to work.

RunAsSet ("Administrator", "Domain", "Password")

Where am I going wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I need to install some software on users machines without granting them administrative rights. I have tried the following command and it doesn't seem to work.

RunAsSet ("Administrator", "Domain", "Password")

Where am I going wrong?

That should do the trick ... the subsequent RUN or RUNWAIT statements will execute with those credentials...

What is the error you get ??

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The next line in the script is

Sleep (2000)

DirRemove ("C:\test")

Sleep (1000)

If not DirMove("C:\program files\oda\passport", "C:\test") Then

MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")

Exit(1)

Endif

BlockInput (1)

The message box Cannot move directory pops up and when I check, the C:\test file is still there and the contents of the Passport folder have not been moved.

Share this post


Link to post
Share on other sites

RunASSet is only for Run and Runwait !!!

If you need to do other autoit3 commands then you need to restart the script before executing them.

Something like this works after you compiled it:

$RUN = 0
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
; set to admin mode
If $RUN = 0 Then
   If Not IsAdmin() Then
      RunAsSet($USERNAME, @ComputerName, $PASSWORD)
     ; start the script program (itself) again but now in Adminmode...so all done tasks will run in Adminmode
      Run('"' & @ScriptFullPath & '" " 1"') 
      If @error = 1 Then
         MsgBox(48, "Error", "cannot start Admin mode.")   
      EndIf
      Exit
   EndIf
EndIf

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

RunASSet is only for Run and Runwait !!!

If you need to do other autoit3 commands then you need to restart the script before executing them.

Something like this works after you compiled it:

$RUN = 0
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
; set to admin mode
If $RUN = 0 Then
   If Not IsAdmin() Then
      RunAsSet($USERNAME, @ComputerName, $PASSWORD)
    ; start the script program (itself) again but now in Adminmode...so all done tasks will run in Adminmode
      Run('"' & @ScriptFullPath & '" " 1"') 
      If @error = 1 Then
         MsgBox(48, "Error", "cannot start Admin mode.")   
      EndIf
      Exit
   EndIf
EndIf
Heh, that is some cunning code. :D

Share this post


Link to post
Share on other sites

Really interesting and definitely something I'll use.

Thanks for the code. :D

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Heh, that is some cunning code.  :D

The basic idea was made by Larry quit a while ago....just worked it out this way.

Have used this piece of code already many times for installs of patches etc..

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks for the code, not sure where to place it in the script so I started the script off with it, now when I execute this line

If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]

I get the error Variable used without being declared.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Thanks for the code, not sure where to place it in the script so I started the script off with it, now when I execute this line

If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]

I get the error Variable used without being declared.

on $run ?

- Just put the whoile code i posted before your script....

- Compile it .....

- then run it....

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Actually on the first $CMDLINE [0]

Share this post


Link to post
Share on other sites

$__msgbox = MsgBox ( 4, 'AOOA MIS Dept', 'This Script will install the Latest Version of Passport for Windows. Do you want to Continue?' )

if NOT ( $__msgbox = 7 ) then

EndIf

RunAsSet ("Administrator", "Domain", "Password")

$RUN = 0

If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]

; set to admin mode

If $RUN = 0 Then

If Not IsAdmin() Then

RunAsSet($USERNAME, @ComputerName, $PASSWORD)

; start thescript program (itself) again but now in Adminmode...so all done tasks will run in Adminmode

Run('"' & @ScriptFullPath & '" " 1"')

If @error = 1 Then

MsgBox(48, "Error", "cannot start Admin mode.")

EndIf

Exit

EndIf

EndIf

Sleep (2000)

DirRemove ("C:\test")

Sleep (1000)

DirMove ("C:\program files\oda\passport", "C:\test1")

If not DirMove("C:\program files\oda\passport", "C:\test1") Then

MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")

Exit(1)

Endif

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

This works for me without an error :

$RUN = 0
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
; set to admin mode
If $RUN = 0 Then
   $__MSGBOX = MsgBox(4, 'AOOA MIS Dept', 'This Script will install the Latest Version of Passport for Windows. Do you want to Continue?')
   If NOT ($__MSGBOX = 6) Then  Exit
   If Not IsAdmin() Then
      RunAsSet("Administrator", "Domain", "Password")
    ; start thescript program (itself) again but now in Adminmode...so all done tasks will run in Adminmode
      Run('"' & @ScriptFullPath & '" " 1"') 
      If @error = 1 Then
         MsgBox(48, "Error", "cannot start Admin mode.") 
      EndIf
      Exit
   EndIf
EndIf
Sleep(2000)
DirRemove("C:\test")
Sleep(1000) 
If Not DirMove("C:\program files\oda\passport", "C:\test1") Then 
   MsgBox(4096, "Cannot Move Directory", "The directory could not be moved. Check if a program is still running from this directory")
   Exit (1)
EndIf

EDIT: remove the double RunAsSet

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I took just your script, copied it into Crimson Editor, compiled it, ran it from the network share as a user and now I get the variable used without being declared at the line

RunAsSet($USERNAME, @ComputerName, $Password)

Share this post


Link to post
Share on other sites

yea...

you need to specify those or hardcode them like you did in your example...

Updated the earlier posted script.....


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

JdeB, I edited the script to follow your updates, if I leave the RunAsSet line as "Administrator", "Domain", "Password" then I receive an error invalid user name or password. If I edit this line to reflect the correct domain and password for the Administrator account then the script fails on the DirMove line.

Yet I can move this directory on my own.

Edited by mrrlg

Share this post


Link to post
Share on other sites

Are you sure the DirRemove("C:\test") works...

If the files already exists DirMove will fail unless you specify:

DirMove("C:\program files\oda\passport", "C:\test1",1)


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

C:\text is deleted,

C:\text1 is created,

The contents of C:\program files\oda\passport are not moved.

Is dirmove the wrong command to use?

Share this post


Link to post
Share on other sites

C:\text is deleted,

C:\text1 is created,

The contents of C:\program files\oda\passport are not moved.

Is dirmove the wrong command to use?

You can use the filecopy function.

Example from the help file:

FileCopy("C:\*.au3", "D:\mydir\*.*")

; method to copy a folder (with its contents)
DirCreate("C:\old")
FileCopy("C:\old\*.*", "C:\new\")

Share this post


Link to post
Share on other sites

C:\text is deleted,

C:\text1 is created,

The contents of C:\program files\oda\passport are not moved.

Is dirmove the wrong command to use?

Should work, did you check if it already existed and try it with the ,1 parameter ?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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