# Run with elevated permissions

## Recommended Posts

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.

Where am I going wrong?

##### Share on other sites

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.

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

Live for the present,
Dream of the future,
Learn from the past.

##### 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 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]
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 SciTE4AutoIt3 Full installer Download page - Beta files 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
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.

##### Share on other sites

Really interesting and definitely something I'll use.

Thanks for the code.

##### Share on other sites

Heh, that is some cunning code.

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

Live for the present,
Dream of the future,
Learn from the past.

##### 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 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 on other sites

Thats a build-in variable...

Can you post the script as you have it now ?

Live for the present,
Dream of the future,
Learn from the past.

##### 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

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

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 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
; 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

Live for the present,
Dream of the future,
Learn from the past.

##### 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 on other sites

yea...

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

Updated the earlier posted script.....

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

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

Live for the present,
Dream of the future,
Learn from the past.

##### 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 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 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 ?

Live for the present,
Dream of the future,
Learn from the past.

## Create an account

Register a new account