Sign in to follow this  
Followers 0
PDowning

RunAs() arguments

26 posts in this topic

I'm sure it's been covered, but I keep getting confused on how many " or ' should be in the line. Here is what I am attempting:

RunAs("administrator", "domain", "password", "msiexec.exe " I:\launcherapps\Language Arts\Reading\Read Out Loud.msi"")

I keep getting syntax errors.  Yes I could define :  $RunMSI =  " I:launcherappsLanguage ArtsReadingRead Out Loud.msi" ,  and then run a ShellExecute($RunMSI), but the stupid program keeps telling me the logged in user doesn't have rights to a directory and fails out, so I need to do a RunAs().

Right?

Share this post


Link to post
Share on other sites



I'm guessing I: is a network location? Use the absolute name (UNC Path) instead of the drive letter, because the user credentials aren't going to have the I: drive.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I'm guessing I: is a network location? Use the absolute name (UNC Path) instead of the drive letter, because the user credentials aren't going to have the I: drive.

 

good thought, but this script will be used globally, so I can't hardcode it for a server name.  I need to use the I: mapping.

Share this post


Link to post
Share on other sites

I'm sure it's been covered, but I keep getting confused on how many " or ' should be in the line. Here is what I am attempting:

RunAs("administrator", "domain", "password", "msiexec.exe " I:\launcherapps\Language Arts\Reading\Read Out Loud.msi"")

I keep getting syntax errors.  Yes I could define :  $RunMSI =  " I:launcherappsLanguage ArtsReadingRead Out Loud.msi" ,  and then run a ShellExecute($RunMSI), but the stupid program keeps telling me the logged in user doesn't have rights to a directory and fails out, so I need to do a RunAs().

Right?

 

does

RunAs("administrator", "domain", "password", 'msiexec.exe " I:launcherappsLanguage ArtsReadingRead Out Loud.msi"')

( single quote) work ?

Nigel

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

good thought, but this script will be used globally, so I can't hardcode it for a server name.  I need to use the I: mapping.

My point was you shouldn't be using the I: drive because the credentials you're using in the RunAs won't have an I: drive, if the I: drive is a network share. They may have access to the drive's location, but there won't be a drive named I:.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

does

RunAs("administrator", "domain", "password", 'msiexec.exe " I:launcherappsLanguage ArtsReadingRead Out Loud.msi"')

( single quote) work ?

Nigel

No that gets me :   RunAs() [built-in] called with wrong number of args.

Is there a way I can just define the msiexec portion as a variable and pass that into the RunAs() instead?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

My point was you shouldn't be using the I: drive because the credentials you're using in the RunAs won't have an I: drive, if the I: drive is a network share. They may have access to the drive's location, but there won't be a drive named I:.

 

Ok gave this a shot: 

RunAs("administrator", "domain", "password", "msiexec.exe", "\\server\apps$\courseap\launcherapps\Language Arts\Reading\Read Out Loud.msi")

I get no errors, but it appears the script isn't functioning either.  The msi obviously isn't set to quiet or passive mode, so I should see it loading the msi, but I get nothing. 

Edit: fixed the unc designation

Edit2:   I have also tried adding this:

$RunMSI = "\\server\apps$\courseap\launcherapps\Language Arts\Reading\Read Out Loud.msi"

And changed the Runas() to: 

RunAs("administrator", "domain", "password", "msiexec.exe", $RunMSI)

Again, no errors, and it runs anything else that is in the script. Baffled ....

Edited by PDowning

Share this post


Link to post
Share on other sites

I put the compiled AutoIt script in a folder above the install, relative to the location of the msi, and then use the following to find the location.  I have fond times when @ScriptDir reports back a drive and others that it reports a UNC, but do not know when or why.

#include <WinNet.au3>

; Get the current location of this script
$ScriptPath = @ScriptDir

;Make sure it is a UNC and not a mapped drive
if StringInStr($ScriptPath, ":") > 0 Then
    $MyPath = _WinNet_GetUniversalName($ScriptPath)
    $ScriptPath = $MyPath[0]
EndIf

From here, I can use $ScriptPath and add the rest of the path to the msi.  In your case, I may put the AutoIt executable in serverapps$courseaplauncherapps.  Also, just to be sure, I would want to be sure that I have quotes around the ,si path & file since there are spaces.  So I would have:

$msiPath = '"' & $ScriptPath & '\Language Arts\Reading\Read Out Loud.msi"'

RunAs("administrator", "domain", "password", "msiexec.exe", $msiPath)

Karl

Share this post


Link to post
Share on other sites

Your parameters for RunAs are wrong. You have "msiexec.exe" in the logon flag location. You should probably move that to the "program" location and append the MSI filename and path to the command to run. You might also want to add the full path to msiexe.exe as well as putting quotes around the MSI path/filename string.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

msiexec /i "i:\launcherapps\language arts\reading\read out loud.msi"

that line works just fine from the CMD prompt.  just the RunAs() doesn't like it.  Trying the other suggestion as well.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Good catch.  I blindly copied the RunAs and made the minor change to use a variable.  From a script I have that works well, modified slightly to match your use:

#include <WinNet.au3>

; Get the current location of this script
$ScriptPath = @ScriptDir

;Make sure it is a UNC and not a mapped drive
if StringInStr($ScriptPath, ":") > 0 Then
     $MyPath = _WinNet_GetUniversalName($ScriptPath)     $ScriptPath = $MyPath[0]
EndIf



;set variables for the command
$msiPath = '"' & $ScriptPath & '\Language Arts\Reading\Read Out Loud.msi"'
$InstallCommand = 'msiexec /i "' & $msiPath

;Run the command
$pid = RunAsWait($sUserName, $sDomain, $sPassword, 2, $InstallCommand, @TempDir, @SW_ENABLE)

If $pid = 0 AND @error <> 0 Then
     MsgBox( 4096, "Installer", "Unable to Install Program.  Run failed. Error = " & @error)
     MsgBox( 4096, "Installer", "Installation Aborted. " & $InstallCommand)
Exit
Else
     MsgBox(0, "MSI Command", "Command Run Succesfully.")
EndIf

 

I used RunAsWait so I could display a message when it was done.

Sorry for the confusion...

Edited by KSum

Share this post


Link to post
Share on other sites

I put the compiled AutoIt script in a folder above the install, relative to the location of the msi, and then use the following to find the location.  I have fond times when @ScriptDir reports back a drive and others that it reports a UNC, but do not know when or why.

#include <WinNet.au3>

; Get the current location of this script
$ScriptPath = @ScriptDir

;Make sure it is a UNC and not a mapped drive
if StringInStr($ScriptPath, ":") > 0 Then
    $MyPath = _WinNet_GetUniversalName($ScriptPath)
    $ScriptPath = $MyPath[0]
EndIf

From here, I can use $ScriptPath and add the rest of the path to the msi.  In your case, I may put the AutoIt executable in serverapps$courseaplauncherapps.  Also, just to be sure, I would want to be sure that I have quotes around the ,si path & file since there are spaces.  So I would have:

$msiPath = '"' & $ScriptPath & '\Language Arts\Reading\Read Out Loud.msi"'

RunAs("administrator", "domain", "password", "msiexec.exe", $msiPath)

Karl

 

Ok made the attempt at this and found a minor bug when reporting back the $msipath. It was returning the path doubled. so I removed the "language artsreading" portion from the $msi path. it now reports the correct path, but still won't run the msi.

Share this post


Link to post
Share on other sites

If both the AutoIt script and the msi file are in teh same folder, then yes, remove that portion.  Be sure to add a backslash to the folder $msiPath and use the second example as it fixes the command to be all together and defines the logon flag.  $msiPath should end up for you as:

$msiPath = '"' & $ScriptPath & '\Read Out Loud.msi"'

Share this post


Link to post
Share on other sites

Good catch.  I blindly copied the RunAs and made the minor change to use a variable.  From a script I have that works well, modified slightly to match your use:

#include <WinNet.au3>

; Get the current location of this script
$ScriptPath = @ScriptDir

;Make sure it is a UNC and not a mapped drive
if StringInStr($ScriptPath, ":") > 0 Then
     $MyPath = _WinNet_GetUniversalName($ScriptPath)     $ScriptPath = $MyPath[0]
EndIf



;set variables for the command
$msiPath = '"' & $ScriptPath & '\Language Arts\Reading\Read Out Loud.msi"'
$InstallCommand = 'msiexec /i "' & $msiPath

;Run the command
$pid = RunAsWait($sUserName, $sDomain, $sPassword, 2, $InstallCommand, @TempDir, @SW_ENABLE)

If $pid = 0 AND @error <> 0 Then
     MsgBox( 4096, "Installer", "Unable to Install Program.  Run failed. Error = " & @error)
     MsgBox( 4096, "Installer", "Installation Aborted. " & $InstallCommand)
Exit
Else
     MsgBox(0, "MSI Command", "Command Run Succesfully.")
EndIf

 

I used RunAsWait so I could display a message when it was done.

Sorry for the confusion...

 

 

 

 

If both the AutoIt script and the msi file are in teh same folder, then yes, remove that portion.  Be sure to add a backslash to the folder $msiPath and use the second example as it fixes the command to be all together and defines the logon flag.  $msiPath should end up for you as:

$msiPath = '"' & $ScriptPath & '\Read Out Loud.msi"'

Correct, they are in the same path. but nothing happens. the script executes and just sits there till i hit ctrl-break to stop it.

Share this post


Link to post
Share on other sites

Whoops double-tap ...

Share this post


Link to post
Share on other sites

ok figured out why it isn't working. After a few placed msgbox's,  $ScriptPath gets no value before the If .. Then statement.  Inside the If statement,  $MyPath gets no value as well, therefore $ScriptPath gets no value either.

Share this post


Link to post
Share on other sites

Can you do a msgbox on @ScriptDir please and see if it gives a value?  It should and $ScriptPath should be set to that value.

Share this post


Link to post
Share on other sites

Can you do a msgbox on @ScriptDir please and see if it gives a value?  It should and $ScriptPath should be set to that value.

 

It returns the correct mapped drive value of  I:launcherappslanguage artsreading

Share this post


Link to post
Share on other sites

And you have this line before the first IF statement?

$ScriptPath = @ScriptDir

Use a msgbox to Check the value of $ScriptPath right after that line, please.

Share this post


Link to post
Share on other sites

And you have this line before the first IF statement?

$ScriptPath = @ScriptDir

Use a msgbox to Check the value of $ScriptPath right after that line, please.

#include <WinNet.au3>


; Get the current location of this script
$ScriptPath = @ScriptDir


MsgBox(0, "scriptdir", @ScriptDir)
msgbox(0, "titlealpha", "scriptpath = ", $ScriptPath)

That's the code. 

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  
Followers 0