minglespasm
IS-IT--Management
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
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