Jump to content
Sign in to follow this  
KSum

RunAs not running as Administrator?

Recommended Posts

KSum

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

Share this post


Link to post
Share on other sites
JLogan3o13

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
KSum

JLogan3o13,

Thank you for the response. That effectively made the $copyFileFullName equal c:tempSupportInstall_IDRs.exe and didn't seem to help. It still ran Install_IDRs.exe but apparently not with the correct permissions.

Karl

Share this post


Link to post
Share on other sites
JLogan3o13

I'm assuming you're doing this on XP, is that correct?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
KSum

Windows 7 is the test machine.

Share this post


Link to post
Share on other sites
JLogan3o13

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
MrAutomationGuy

Is that a local administrator or domain?

Try using this format for your username: "<domainName><userName>".

Share this post


Link to post
Share on other sites
KSum

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.

Share this post


Link to post
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
Sign in to follow this  

×