我正在尝试使用VBScript或.bat创建一个基本的Run命令模拟器,如果这更容易。
我没有接受过这些语言的正规教育,但可以通过查看论坛和网络帮助来完成非常基本的功能。我需要这段代码才能为他们想要打开的程序请求用户输入(输入框功能)并实际打开程序。
我工作的服务器同时阻止了Run和CMD,但没有写入脚本
任何帮助将不胜感激
〜小丑
答案 0 :(得分:3)
这会运行CMD并捕获它的输出。
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
这显示了制作自己的控制台程序。大多数菜单选项都没有做任何事情。
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
这显示了一个基本批次。
:start
set /p CMDToExec=Enter Command
%CMDToExec%
Goto Start