Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple question I guess..

Status
Not open for further replies.

g37s

IS-IT--Management
Dec 18, 2008
6
US
I have this code below that will write a registry value to a file. I want the next line in the code to say if the registry value = 1 then write [PASSED!] if anything else write [FAILED!].


Set WshShell = WScript.CreateObject("WScript.Shell")
outfile.writeline "Append parent suffix of the primary DNS suffix setting... " & WshShell.RegRead("HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\UseDomainNameDevolution")
 
You need to use On Error Resume Next so you can trap the error code.

Code:
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Result = WshShell.RegRead("HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\UseDomainNameDevolution")
If Err.Number = 0 Then
	outfile.writeline "Append parent suffix of the primary DNS suffix setting... " & Result
	outfile.writeline "[Passed]"
Else
	outfile.writeline "[Failed]"
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
if the registry value = 1 then write [PASSED!]
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
regvalue = WshShell.RegRead("HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\UseDomainNameDevolution")
outfile.WriteLine "Append parent suffix of the primary DNS suffix setting... " & regvalue
If regvalue = 1 Then
  outfile.WriteLine "[PASSED!]"
Else
  outfile.WriteLine "[FAILED!]"
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, if the reg value were missing then your code will fail. But looking back at my code it only takes that into account and doesn't verify the actual value.

A combination of our code seems to be in order.

Code:
On Error Resume Next
Set WshShell = WScript.CreateObject("WScript.Shell")
Result = WshShell.RegRead("HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\UseDomainNameDevolution")
If Err.Number = 0 Then
    If regvalue = 1 Then
       outfile.WriteLine "[PASSED!]"
    Else
       outfile.WriteLine "[FAILED!]"
    End If
Else
    outfile.writeline "[Failed]"
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top