pedaleo
pedaleo

Reputation: 411

How do I read a registry value and check his value?

I need to read a value from the registry and then check if contains the name of an old server.

I did this vbs but I'm receiving the error "Object required: " in the IF statement.

Any clue on what I'm doing wrong ?

Thanks

Dim objShell,strDocuments

Set objShell = WScript.CreateObject("WScript.Shell")

strDocuments = objShell.RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\Personal")

If strDocuments.Contains("\\oldServer\homes") then

    WScript.Echo "Documents pointing to the old server"

End If

Upvotes: 1

Views: 131

Answers (1)

Kul-Tigin
Kul-Tigin

Reputation: 16950

In VBScript primitive types has not built-in methods like Contains. Instead use InStr function.

If InStr(strDocuments, "\\oldServer\homes") > 0 Then

or with case-insensitive comparison:

If InStr(1, strDocuments, "\\oldServer\homes", vbTextCompare) > 0 Then

Upvotes: 2

Related Questions