Reputation: 55
I'm attempting to create a basic Run command emulator using VBScript, or .bat if that would be easier.
I have had no formal education on these languages, but can do very basic functions from looking at forums and web help. I need this code to be able to request user input for the program they want to open (input box function) and actually open the program.
The server I work at has both Run and CMD blocked, but not written scripts.
Any help would be appreciated.
~Jester
Upvotes: 1
Views: 409
Reputation:
This runs CMD and captures it's output.
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Set cmd = CreateObject("Wscript.Shell").Exec("cmd")
cmd.stdin.writeline "dir"
wscript.sleep 20000
cmd.stdin.writeline "dir"
cmd.stdin.writeline "exit"
Do While Not cmd.stdout.AtEndOfStream
results = cmd.stdout.readall
If err.number <> 0 then Exit Do
wscript.echo results
Loop
'wscript.sleep 5000
This shows making your own console program. Most menu options don't do anything.
Set Arg = WScript.Arguments
set WshShell = createObject("Wscript.Shell")
Set Inp = WScript.Stdin
Set Outp = Wscript.Stdout
Showmenu
Sub ShowHelpMenu
outp.writeline " -----------------------------------------------------------------------------"
outp.writeblanklines(1)
outp.writeline " Menu"
outp.writeline " ----"
outp.writeblanklines(1)
outp.writeline " 1 Help 2 HTML Help 3 Version 4 History"
outp.writeblanklines(1)
outp.writeline " 5 Exit"
outp.writeblanklines(1)
outp.write "Filter>"
End Sub
'=============================================
Sub ShowMenu
Do
ShowHelpMenu
Answ=Inp.read(1)
Outp.write Answ
' Answ=Inp.readline
If Answ = "1" Then
ShowGeneralHelp "TEXT"
Elseif Answ = "2" Then
ShowGeneralHelp "HTML"
Elseif Answ = "3" Then
Version
Elseif Answ = "4" Then
History
Elseif Answ = "5" Then
Exit Do
End If
Loop
End Sub
'=============================================
Sub History
On Error Resume Next
WshShell.Run """" & FilterPath & "FilterHistory.txt""" , 1, False
err.clear
End Sub
'=============================================
Sub Version
outp.writeblanklines(1)
outp.writeline " Version"
outp.writeline " -------"
outp.writeblanklines(1)
outp.writeline " Filter Ver 0.6 - 2015 (Public Domain)"
outp.writeblanklines(1)
outp.writeline " by David Candy"
outp.writeblanklines(1)
End Sub
This shows a basic batch.
:start
set /p CMDToExec=Enter Command
%CMDToExec%
Goto Start
Upvotes: 3