随笔 - 64, 文章 - 11, 评论 - 12, 引用 - 0
数据加载中……

搭建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


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

posted on 2009-02-23 10:59 Robertxiao 阅读(1593) 评论(0)  编辑 收藏 引用 所属分类: 天马行空


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理