Advise please Guys with a query on a dword value
| |
Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 7:03 AM :: Rank: 125 |
Author
|
|
|
Points: 40744
Level: System Center Expert |
Thank you for your rating!
|
I have written some code which is not giving me the answer I am looking for and was hoping for one of you to tell me where I'm going wrong. I want to get a dword value but I will be unsure of the name of the key (as this could be random) what I do need to find is that when a 'ValidCommunity' is created that the dward setting is set to 4.
Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim strComputer
Dim objRegistry
Dim strKeyPath
Dim strValueName
Dim dwValue
strComputer = "."
'Set objRegistry=GetObject("winmgmts:\\" & _
' strComputer & "\root\default:StdRegProv")
Set objRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities"
strValueName = "."
dwValue = "reg_dword"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue
Wscript.Echo "" & dwValue
'Wscript.Echo "This registry key exist with the", strValueName & " = " & dwValue
Thoughts....
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
Re: Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 9:29 AM :: Rank: 135 |
Author
|
|
|
Points: 28999
Level: System Center Expert |
Thank you for your rating!
|
Hi Simon,
I think I cannot follow. Can you post a screenshot of this reg key where some communities are shown. Do you then want to iterate through all values and verify that each one has a "4" in it?
cheers,
Stefan
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
Re: Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 9:34 AM :: Rank: 120 |
Author
|
|
|
Points: 40744
Level: System Center Expert |
Thank you for your rating!
|
Hi Stefan and thanks for your input in the SCC forum; To get a reg key to display is an easy thing to get this one seems not to be the case so I used this code to display ALL inside the SNMP hive, hey guess what is stop before getting to the one I want!
' Constants (taken from WinReg.h)
'
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
' Chose computer name, registry tree and key path
'
strComputer = "." ' Use . for current machine
hDefKey = HKEY_LOCAL_MACHINE
strKeyPath = "System\CurrentControlSet\Services\SNMP"
' Connect to registry provider on target machine with current user
'
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
' Enum the subkeys of the key path we've chosen
'
oReg.EnumKey hDefKey, strKeyPath, arrSubKeys
For Each strSubkey In arrSubKeys
' Show the subkey
'
wscript.echo strSubkey
' Show its value names and types
'
strSubKeyPath = strKeyPath & "\" & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes
For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)
' Show a REG_SZ value
'
Case REG_SZ
oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_SZ) = " & strValue
' Show a REG_EXPAND_SZ value
'
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_EXPAND_SZ) = " & strValue
' Show a REG_BINARY value
'
Case REG_BINARY
oReg.GetBinaryValue hDefKey, strSubKeyPath, strValueName, arrBytes
strBytes = ""
For Each uByte in arrBytes
strBytes = strBytes & Hex(uByte) & " "
Next
wscript.echo " " & strValueName & " (REG_BINARY) = " & strBytes
' Show a REG_DWORD value
'
Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
wscript.echo " " & strValueName & " (REG_DWORD) = " & CStr(uValue)
' Show a REG_MULTI_SZ value
'
Case REG_MULTI_SZ
oReg.GetMultiStringValue hDefKey, strSubKeyPath, strValueName, arrValues
wscript.echo " " & strValueName & " (REG_MULTI_SZ) ="
For Each strValue in arrValues
wscript.echo " " & strValue
Next
End Select
Next
Next
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
Re: Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 9:35 AM :: Rank: 124 |
Author
|
|
|
Points: 40744
Level: System Center Expert |
Thank you for your rating!
|
HERE is the Key,
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities]
"Public"=dword:00000004
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
Re: Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 10:54 AM :: Rank: 110 |
Author
|
|
|
Points: 40744
Level: System Center Expert |
Thank you for your rating!
|
This is the correct code.
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
' Chose computer name, registry tree and key path
strComputer = "." ' Use . for current machine
hDefKey = HKEY_LOCAL_MACHINE
strKeyPath = "System\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities"
' Connect to registry provider on target machine with current user
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strSubKeyPath = strKeyPath & "\" & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes
For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)
' Show a REG_SZ value
Case REG_SZ
oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_SZ) = " & strValue
' Show a REG_EXPAND_SZ value
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_EXPAND_SZ) = " & strValue
' Show a REG_BINARY value
Case REG_BINARY
oReg.GetBinaryValue hDefKey, strSubKeyPath, strValueName, arrBytes
strBytes = ""
For Each uByte in arrBytes
strBytes = strBytes & Hex(uByte) & " "
Next
wscript.echo " " & strValueName & " (REG_BINARY) = " & strBytes
' Show a REG_DWORD value
'
Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
wscript.echo " " & strValueName & " (REG_DWORD) = " & CStr(uValue)
' Show a REG_MULTI_SZ value
'
Case REG_MULTI_SZ
oReg.GetMultiStringValue hDefKey, strSubKeyPath, strValueName, arrValues
wscript.echo " " & strValueName & " (REG_MULTI_SZ) ="
For Each strValue in arrValues
wscript.echo " " & strValue
Next
End Select
If uValue=int(4) Then
WScript.echo "True"
Else
WScript.Echo "False"
WScript.quit
End If
Next
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
RE: Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 11:12 AM :: Rank: 115 |
Author
|
|
|
Points: 65502
Level: System Center Expert |
Thank you for your rating!
|
here is a commented and beautified version of the correct script. Basically, it simply checks all SNMP community strings to determine if any communities are NOT READ ONLY.
I have also attached a downloadable version to this post. This would be just right for use in a DCM baseline in ConfigMgr 2007. If you download, rename with a .vbs extension.
'Declare Registry Constants
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_MULTI_SZ = 7
'Chose computer name, registry tree and key path
strComputer = "." ' Use . for current machine
'This is the HIVE we're working in
hDefKey = HKEY_LOCAL_MACHINE
'This is the key we will target. Next, we will enumerates values of this key
strKeyPath = "System\CurrentControlSet\Services\SNMP\Parameters\ValidCommunities"
' Connect to registry provider on target machine with current user
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
'Next, we will loop through the values in this key looking for any CASE where the
'SNMP community string does not have an access value of 4 (read only)
strSubKeyPath = strKeyPath & "\" & strSubkey
oReg.EnumValues hDefKey, strSubKeyPath, arrValueNames, arrTypes
For i = LBound(arrValueNames) To UBound(arrValueNames)
strValueName = arrValueNames(i)
Select Case arrTypes(i)
' Show a REG_SZ value
Case REG_SZ
oReg.GetStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_SZ) = " & strValue
' Show a REG_EXPAND_SZ value
Case REG_EXPAND_SZ
oReg.GetExpandedStringValue hDefKey, strSubKeyPath, strValueName, strValue
wscript.echo " " & strValueName & " (REG_EXPAND_SZ) = " & strValue
' Show a REG_BINARY value
Case REG_BINARY
oReg.GetBinaryValue hDefKey, strSubKeyPath, strValueName, arrBytes
strBytes = ""
For Each uByte in arrBytes
strBytes = strBytes & Hex(uByte) & " "
Next
wscript.echo " " & strValueName & " (REG_BINARY) = " & strBytes
' Show a REG_DWORD value
Case REG_DWORD
oReg.GetDWORDValue hDefKey, strSubKeyPath, strValueName, uValue
wscript.echo " " & strValueName & " (REG_DWORD) = " & CStr(uValue)
' Show a REG_MULTI_SZ value
Case REG_MULTI_SZ
oReg.GetMultiStringValue hDefKey, strSubKeyPath, strValueName, arrValues
wscript.echo " " & strValueName & " (REG_MULTI_SZ) ="
For Each strValue in arrValues
wscript.echo " " & strValue
Next
End Select
'Display the SNMP community strings
'If value is not 4(read only) return FALSE and Exit
If uValue=int(4) Then
WScript.echo "True"
Else
WScript.Echo "False"
WScript.quit
End If
Next
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
Re: Advise please Guys with a query on a dword value
Posted: Sat, Oct 31, 2009 11:31 AM :: Rank: 136 |
Author
|
|
|
Points: 40744
Level: System Center Expert |
Thank you for your rating!
|
What would also be worth knowing is how you just did that! As format the code with such grace.
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
Re: Advise please Guys with a query on a dword value
Posted: Tue, May 11, 2010 10:17 PM :: Rank: 124 |
Author
|
|
|
Points: 30
Level: System Center Enthusiast |
Thank you for your rating!
|
How to Plan a Halloween Golf Tournament
Step 1 Anyone working the tournament but not playing in it should dress up. Halloween costumes are sometimes not the most comfortable [url=http://www.appservnetwork.com/forum/index.php?topic=4729.0]golfwholesale18 reviews[/url][/b] outfits to play golf in, so refrain from requiring players to dress up while on the course. Make sure all of the paperwork for the tournament, from the sign-up sheet to the rules sheet, includes Halloween theme. Ask the golf course management to get involved by allowing you to decorate the starter's booth with some basic Halloween decorations. When you advertise, [url=http://www.goarticles.com/cgi-bin/showa.cgi?C=2851102]golfwholesale18.com[/url] be sure to include the Halloween theme and to mention that a costume party will follow the tournament. Get local businesses involved by having them donate prizes for the players in exchange for prominent advertising spots at at the after-play party. Step 2 During the actual playing there is very little that can be done for a Halloween theme. ishiner You cannot have people coming out of the woods to startle people, or loud noises being piped in through speakers placed in the woods because [url=http://www.golfsetbase.com/blog/the-compare-between-golfwholesale18-and-golfsetbase/]golfwholesale18[/url] it will result in complaints from the golfers; however, you can decorate the course to some extent by placing small hanging decorations on each flag stick. Plastic spiders, plastic skeletons and other hanging decorations would be appropriate here. Step 3 When playing is over, [url=http://www.goarticles.com/cgi-bin/showa.cgi?C=2851091]www.golfwholesale18.com[/url] you can begin the Halloween-themed party in the clubhouse. Encourage golfers to put on costumes before they enter the clubhouse to claim their prizes. Designate some of the tournament workers as costume judges and set aside three top prizes for the costume contest.
|
|
| Your Reports Help Protect the Community |
|
The community depends on each member to help keep Answers a safe and positive place. Do your part by using the form below to report Q&A that violates the Community Guidelines.
|
Additional Detail(optional)
|
Report Abuse |
|
|
|
|
|
|
Quick Links
System Center Web sites
3rd Party / Partner Resources
Other System Center Resources
|
|
|
|
|
Top Contributors
|
|
Points: 65502
Level: System Center Expert
|
|
|
Points: 42718
Level: System Center Expert
|
|
|
Points: 40744
Level: System Center Expert
|
|
|
Points: 28999
Level: System Center Expert
|
|
|
Points: 27584
Level: System Center Expert
|
|
|
|
|
|
|
|
|