Jump to content

RunAs not running as Administrator?


Recommended Posts

It appears that RunAs will run, but not as the administrator. A script comprised only of the below code does not allow Install_IDRs.exe to copy files to locations where the local computer's administrator account has access manually. If I run this under the local administrator's log-in it works, suggesting the executable is run with the logged in credentials and not the admonistrator's. Any idea what I may have wrong here?

$copyFileLocation = @ScriptDir & "\Support\"
$copyFileFullName = $copyFileLocation & "Install_IDRs.exe"

Local $sUserName = "administrator"
Local $sPassword = "mywrongpassword"

$Status = RunAs($sUserName, @ComputerName, $sPassword, 2, $copyFileFullName, @DesktopDir)
MsgBox(4096, "IDR Installation", $Status)

Install_IDRs.exe is a script which I Built using the Build option in the SciTE editor. It uses FileCopy to copy a file from one location to another. In my test cases it is from a folder on teh local hard drive to another folder on the local hard drive

Karl

Link to comment
Share on other sites

  • Moderators

Hi, KSum. To start, try changing this:

$copyFileFullName = $copyFileLocation & "Install_IDRs.exe"

to this:

$copyFileFullName = $copyFileLocation & "Install_IDRs.exe"

I ran it like this, using a different compiled script, and it worked just fine using admin creds.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Hmm.. that complicates it. Someone much more intelligent than I can probably weigh in, but I believe in Windows 7 your ONLY option is #RequireAdmin

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

That was local. I had thought about adding the domain name but since it is already passed to RunAs I opted against. Regardless, I made the change as shown below and that didn't help.

Local $sUserName = @ComputerName & "\administrator"
Local $sPassword = "mywrongpassword"
; Run a command prompt as the other user.
$Status = RunAs($sUserName, @ComputerName, $sPassword, 2, $copyFileFullName, @DesktopDir)

So then I tried removing @ComputerName, to make the Run As look like this, but that didn't let $copyFileFullName run at all:

; Run a command prompt as the other user.
$Status = RunAs($sUserName, "", $sPassword, 2, $copyFileFullName, @DesktopDir)

NOTE: The password I am using is actually the correct password, and the Secondary Logon (RunAs) service is enabled. When I change the password to a bad password, $copyFileFullName does not run.

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