Jump to content

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.

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

Where am I going wrong?

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Administrators

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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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)

Link to comment
Share on other sites

  • Developers

yea...

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

Updated the earlier posted script.....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
Link to comment
Share on other sites

  • Developers

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)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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\")
Link to comment
Share on other sites

  • Developers

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 ?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...