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