VB Script pass user input to cmd

Hi,
I need some help creating a vbscript to run a command line string to register zenworks agents to my zen server. Normally I would type it all in via command line but I want to script it so people don't need to remember all the options needed and password is not exposed in clear-text. The command normally run is "zac reg -k <keyname> -u <username> -p <password> https://servername:443"

I would like the script to prompt for username and password and give me a choice of key names to select with a radio button so only one can be chosen. Then I would like it to execute the command in a cmd window. I don't want the password to be viewable in the command executed in the cmd window. Is it possible to put it in a variable that is only used for the vbscript?

I know about the set /p command for dos but if you type set you can see the variable and password.

If you have any other ideas on how to do this I'd like to hear them. Please help!
dc3sopsAsked:
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.

merowingerCommented:
I've written the code below please give it a try.
VbScript does not support radio buttons or somthing else. If you want such a form you should use at least a .hta script
set objShell = CreateObject("Wscript.Shell")
bolCharCorrect = False
strUser = ""
strPassword = ""
strKeyname1 = "XYZ"
strKeyname2 = "ABC"
strKeyname3 = "FBI"
strKeyname4 = "ZZZ"

Do while strUser = ""
	strUser = InputBox("Please type in the user","User")
Loop

Do While strPassword = ""
	strPassword = InputBox("Please type in the password","Password")
Loop

Do While bolCharCorrect = False
	strKeycharacter = InputBox("Select your keyname and type in the related character" _
	 						&vbNewLine &"A - " &strKeyname1 _
	  						&vbNewLine &"B - " &strKeyname2 _
	   						&vbNewLine &"C - " &strKeyname3 _
	   						&vbNewLine &"D - " &strKeyname4)
	
	Select Case (Ucase(strKeycharacter))
		Case "A"
			strKeyname = strKeyname1
			bolCharCorrect = True
		Case "B"
			strKeyname = strKeyname2
			bolCharCorrect = True
		Case "C"
			strKeyname = strKeyname3
			bolCharCorrect = True
		Case "D"
			strKeyname = strKeyname4	
			bolCharCorrect = true
		Case Else
		bolCharCorrect = False
	End Select
Loop


On Error Resume Next
'return = objShell.Run ("zac reg -k " &strKeyname &" -u " &strUser &" -p " &strPassword &" https://servername:443",0,True)
WScript.Echo "zac reg -k " &strKeyname &" -u " &strUser &" -p " &strPassword &" https://servername:443"
On Error GoTo 0

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
merowingerCommented:
of forgot to say. If the command which is shown at the end is correct, then remove line 46 and uncomment line45 (remove ' character)
0
dc3sopsAuthor Commented:
Looks good so far. I have a few questions though. Is there a way to make the password appear as dots when typing? Can you change the letter selections to numbers?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

AbqBillCommented:
Hi, you can use my editv32.exe (x86) or editv64.exe (x64) program to retrieve a line of input and store it in an environment variable. If you use the -m argument on its command line, typed characters are masked with '*' characters. Example:

editv64 -m -p "Please enter the password: " _PWD

This line of code will display the prompt 'Please enter the password: ' and wait for you to type a response. Typed characters will appear as '*'. When you press Enter, the response will be stored in the _PWD environment variable. You can download editv32.exe and editv64.exe from my web site: http://www.westmesatech.com/editv.html. Hope this helps. Bill.
0
merowingerCommented:
i don't know any, but try the suggenstion from AbgBill with my script
0
RobSampsonCommented:
Hi, I have modified merowinger's code to provide the user input at the command line, which allows for the password to be hidden.

This was the source for that, if you're interested:
http://blogs.technet.com/heyscriptingguy/archive/2005/02/04/how-can-i-mask-passwords-using-an-inputbox.aspx

Regards,

Rob.
If LCase(Right(Wscript.FullName, 11)) = "wscript.exe" Then
    strPath = Wscript.ScriptFullName
    strCommand = "%comspec% /k cscript  """ & strPath & """"
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run(strCommand), 1, True
    Wscript.Quit
End If

set objShell = CreateObject("Wscript.Shell")
bolCharCorrect = False
strUser = ""
strPassword = ""
strKeyname1 = "XYZ"
strKeyname2 = "ABC"
strKeyname3 = "FBI"
strKeyname4 = "ZZZ"

Do while strUser = ""
	Wscript.StdOut.Write "Please type in the user: "
	strUser = Wscript.StdIn.ReadLine
Loop

Do While strPassword = ""
	Set objPassword = CreateObject("ScriptPW.Password") 
	WScript.StdOut.Write "Please enter your password:" 
	strPassword = objPassword.GetPassword() 
Loop

Do While bolCharCorrect = False
	strKeycharacter = InputBox("Select your keyname and type in the related character" _
	 						&vbNewLine &"A - " &strKeyname1 _
	  						&vbNewLine &"B - " &strKeyname2 _
	   						&vbNewLine &"C - " &strKeyname3 _
	   						&vbNewLine &"D - " &strKeyname4)
	
	Select Case (Ucase(strKeycharacter))
		Case "A"
			strKeyname = strKeyname1
			bolCharCorrect = True
		Case "B"
			strKeyname = strKeyname2
			bolCharCorrect = True
		Case "C"
			strKeyname = strKeyname3
			bolCharCorrect = True
		Case "D"
			strKeyname = strKeyname4	
			bolCharCorrect = true
		Case Else
		bolCharCorrect = False
	End Select
Loop


On Error Resume Next
'return = objShell.Run ("zac reg -k " &strKeyname &" -u " &strUser &" -p " &strPassword &" https://servername:443",0,True)
WScript.Echo "zac reg -k " &strKeyname &" -u " &strUser &" -p " &strPassword &" https://servername:443"
On Error GoTo 0

Open in new window

0
AbqBillCommented:
Hi all, keep in mind that the ScriptPW.Password object only exists in Windows XP. It was removed in Vista and newer versions of Windows (I don't know why). Hence other solutions are recommended, such as my editv32.exe/editv64.exe utility. For a GUI password input box, you can also use my passdlg.dll, which you can get here: http://www.westmesatech.com/passdlg/. Bill.
0
RobSampsonCommented:
Fair enough. I didn't realise it was removed from other OS's....how annoying....also on the link I provided, you can use an HTA as well, but Bill's tools will probably be easier for you.

Regards,

Rob.
0
dc3sopsAuthor Commented:
Hi guys, thanks for your input. I've been working on an HTA script since a straight up vbs won't can't handle every thing I want to do. It's almost complete. I'll post it when I'm done, some time near the end of the week I think.
0
TakedaTCommented:
I agree that an HTA is probably the best way to go with this.

But, you can get the password masked and use radio buttons in VBScript using InternetExplorer.Application.

Here is a link to code for masking the password in a IE window popup.

-http://www.robvanderwoude.com/vbstech_ui_password.php

And here is a link to a question that I answered using radio buttons in VBScript with InternetExplorer.Application

-http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_25661081.html

Combining both these methods could have done what you wanted.
0
dc3sopsAuthor Commented:
Hi guys, I finished the scripts ahead of schedule. Here they are.

Registering the agent:

<html>
<head>
<title>Register ZENworks Agent</title>
<HTA:APPLICATION 
     ID="objTest" 
     APPLICATIONNAME="Register ZENworks Agent"
     SCROLL="yes"
	 SysMenu="no"
     SINGLEINSTANCE="yes"
>
</head>
<style type="text/css">

.uberform legend {
	color: #2360B0;
}

.uberform .redbold {
	color: red;
}

.uberform form { display: block; }

.uberform fieldset
{
	margin: 10px 0;
	border: 1px solid #ccc;
	background: #efefef;
	display: block;
	padding: 5px;
}


.uberform label
{
	float: left;
	width: 150px;
	border-bottom: 1px #ccc solid;
	margin: 0 3px;
}

.uberform textarea
{
	margin: 0 10px 10px 10px;
	width: 90%;
	height: 7em;
}

.uberform ul
{
	list-style: none;
	margin: 0;
	padding: 0;
}

.uberform li
{
	margin: .4em 0;
	padding: 5px 0;
	clear: left;
}

.uberform input.submit{margin: .5em;}

.uberform .required { border: #900 1px solid; }
</style>

<SCRIPT LANGUAGE="VBScript">
Dim objShell : Set objShell = CreateObject("Wscript.Shell")

Sub Window_onLoad
    window.resizeTo 700,400
End Sub

Sub ExitProgram
        window.close()
End Sub

Sub RunProgram
	strUser = Username.Value 
	strPassword = Password.Value
	strKeyname = Regkey.Value
	'Msgbox "zac reg -g -k " &strKeyname &" -u " &strUser &" -p " &strPassword &" https://1.1.1.1:443"
    Dim objExec : Set objExec = objShell.Exec ("zac reg -g -k " &strKeyname &" -u " &strUser &" -p " &strPassword &" https://1.1.1.1:443")
Do While Not objExec.StdOut.AtEndOfStream
    strData = strData & objExec.StdOut.ReadLine & "<br />"
  Loop
  RegResults.InnerHTML = strData
  Set objExec = Nothing
End Sub

'Sub TestSub
'        If Regkey.Value = "Select" Then
'        Msgbox "Please select a registration key"
'        End If
'End Sub

</SCRIPT>

<body>
<div class="uberform column">
<fieldset> 
<legend>ZENworks Agent Registration</legend> 
<p>Enter your username and password, then select the appropriate agent to register.</p> 
<ul> 
   <li><label>Username:</label> <input type="text" name="Username" size="30" /></li> 
   <li><label>Password:</label> <input type="password" name="Password" size="30" /></li> 
   <li><label>Select Agent:</label> <select size="1" name="Regkey" onChange="TestSub">
    <option value="Agent_1">Agent_1</option>
    <option value="Agent_2">Agent_2</option>
    <option value="Agent_3">Agent_3</option>
    <option value="Agent_4">Agent_4</option>
	<option value="Agent_5">Agent_5</option>
    <option value="Agent_6">Agent_6</option>
    <option value="Agent_7">Agent_7</option>
    <option value="Agent_8">Agent_8</option>
	<option value="Agent_9">Agent_9</option>
    <option value="Agent_10">Agent_10</option>
    <option value="Agent_11">Agent_11</option>
  	<option value="Agent_12">Agent_12</option>
    <option value="Agent_13">Agent_13</option>
	<option value="Agent_14">Agent_14</option>
</select></li> 
</ul> 
</fieldset> 
<button onclick="RunProgram">Register ZENworks Agent</button>&nbsp; &nbsp; &nbsp; 
<button onclick="ExitProgram">Cancel</button>
</div>
<div class="uberform column">
<fieldset>
<legend>Results</legend>
<SPAN ID=RegResults></SPAN>
</fieldset> 
</div>
</body>

Open in new window

0
dc3sopsAuthor Commented:
Unregistering the agent:

<html>
<head>
<title>Unregister ZENworks Agent</title>
<HTA:APPLICATION 
     ID="objTest" 
     APPLICATIONNAME="Unregister ZENworks Agent"
     SCROLL="yes"
	 SysMenu="no"
     SINGLEINSTANCE="yes"
>
</head>
<style type="text/css">

.uberform legend {
	color: #2360B0;
}

.uberform .redbold {
	color: red;
}

.uberform form { display: block; }

.uberform fieldset
{
	margin: 10px 0;
	border: 1px solid #ccc;
	background: #efefef;
	display: block;
	padding: 5px;
}


.uberform label
{
	float: left;
	width: 150px;
	border-bottom: 1px #ccc solid;
	margin: 0 3px;
}

.uberform textarea
{
	margin: 0 10px 10px 10px;
	width: 90%;
	height: 7em;
}

.uberform ul
{
	list-style: none;
	margin: 0;
	padding: 0;
}

.uberform li
{
	margin: .4em 0;
	padding: 5px 0;
	clear: left;
}

.uberform input.submit{margin: .5em;}

.uberform .required { border: #900 1px solid; }
</style>

<SCRIPT LANGUAGE="VBScript">
Dim objShell : Set objShell = CreateObject("Wscript.Shell")

Sub Window_onLoad
    window.resizeTo 700,400
End Sub

Sub ExitProgram
        window.close()
End Sub

Sub RunProgram
	strUser = Username.Value 
	strPassword = Password.Value
	'Msgbox "zac unr -f -u " &strUser &" -p " &strPassword
    Dim objExec : Set objExec = objShell.Exec ("zac unr -f -u " &strUser &" -p " &strPassword)
Do While Not objExec.StdOut.AtEndOfStream
    strData = strData & objExec.StdOut.ReadLine & "<br />"
  Loop
  UnregResults.InnerHTML = strData
  Set objExec = Nothing
End Sub

</SCRIPT>

<body>
<div class="uberform column">
<fieldset> 
<legend>Unregister ZENworks Agent</legend> 
<p>Enter your username and password. Then click unregister.</p> 
<ul> 
   <li><label>Username:</label> <input type="text" name="Username" size="30" /></li> 
   <li><label>Password:</label> <input type="password" name="Password" size="30" /></li> 
</ul> 
</fieldset> 
<button onclick="RunProgram">Unregister ZENworks Agent</button>&nbsp; &nbsp; &nbsp; 
<button onclick="ExitProgram">Cancel</button>
</div>
<div class="uberform column">
<fieldset>
<legend>Results</legend>
<SPAN ID=UnregResults></SPAN>
</fieldset> 
</div>
</body>

Open in new window

0
dc3sopsAuthor Commented:
Although I found (created)  the answer myself, the experts pointed me in the right direction and provided useful information that I wouldn't have known otherwise. Before this I never heard of and HTA (HTML Application).
0
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
Visual Basic Classic

From novice to tech pro — start learning today.