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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SMS query the registry

Status
Not open for further replies.

Computergeek30

IS-IT--Management
Jun 9, 2003
2
US
Is there a way to build a query in SMS to search the registry for a specific key or registry setting? I want SMS to query a certain collection and search the registry for a speicific value. Is this possible?
 
SMS does not have a built-in routine to read a give registry entry, but you could use a vbs or sms installer script to read the value and return it as a mif or write directly to a file share somewhere.

Below is some vbs to read registry entries and to write a mif. I didn't include any error handling.

-------- vbs to read various registry entries -----------

const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")


' === String value ===
strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"
strValueName = "TrustPolicy"

oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

wscript.echo "Current WSH Trust Policy Value: " & strValue

' === DWORD value ===
strKeyPath = "Console"
strValueName = "HistoryBufferSize"

oReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

wscript.echo "Current History Buffer Size: " & dwValue

' === Binary value ===
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "DigitalProductID"

oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

For i = lBound(strValue) to uBound(strValue)
' wscript.echo strValue(i)
Next


' === MultiString value ===
strKeyPath = "SYSTEM\CurrentControlSet\Services\Eventlog\System"
strValueName = "Sources"

oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,arrValues

For Each strValue In arrValues
' wscript.echo strValue
Next

' === Expanded string value ===
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strValueName = "UIHost"

oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

wscript.echo "The Windows logon UI host is: " & strValue


------------ vbs to write a mif ------------

Set objShell = WScript.CreateObject ("WScript.Shell")
Set objWSH = WScript.CreateObject ("WScript.Network")
Set objArgs = WScript.Arguments
Set objFSO = CreateObject ("Scripting.FileSystemObject")

GroupName = ("This is the group name")
ClassName = ("This is the class name")

Attribute1 = ("hello")
Attribute2 = ("world")

'A = Array(10,20,30)
'B = A(2) ' B is now 30.

' ======= Create MIF =======
Set MIFFile = objFSO.CreateTextFile ("c:\winnt\ms\sms\noidmifs\test.txt", True)

MIFFile.WriteLine ("Start Component")
MIFFile.WriteLine (" Name = ""Machine""")
MIFFile.WriteLine (" Start Group")
MIFFile.WriteLine (" Name = " & chr(34) & GroupName & chr(34) & "")
MIFFile.WriteLine (" ID = 1")
MIFFile.WriteLine (" Class = " & chr(34) & ClassName & chr(34) & "")

If Len(Attribute1) > 0 Then
MIFFile.WriteLine (" Start Attribute")
MIFFile.WriteLine (" Name = ""Attribute 1 Name""")
MIFFile.WriteLine (" ID = 1")
MIFFile.WriteLine (" Type = String 10")
MIFFile.WriteLine (" Storage = Specific")
MIFFile.WriteLine (" Value = " & chr(34) & Attribute1 & chr(34) & "")
MIFFile.WriteLine (" End Attribute")
End If

If Len(Attribute2) > 0 Then
MIFFile.WriteLine (" Start Attribute")
MIFFile.WriteLine (" Name = ""Attribute 2 Name""")
MIFFile.WriteLine (" ID = 2")
MIFFile.WriteLine (" Type = String 10")
MIFFile.WriteLine (" Storage = Specific")
MIFFile.WriteLine (" Value = " & chr(34) & Attribute2 & chr(34) & "")
MIFFile.WriteLine (" End Attribute")
End If

MIFFile.WriteLine (" End Group")
MIFFile.WriteLine ("End Component")
MIFFile.Close

Set objFSO = Nothing


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top