On the line "If (IsNull(value)) then" below is my code correct? I want to check if the registry key exists and if not then show a web page.
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
The IsNull function returns a Boolean value that indicates whether a specified expression contains no valid data (Null). It returns True if expression is Null; otherwise, it returns False.
In VBScript—where all variables are variants—variables can be one of two special values: EMPTY or NULL. EMPTY is defined as a variable with an un-initialized value, whereas NULL is a variable that contains no valid data.
The IsEmpty function returns a Boolean value that indicates whether a specified variable has been initialized or not. It returns true if the variable is uninitialized; otherwise, it returns False.
The Null value indicates that the Variant contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It's also not the same as a zero-length string (""), which is sometimes referred to as a null string.
Do you mean 'Null' or 'Nothing'?
In VBScript, Nothing means absence of value (or a null pointer). Null is used to represent NULL values from a database.
See this link for more info.
Also, see this example for how to detect if a registry key exists:
Const HKLM = &H80000002
Set oReg =GetObject("Winmgmts:root\default:StdRegProv")
sKeyPath = "Software\Microsoft\Windows\CurrentVersion"
If RegValueExists(HKLM, sKeyPath, sValue) Then
WScript.Echo "Value exists"
Else
WScript.Echo "Value does not exist"
End If
Function RegValueExists(sHive, sRegKey, sRegValue)
Dim aValueNames, aValueTypes
RegValueExists = False
If oReg.EnumValues(sHive, sKeyPath, aValueNames, aValueTypes) = 0 Then
If IsArray(aValueNames) Then
For i = 0 To UBound(aValueNames)
If LCase(aValueNames(i)) = LCase(sRegValue) Then
RegValueExists = True
End If
Next
End If
End If
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With