Jump to content

RerunAs UDF?


DaveF
 Share

Recommended Posts

Does anyone have a preferred UDF for re-running a script as an Administrator? My own method from years ago looks like:

; Assess whether we're an admin. If not RunAsSet to an admin user for the Local
; machine and re-run the script with superfluous parameters under the new
; credentials. If we arrive in this loop again with the superfluous parameters
; on the command line, the user in RunAsSet wasn't an admin, so exit.
If (Not IsAdmin()) Then
   If $CMDLINE[0] = 5 Then
      MsgBox(0, "Error", "The provided user is not an Administrator on this PC.")
      Exit
   EndIf
   RunAsSet("dave", @ComputerName , "boottothehead")
   Run(@ScriptName & " 1 2 3 4 5")
   RunAsSet()
   Exit
EndIf

...and that works fine for me since I don't ever use command-line arguments or run uncompiled scripts. I just wondered what else might be out there...

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

Sorry to sound stupid here Dave but what does the "1 2 3 4 5" mean after the Run(@ScriptName) mean?

As MadBoy says I'm adding those as command line parameters when I re-call the script with the new credentials. Normally when compiled script is run by double-clicking the EXE there wouldn't be any parameters on the command line. I'm using the test of whether they're there or not (actually testing to see if there are 5 in the example) to determine if this instance of the script is being run by a person (e.g double-click), where it would be OK if the Windows user wasn't an Administrator, or if the script had been (re)run by the script itself, in which case the Windows user credentials come from RunAsSet and should have been an Administrator. If the credentials were valid but weren't for an Administrator we'd be in a kind of infinite loop where the script re-ran itself over and over, thus this test...

Hi!

The method showed don't run under Vista.

What kind of error are you seeing, Michel?

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

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