darcmarc
Joined: 22 Feb 2005 Posts: 10 Location: USA
|
Posted: Wed Jun 08, 2005 11:10 pm Post subject: |
|
|
I couldn't find a way to get user input on all operating systems, but I think i've finally figured it out. Using HTA and VBscripts.
This one gets input from a menu:
| Code: |
@echo off
::
:: file:choice.cmd; author:they; copyright:none; date:060805;
:: contact:darcmarc@gmail.com;
::
:: This batch file will create an HTML Application (HTA).
:: Values entered in the HTA will be saved as %TEMP%\USERIN.BAT
:: After the USERIN.BAT is CALLed from the main batch
:: (and assuming there is enough room in the environment)
:: environmental variable 'o' will be set.
:BEGIN
cls
echo Another User Input Test!
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the HTA
type %0 | find " " | find /v "Not Me!" > %TEMP%\UserIn.hta
:: Open the HTA and set the vars
start /w %TEMP%\UserIn.hta
call %TEMP%\UserIn.bat
echo Your Choice was was option: %o%
pause
:: Clean up
del %TEMP%\UserIn.hta
del %TEMP%\UserIn.bat
goto DONE
:ERROR
cls
echo %0 is not the full path and file name
echo for the batch file. You MUST call this
echo batch file with a full path and file name.
goto EOF
:HTA
:: All HTA code MUST be indented four or more spaces.
:: NOTHING else in this batch file may be indented four spaces.
<html>
<head>
<title>Menu Choice</title>
<hta:application>
<script language="vbscript">
window.resizeTo 300,250
Sub SaveBatch()
Set fs = CreateObject("Scripting.FileSystemObject")
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
Set ts = fs.OpenTextFile(strFile, 2, True)
ts.WriteLine "SET o=" & document.Forms(0).elements("choice").value
ts.Close
End Sub
</script>
</head>
<body>
<h3>Pick an Option!</h3>
<form>
Choices:<br>1. Blah!<br>2. Blah!<br>3. Blah!<br>
<select size="1" name="choice">
<option value="option1">1</option>
<option value="option2">2</option>
<option value="option3">3</option>
</select>
<br><input type=submit language="vbscript" value="OK"
onclick="SaveBatch : Window.Close">
</form>
<script language=vbscript>
document.Forms(0).elements("choice").focus
</script>
</body>
</html>
:EOF
|
This one gets input from text fields, like the user/password combo I've done:
| Code: |
@echo off
::
:: file:pass.cmd; author:they; copyright:none; date:060805;
:: contact:darcmarc@gmail.com;
::
:: This batch file will create an HTML Application (HTA).
:: Values entered in the HTA will be saved as %TEMP%\USERIN.BAT
:: After the USERIN.BAT is CALLed from the main batch
:: (and assuming there is enough room in the environment)
:: environmental variables USERNAME and PASSWORD will be set.
:BEGIN
cls
echo Please enter your user name and password in the entry box...
:: See if I can find myself
If not exist %0 goto ERROR
:: Make the web page
type %0 | find " " | find /v "Not Me!" > %TEMP%\UserIn.hta
:: Run the vbs code
start /w %TEMP%\UserIn.hta
call %TEMP%\UserIn.bat
echo Your username is %USERNAME%
echo Your password is %PASSWORD%
pause
:: Clean up
del %TEMP%\UserIn.hta
del %TEMP%\UserIn.bat
goto DONE
:ERROR
cls
echo %0 is not the full path and file name
echo for the batch file. You MUST call this
echo batch file with a full path and file name.
goto DONE
:HTA
:: All HTA code MUST be indented four or more spaces.
:: NOTHING else in this batch file may be indented four spaces.
<html>
<head>
<title>Password Entry</title>
<hta:application>
<script language="vbscript">
window.resizeTo 250,200
Sub SaveBatch()
Set fs = CreateObject("Scripting.FileSystemObject")
strFile = fs.GetAbsolutePathName(fs.BuildPath(fs.GetSpecialFolder(2), "UserIn.bat"))
Set ts = fs.OpenTextFile(strFile, 2, True)
ts.WriteLine "SET USERNAME=" & document.Forms(0).elements("username").value
ts.WriteLine "SET PASSWORD=" & document.Forms(0).elements("password").value
ts.Close
End Sub
</script>
</head>
<body>
<form>
User Name:
<br><input type=text name=username tabindex=1>
<br>Password:
<br><input type=password name=password>
<br><input type=submit language="vbscript" value="OK"
onclick="SaveBatch : Window.Close">
</form>
<script language=vbscript>
document.Forms(0).elements("username").focus
</script>
</body>
</html>
:EOF
|
Run those and tell me what you think! Enjoy!
If you don't want to copy those and would just rather download the .cmd file, they can be got here:
http://darcmarc.servehttp.com/exe/choice.cmd
http://darcmarc.servehttp.com/exe/pass.cmd
(The file extention rather cmd or bat does not matter here. cmd might not run on win 98 or older.)
Edited By darcmarc on 1119670120 |
|