搭建Vbscript脚本开发环境

搭建Vbscript脚本开发环境

      添加新建Vbscript 文件的快捷菜单

filetype = ".vbs"
set WSHShell = CreateObject("WScript.Shell")
prg = ReadReg("HKCR\" & filetype & "\")
prgname = ReadReg("HKCR\" & prg & "\")
ask = "what shoud be the name for new VBScript scripts?"
title = "New menu entry"
prgname = InputBox(ask, title, prgname)
WSHShell.RegWrite "HKCR\" & prg & "\",prgname
WSHShell.RegWrite "HKCR\" & filetype & "\ShellNew\NullFile", ""
function ReadReg(key)
  on error resume next
  ReadReg = WSHShell.RegRead(key)
  if err.Number > 0 then
   error = "Error: Registry-key""" & key & """ could not be found!"
   msgbox error, vbCritical
   WScript.Quit
  end if
end function


      创建Vbscript调试快捷菜单

Set wshshell = CreateObject("wscript.shell")
vbsfile = wshshell.regread("HKCR\.vbs\")
master = "HKCR\" & vbsfile & "\shell\"
wshshell.regwrite master & "debug\", "&Debug"
wshshell.regwrite master & "debug\command\", "wscript.exe //x ""%L"""
wshshell.regwrite master & "check\", "&Monitor"
wshshell.regwrite master & "check\command\", "wscript.exe //D ""%L"""
MsgBox "Debugging Command Setup Successful"

      写私有日志

Set wshshell = CreateObject("wscript.shell")
Set fs = CreateObject("Scripting.FileSystemObject")
windir = wshshell.ExpandEnvironmentStrings("%WINDIR%")
logfile = windir & "\wsh.log"
debugging = True
LogIt "Script has started."
LogIt "Loop is entered."
For x = 1 To 10
 LogIt "Variable x:" & x
Next
LogIt "Loop is done."
MsgBox "done!"
LogIt "Script is done."

Sub LogIt(text)
 If Not debugging Then Exit Sub
 Set output = fs.OpenTextFile(logfile, 8, True, -2)
 output.writeLine Now() & vbTab & "Information: " & text
 output.close
End Sub


声明:上述内容来源脚本编程的相关书中。

你可能感兴趣的:(搭建Vbscript脚本开发环境)