- 'By zqz0012005@www.bathome.cn
- 'Version: 0.3 2008-06-18
-
- On Error Resume Next
-
- host = WScript.FullName
- f0 = WScript.ScriptFullName
- dp0 = Left( f0, InstrRev(f0,"\") )
-
- if LCase( right(host, len(host)-InStrRev(host,"\")) ) = LCase("wscript.exe") then
- CreateObject("WScript.Shell").run "cmd /d /ccolor f9&title vbs-cmd" &_
- "&cscript //logo """ & f0 & chr(34)
- WScript.Quit
- end if
-
- set ws = CreateObject("WScript.Shell")
- set wn = CreateObject("WScript.Network")
- set fso = CreateObject("Scripting.FileSystemObject")
- set dict = CreateObject("Scripting.Dictionary")
- set sh = CreateObject("Shell.Application")
- set wmi = GetObject("winmgmts:{(debug, security, shutdown)}!\\.\root\cimv2")
-
- 'set colps = wmi.instancesOf("win32_process")
- 'set colps = GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_
-
- set stdin = WScript.stdin
- set stdout = WScript.stdout
- stdout.writeline "可以直接运行vbs语句,要运行cmd命令,请在命令前加'cmd '(cmd空格)"
-
- do
- stdout.writeBlankLines(1)
- stdout.write ws.CurrentDirectory & vbCrLf & "# "
- s=Trim(stdin.readLine)
- Select Case 0
- Case StrComp(s,"exit",1) wsh.quit
- Case StrComp(left(s,2),"cd",1)
- if mid(s,3)="" then
- wsh.echo ws.CurrentDirectory
- elseif mid(s,3,1)=" " then
- ws.CurrentDirectory = LTrim(mid(s,3))
- else
- execStatementBlock
- end if
- Case StrComp(left(s,4),"cmd ",1)
- set oexec=ws.exec( "cmd /d /q /c" & LTrim(mid(s,4)) & "&exit" )
- 'oexec.stdin.writeLine vbCrLf & "exit"
- stdout.write oexec.stdout.readall & oexec.stderr.readall
- set oexec=nothing
- Case StrComp(left(s,5),"wmic ",1)
- set oexec=ws.exec("cmd /d /q /c echo exit|" & s)
- 'oexec.stdin.writeLine vbCrLf & "exit"
- stdout.write oexec.stdout.readall & oexec.stderr.readall
- set oexec=nothing
- Case StrComp(s,"help",1) call help()
- Case StrComp(s,"") 'do nothing
- Case Else
- LastCode = execStatementBlock()
- 'Case Else execute s
- 'Case Else wsh.echo "[" & s & "]"
- End Select
- showErrMsg
- loop
-
- function execStatementBlock()
- dim i, t
- ReDim a(0)
- a(0) = s
- stdout.write "More? "
- t = Trim(stdin.readLine)
- do until t=""
- i = i + 1
- ReDim Preserve a(i)
- a(i) = t
- stdout.write "More? "
- t = Trim(stdin.readLine)
- loop
- execute Join(a, ":")
- execStatementBlock = Join(a, vbCrLf)
- end function
-
- sub help()
- stdout.writeline vbCrLf & "可以直接运行vbs语句,在More? 提示符后直接回车以完成输入。"
- stdout.writeline "要运行cmd命令,请在命令前加'cmd '(cmd空格)。wmic类似。" & vbCrLf
- stdout.writeLine "显示环境变量:printenv"
- stdout.writeLine "f0 = " & f0
- stdout.writeLine "dp0 = " & dp0
- stdout.writeLine "常用对象:"
- stdout.writeLine "ws = CreateObject(""WScript.Shell"")"
- stdout.writeLine "wn = CreateObject(""WScript.Network"")"
- stdout.writeLine "fso = CreateObject(""Scripting.FileSystemObject"")"
- stdout.writeLine "dict = CreateObject(""Scripting.Dictionary"")"
- stdout.writeLine "sh = CreateObject(""Shell.Application"")"
- stdout.writeLine "wmi = GetObject(""winmgmts:{(debug, security, shutdown)}!\\.\root\cimv2"")"
- end sub
-
- sub showErrMsg()
- if err.number<>0 then
- wsh.echo err.source & "[errno=" & err.number & "]: " & err.description
- err.clear
- end if
- end sub
-
- sub calc(expression)
- wsh.echo eval(expression)
- end sub
-
- sub ps()
- dim colProc, proc
- set colProc = wmi.ExecQuery("select * from Win32_Process")
- for each proc in colProc
- wsh.echo proc.name
- wsh.echo proc.ExecutablePath
- wsh.echo proc.CommandLine
- wsh.echo ""
- next
- end sub
-
- sub printenv()
- dim envType, envset, env, i
- envType = Array("system","process","user","Volatile")
- for i=0 to UBound(envType)
- wsh.echo vbCrLf & envType(i) & "类型的环境变量:"
- set envset = ws.Environment(envType(i))
- for each env in envset
- wsh.echo env
- next
- next
- end sub
-
- sub env()
- printenv()
- end sub
-
- sub dir()
- end sub
-
- 'To be continued to complete and improve
复制代码
|