LancIT

MSI File as Administrator

5 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I'm trying to run a simple .MSI file as our Domain Admin account to install something.

I'm totally new to this and my scripting skills are... Poor, so any help really appreciated. 

I've tried reading up, but so far I'm stuck.

Here's my script - Don't laugh!

; Script Start - Add your code below here
Local $sUserName = "account"
Local $sPassword = "password"
Local $sDomain = "domain"
 
RunAsWait($sUserName, $sDomain, $sPassword, 0, ("msiexec /i "C:FileInstaller.msi""))

i get this error:
Line 6 (File "C:File.au3"):
 
RunAsWait($sUserName, $sDomain, $sPassword, 0, ("msiexec /i "C:FileInstaller.msi""))
RunAsWait($sUserName, £sDomain, $sPassword, 0, ("msiexec /i "C:^ ERROR

Error: Unable to parse line.

 

 
 
 
I've tried many different variations, but it still keeps failing... Tell me I'm missing something really silly, or the script is just totally wrong??
Edited by LancIT

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi, and welcome to the forum.

If you want to use doublequotes inside a string delimited by doublequotes, you need to double the doublequotes (autoit's way of "escaping", many other languages do it by placing a backslash in front of them).

So instead of "this string contains " a doublequote", you write: "this string contains "" a doublequote".

Because you did not, your string is terminated after the "/i " part and the rest C:...blah... is interpreted as AutoIt language instead of as the rest of your string. As it is not valid AutoIt language, the procedure fails.

Also, it should not be necessary to put the file inside of parentheses.

Try:

RunAsWait($sUserName, $sDomain, $sPassword, 0, "msiexec /i ""C:\File\Installer.msi""")

Note that at the end, there are three doublequotes. The first two to make one doublequote in the string, and the third to end the string.

AutoIt also supports 'single quotes' as string delimiters, which makes life easier in these situations, because it eliminates the need to double the doublequotes (though you'd have to double the single quotes - luckily you don't need them in this particular string :) ):

RunAsWait($sUserName, $sDomain, $sPassword, 0, 'msiexec /i "C:\File\Installer.msi"')

/edit: Why would anyone laugh at you? You actually took the time and effort to formulate your question well.  :thumbsup:  Can't say that for every first post... 

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

RunAsWait($sUserName, $sDomain, $sPassword, 0, ("msiexec /i "C:FileInstaller.msi"")) The Highlighted quote is ending the string, so use this: RunAsWait($sUserName, $sDomain, $sPassword, 0, ('msiexec /i "C:FileInstaller.msi"'))


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Hi, and welcome to the forum.

If you want to use doublequotes inside a string delimited by doublequotes, you need to double the doublequotes (autoit's way of "escaping", many other languages do it by placing a backslash in front of them).

So instead of "this string contains " a doublequote", you write: "this string contains "" a doublequote".

Because you did not, your string is terminated after the "/i " part and the rest C:...blah... is interpreted as AutoIt language instead of as the rest of your string. As it is not valid AutoIt language, the procedure fails.

Also, it should not be necessary to put the file inside of parentheses.

Try:

RunAsWait($sUserName, $sDomain, $sPassword, 0, "msiexec /i ""C:\File\Installer.msi""")

Note that at the end, there are three doublequotes. The first two to make one doublequote in the string, and the third to end the string.

AutoIt also supports 'single quotes' as string delimiters, which makes life easier in these situations, because it eliminates the need to double the doublequotes (though you'd have to double the single quotes - luckily you don't need them in this particular string :) ):

RunAsWait($sUserName, $sDomain, $sPassword, 0, 'msiexec /i "C:\File\Installer.msi"')

/edit: Why would anyone laugh at you? You actually took the time and effort to formulate your question well.  :thumbsup:  Can't say that for every first post... 

 

Hi, and welcome to the forum.

If you want to use doublequotes inside a string delimited by doublequotes, you need to double the doublequotes (autoit's way of "escaping", many other languages do it by placing a backslash in front of them).

So instead of "this string contains " a doublequote", you write: "this string contains "" a doublequote".

Because you did not, your string is terminated after the "/i " part and the rest C:...blah... is interpreted as AutoIt language instead of as the rest of your string. As it is not valid AutoIt language, the procedure fails.

Also, it should not be necessary to put the file inside of parentheses.

Try:

RunAsWait($sUserName, $sDomain, $sPassword, 0, "msiexec /i ""C:\File\Installer.msi""")

Note that at the end, there are three doublequotes. The first two to make one doublequote in the string, and the third to end the string.

AutoIt also supports 'single quotes' as string delimiters, which makes life easier in these situations, because it eliminates the need to double the doublequotes (though you'd have to double the single quotes - luckily you don't need them in this particular string :) ):

RunAsWait($sUserName, $sDomain, $sPassword, 0, 'msiexec /i "C:\File\Installer.msi"')

/edit: Why would anyone laugh at you? You actually took the time and effort to formulate your question well.  :thumbsup:  Can't say that for every first post... 

Thanks guys, I'm going to test this now.

Much appriciated! 

I'm a heavy forum user, So I know how to setup first posts, luckily! Nothing more annoying than "Help... It won't work" style posts :P

1 person likes this

Share this post


Link to post
Share on other sites

Not too often would I have a file that the user would run where I need to put the Admin permissions in the file, usually I as an administrator would run it.

On the occasion I do need them to run a file, I personally would not feel comfortable putting the credentials right in the script like that.

There are a few Autoit only ways to do it safer, but the easiest for me was to use a free download called RunAsSPC

http://www.robotronic.de/runasspcEn.html

Its not perfect in its own right but it worked for me.  I embed the needed files with FileInstall and invoke RunAsSPC silently via CMD so that the files are run as an admin.

The other way to put credentials in the code and make it a bit more safe is with the crypt/decrypt functions, but it could still be reversed easier than the RunAsSPC encrypted certificate. 

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