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

Editing Remote Registry

Status
Not open for further replies.

minglespasm

IS-IT--Management
Aug 1, 2003
4
GB
Hello,

I've been modifying an old well & used script i use to perform domain wide admin tasks.

I am trying to remotely edit each registry in the domain to point MS Office applications to a new template location.

The script only works locally, and doesn't loop through each computer in the domain as it should.

The code is pasted below, any pointers greatly appreciated.

Const HKEY_CURRENT_USER = &H80000001
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim objDomain, objRegistry, strComputerName, ver
Dim strKeyPath, strValueName, strValue
Dim FileSysObj

on error resume next
ver = 11
Set objDomain = GetObject("WinNT://MPC-NOTES")
Set FileSysObj = CreateObject("Scripting.FileSystemObject")

'setup logs
Set FailureLog = FileSysObj.OpenTextFile("C:\TEMP\Failure.log", ForAppending, True)
Set SuccessLog = FileSysObj.OpenTextFile("C:\TEMP\Success.log", ForAppending, True)

'start loop
For Each Object In objDomain

'filter for computers
If Object.class = "Computer" Then
strComputerName = Object.name

'set reference to remote registry
Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputerName & "\root\default:StdRegProv")
ver = 11
'check for office installation
Do While ver > 8
strKeypath = "Software\Microsoft\Office\" & ver & ".0\Common\General"
strValueName = "UserTemplates"
objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
If IsNull(strValue) Then
ver = ver - 1
If ver = 8 Then
'log failure event
FailureLog.WriteLine("FAILURE! Workstation " & WorkStation & " was not modified; No Office instalation could be found")
End If
Else
'set variable
strValue = "\\nautilus\Templates"
'update registry'
objRegistry.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
'log success event'
SuccessLog.WriteLine("The Registry of " & strComputerName & " was modified successfully; Office Version " & ver & ".0 is installed")
Exit Do

End If
Loop

End If

Next

'close logs
FailureLog.Close
SuccessLog.Close

'notify of script completion
Wscript.echo "Completely Done!"

Wscript.Quit Err.Number
 
[1] Make sure MPC-NOTES is the nt domain's name.
[2] Use the .filter to filter the computer rather than the objectclass="Computer", though the latter is fundamentally sound as well.
[tt]
'start loop
[blue]objDomain.filter=array("computer")[/blue]
For Each Object In objDomain

'filter for computers
'[blue]cross the corresponding end if as well[/blue]
'If Object.class = "Computer" Then
strComputerName = Object.name
[/tt]
[3] Control the return value of getstringvalue or setstringvalue. It is the return value which indicates success (iret=0) or not.
[4] If you ask a single measure to debug why the script fails to iterate, I would say take out the "on error resume next" and start from there.

- tsuji
 
i managed to get it to work, kind of.

I changed the code as suggested, and sorted out a few of the variables that were causing a few problems.

The logs show around 30 successful modifications, and no failures - so maybe i need to revisit the logic as i'd expect more results than that (the domain has around 200 workstations in it).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top