dc3sops
asked on
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
of forgot to say. If the command which is shown at the end is correct, then remove line 46 and uncomment line45 (remove ' character)
ASKER
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?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i don't know any, but try the suggenstion from AbgBill with my script
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
Regards,
Rob.
ASKER
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi guys, I finished the scripts ahead of schedule. Here they are.
Registering the agent:
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>
<button onclick="ExitProgram">Cancel</button>
</div>
<div class="uberform column">
<fieldset>
<legend>Results</legend>
<SPAN ID=RegResults></SPAN>
</fieldset>
</div>
</body>
ASKER
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>
<button onclick="ExitProgram">Cancel</button>
</div>
<div class="uberform column">
<fieldset>
<legend>Results</legend>
<SPAN ID=UnregResults></SPAN>
</fieldset>
</div>
</body>
ASKER
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).