Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vbscript and checking for null

Tags:

vbscript

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
like image 211
Steve Wood Avatar asked Aug 23 '10 15:08

Steve Wood


People also ask

IS NULL function in VBScript?

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.

Is null or empty VBScript?

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.

Is empty in VBScript?

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.

Is Null Visual Basic?

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.


1 Answers

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
like image 186
Kilanash Avatar answered Sep 30 '22 05:09

Kilanash