Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Batch or Vbs Script to install application with admin Credentials

Posted on 2009-04-20
5
Medium Priority
?
3,281 Views
Last Modified: 2012-06-22
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?
0
Comment
Question by:ahen0342
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:TakedaT
ID: 24189815
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
 

Author Comment

by:ahen0342
ID: 24195059
the installation file is on the network IE do I need to put " marks aroud the location?
0
 
LVL 10

Expert Comment

by:TakedaT
ID: 24195141
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
 

Author Comment

by:ahen0342
ID: 24195756
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
 
LVL 10

Accepted Solution

by:
TakedaT earned 2000 total points
ID: 24196024
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question