#121163 - 2004-06-11 11:06 PM
remote registry changes
|
Udaloy
Fresh Scripter
Registered: 2003-09-08
Posts: 31
Loc: Ohio
|
We are about to upgrade to windows 2003 server for the domain, and I am tasked with making changes to all the machines in the domain regarding fully qualified domain name. I have the following code to attemp to change registry settings
Code:
IF Open(1,<machinename>\c$\test.txt",2) = 0 $pc = ReadLine(1) WHILE $pc <> 'eof' ;$x=RemoteExec('\\$pc\admin$\system32\nbtstat -R', $pc) ;this section will set WINS address to DHCP ;$x=RemoteExec('\\$pc\admin$\system32\netsh int ip set wins "Local Area Connection" dhcp', $pc) ;?'result of set wins: '+$x+@ERROR+@SERROR ;this section will set DNS source to DHCP ;$x=RemoteExec('\\$pc\admin$\system32\netsh int ip set dns "Local Area Connection" dhcp', $pc) ;?'result of set dns: '+$x+@ERROR+@SERROR ;this section will set primary DNS suffix $x=RemoteExec(updateregistry('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'Domain', 'ad.<domain>.com'), $pc) $x=RemoteExec(updateregistry('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters', 'NV Domain', 'ad.<domain>.com'), $pc) Shutdown($pc,"This computer is being rebooted for maintenance purposes",30,,1) $pc = ReadLine(1) LOOP Close(1) ENDIF
EXIT
FUNCTION RemoteExec($command, OPTIONAL $computer) ;Function RemoteExec($command, optional $computer) DIM $connect, $process IF NOT $computer $computer='.' ENDIF IF InStr($computer,'\') $computer=SubStr($computer,InStrRev($computer,'\')+1) ENDIF $connect = GetObject('winmgmts:{impersonationLevel=impersonate}!//'+$computer+'/root/cimv2:Win32_Process') $process = $connect.create($command) EXIT @error ENDFUNCTION FUNCTION updateregistry($regsubkey, $regentry, $regvalue, OPTIONAL $regtype) DIM $currentregvalue, $currentregtype, $rc
$updateregistry=0
IF $regtype='' $regtype='REG_SZ' ENDIF
$currentregtype=ReadType($regsubkey,$regentry) $currentregvalue=ReadValue($regsubkey, $regentry) IF $currentregvalue<>$regvalue OR $currentregtype<>$regtype $rc=WriteValue($regsubkey,$regentry,$regvalue,$regtype) IF @error EXIT @error ENDIF $updateregistry=1 ENDIF EXIT @error ENDFUNCTION
I've removed some code that isn't germane to keep it a little shorter. Of course, if there's a line commented out, it was for testing purposes, and isn't commented out while running the script. Obviously, the problem is with using two functions in the same line ($x=RemoteExec(updateregistry)). By the way, I have documented the actual authors in my code, Lonkero and Sealeopard if memory serves.
I was able to update my own registry entry, but not any remote registries. I have Administrator privileges on the domain. Now what can I look to? Thanks.
Udaloy
|
|
Top
|
|
|
|
#121166 - 2004-06-12 12:20 AM
Re: remote registry changes
|
Udaloy
Fresh Scripter
Registered: 2003-09-08
Posts: 31
Loc: Ohio
|
Les,
We do want everything to become DHCP, but I am finding out that the machines have DNS servers manually entered. Is it possible to force machines to get DNS automatically? Can you elaborate on setting 015 for a non-coding person? Thanks.
|
|
Top
|
|
|
|
#121168 - 2004-06-12 01:23 AM
Re: remote registry changes
|
Udaloy
Fresh Scripter
Registered: 2003-09-08
Posts: 31
Loc: Ohio
|
Yes, but I'm not having a good go of it. Here's what's in the script: Code:
$x=RemoteExec('\\$pc\admin$\system32\netsh int ip set wins "Local Area Connection" dhcp', $pc) $x=RemoteExec('\\$pc\admin$\system32\netsh int ip set dns "Local Area Connection" dhcp', $pc)
The RemoteExec function code is above in my first posting. I think perhaps I better try adding "name=" in front of Local Area Connection, and adding "source=" in front of dhcp. What do you think?
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|