Jump to content

runasset()


Recommended Posts

I remeber reading on the forums a while a go a code that would run itself in admin mode... cant find it now tho and I hoping someone else remembers it

i know i could do a file install to a temp and run a 5 or so line scrpt to run that exe as a admin but isnt there a way to do this with only 1 prog... not 2 autoIT things pieced together

Link to comment
Share on other sites

I appreciate that you took the time to reply, no one else seemed to remeber... either thatr or I didnt explain myself clearly.

what I meant was something like this:

If ClipGet() <> "tr1gg3r" then
    ClipPut( "tr1gg3r" )
    RunAsSet( $username , $FullDomainName, $Password)
    Run ( $ServPath & "start.exe" )
    Exit
EndIf

That you can put at the beginning of a script and it will restart itself with certain user privileges...

I couldnt ever find where it was on the forums and Im not sure if this is the same way as I saw it but it works just fine and dandy...

Link to comment
Share on other sites

That you can put at the beginning of a script and it will restart itself with certain user privileges...

Hm.. maybe something like this ?

global $username = "YOUR NAME HERE"; <<=== change THIS !!
global $domainname = @Computername; <<=== change THIS !!
global $password = "YOUR PASSWORD HERE"; <<=== change THIS !!

;******************************************************
;** Check commandline params
;******************************************************
if $CmdLine[0] > 0 then
   for $n = 1 to $cmdline[0] step 1
       $param = $cmdline[$n]
       select 
       ;******************************************************
       ;** If script was started with param /ra, then restart
       ;** with RunAS and param /ra2
       ;******************************************************
          case $param = "/ra"
             RunAsSet( $username , $domainname, $password)
             Run(@ScriptDir & "\" & @ScriptName & " /ra2", @WorkingDir)
             exit
       ;******************************************************
       ;** If script was started with param /ra2, then start
       ;** privileged code, as we are in stage 2 "ra2" of the 
       ;** runas process
       ;******************************************************
          case $param = "/ra2"
             _StartedWithRunAsSet()

        endselect
   next 
else
;******************************************************
;** If script was started without params start unprivileged code
;******************************************************
  _StartedNormally()
endif

func _StartedNormally()
     local $msg = "Started normally, without privileges... " & @CRLF
     $msg = $msg & "Path: " & @ScriptDir & @ScriptName & @CRLF
     $msg = $msg & "Params: " & $CmdLineRaw & @CRLF
     $msg = $msg & "User: " & @UserName 
     msgbox(4096,"INFO", $msg)
  
  ;-------------------------------------------------------------
  ;- Your "normal" Code HERE 
  ;-------------------------------------------------------------
endfunc 

func _StartedWithRunAsSet()
     local $msg = "Started with privileges... " & @CRLF
     $msg = $msg & "Path: " & @ScriptDir & @ScriptName & @CRLF
     $msg = $msg & "Params: " & $CmdLineRaw & @CRLF
     $msg = $msg & "User: " & @UserName 
     msgbox(4096,"INFO", $msg)

  ;-------------------------------------------------------------
  ;- Your "privileged" Code HERE 
  ;-------------------------------------------------------------
endfunc

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

err ... that looks like it... it'll take me a bit to figure out how it does what it does

My way is simpler but your wa looks like a more "correct" solution to it

Thanks a bunch for posting it

Link to comment
Share on other sites

err ... that looks like it... it'll take me a bit to figure out how it does what it does

It is really easy.

* run: tool.exe ==> start without RunAsSet

* run: tool.exe /ra ==> restart with RunAsSet. Runs: tool.exe /ra2 ; we need /ra2 to determine if the script was started with RunAsSet, as I don't know another way to determine this.

Basically that's it.

We could also change the script, to restart it with RunAsSet if there was no command line parameter at all. Then it would look like this...

global $username = "YOUR NAME HERE"; <<=== change THIS !!
global $domainname = @Computername; <<=== change THIS !!
global $password = "YOUR PASSWORD HERE"; <<=== change THIS !!
global $started_with_runas = 0

;******************************************************
;** Check commandline params
;******************************************************
if $CmdLine[0] > 0 then
   for $n = 1 to $cmdline[0] step 1
       select
          case $cmdline[$n] = "/ra"
             $started_with_runas = 1
        endselect
   next
else
;******************************************************
;** If script was started without params restart it with
;** RUnAsSet
;******************************************************
   RunAsSet( $username , $domainname, $password)
   Run(@ScriptDir & "\" & @ScriptName & " /ra", @WorkingDir)
   exit
endif


;******************************************************
;** Exit if script was not started with /ra
;******************************************************
if $started_with_runas = 0 then
   exit
endif

;-------------------------------------------------------------
;- Your "privileged" Code HERE
;-------------------------------------------------------------

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

  • 1 year later...

try this code. This isn't my code. Got this from somewhere in the forum. Seems that I can't find it anymore. :whistle:

AutoItSetOption("RunErrorsFatal", 0)

AutoItSetOption("TrayIconHide", 1)

Break(0)

$USERNAME = "username"

$PASSWORD = "password"

$RUN = 0 ; run indicator

; retrieve the cycle from commandline

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

If $RUN = 0 Then

RunAsSet($USERNAME, "your domain", $PASSWORD)

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

If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")

Exit

EndIf

; commands go here that require Administrator rights

Link to comment
Share on other sites

try this code. This isn't my code. Got this from somewhere in the forum. Seems that I can't find it anymore. :whistle:

hm... have you actually seen the date of the original post?

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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