在行「If(IsNull(value))then」下面是我的代碼是否正確?我想檢查註冊表項是否存在,如果不存在,則顯示一個網頁。vbscript and checking for null
Option Explicit
On error resume next
Dim SysVarReg, Value
Set SysVarReg = WScript.CreateObject("WScript.Shell")
value = SysVarReg.RegRead ("HKCU\Software\test\FirstLogonComplete")
If (IsNull(value)) then
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "c:\Program Files\Internet Explorer\iexplore.exe https://intranet/start.htm"
Dim SysVarReg2, Value2
Value2 = "TRUE"
Set SysVarReg2 = WScript.CreateObject("WScript.Shell")
SysVarReg2.RegWrite "HKCU\Software\test\FirstLogonComplete", Value2
else
wscript.echo "Already logged on"
end if
這裏的關鍵(沒有雙關語意)是RegRead [拋出一個錯誤(HTTP ://msdn.microsoft.com/en-us/library/x05fawxd%28v=vs.84%29.aspx)如果該鍵不存在,並且OP已打開「On Error Resume Next」。或者,可以使用'IsEmpty(value)'而不是'IsNull(value)'。 – 2013-01-08 05:24:10