Batch or Vbs Script to install application with admin Credentials

Hi:
I am trying to run a batch file that will install a program.  The program can only be installed with admin rights. how do i run the batch or vbs script with admin credentials and not show the password.  Is there a way to do this with the runas command, or AutoIT?
ahen0342Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TakedaTCommented:
I know you asked for a batch file, but as far as i know, the "runas" command wont allow a command line password.  I have used vbscript to work around this.  Here is the code I used.  Change the lines to use your desired username and also the sendkeys line with your password.  And of course change the program from calc to whatever program you want to run.

Set objShell = CreateObject("wscript.shell")
objShell.run "cmd /c title RUNASINSTALL & runas /user:administrator calc"
Success=False
For i=0 to 5 or Success
	wscript.sleep 100
	Success=objShell.AppActivate("RUNASINSTALL")
	i=i+1
Next
If Success then
	wscript.sleep 100
	objShell.SendKeys "YOURPASSWORDGOESHERE{ENTER}"
End if

Open in new window

0
ahen0342Author Commented:
the installation file is on the network IE do I need to put " marks aroud the location?
0
TakedaTCommented:
Yea..sorry about that.  I surrounded the program part with chr(34) which does exactly that.
Set objShell = CreateObject("wscript.shell")
objShell.run "cmd /c title RUNASINSTALL & runas /user:administrator "&chr(34)&"yourfullpathhere"&chr(34)
Success=False
For i=0 to 5 or Success
	wscript.sleep 100
	Success=objShell.AppActivate("RUNASINSTALL")
	i=i+1
Next
If Success then
	wscript.sleep 100
	objShell.SendKeys "YOURPASSWORDGOESHERE{ENTER}"
End if

Open in new window

0
ahen0342Author Commented:
I do not understand what your saying for example
network location = \\test\cmt\time.bat would:
objShell.run "cmd /c title RUNASINSTALL & runas /user:password ""\\test\cmt\time.bat"
0
TakedaTCommented:
I changed the order of the script to make it easier to understand.  The only lines you may need to change is the first 3.  Each line needs to have your text after the = sign surrounded by one, and only one, double quote on each side just as its shown.

strUsername = "administrator"
strPassword = "password"
strPath = "\\test\cmt\time.bat"
 
Set objShell = CreateObject("wscript.shell")
objShell.run "cmd /c title RUNASINSTALL & runas /user:"&strUsername&" "&chr(34)&strPath&chr(34)
Success=False
For i=0 to 5 or Success
	wscript.sleep 100
	Success=objShell.AppActivate("RUNASINSTALL")
	i=i+1
Next
If Success then
	wscript.sleep 100
	objShell.SendKeys strPassword&"{ENTER}"
End if

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.