Page 1 of 1 1
Topic Options
#121163 - 2004-06-11 11:06 PM remote registry changes
Udaloy Offline
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
#121164 - 2004-06-11 11:11 PM Re: remote registry changes
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
You don't need remote Execute to update the registry remotely.

If you have permissions then you just need the remote path.

There are tons of examples on the board.

Top
#121165 - 2004-06-11 11:32 PM Re: remote registry changes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
If you are setting everything else to DHCP, why not set option 015 in the DHCP to serve out the DNS Domain Name? We have done it for thousands of computers in our AD migration.

Anyway, if you insist on hacking into the reg...

$rc = WriteValue('\\'+$pc+'\HKLM...
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#121166 - 2004-06-12 12:20 AM Re: remote registry changes
Udaloy Offline
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
#121167 - 2004-06-12 12:40 AM Re: remote registry changes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Option 015 should be defined on all your DHCP servers. Should is the operative word, whether or not it is, only your DHCP Admin can say for sure. The bad news is that if you have something hard-coded on the computers, the DHCP option will not override it. You need to blank out the hard-coded setting. You may ask why not then just hard-code the new setting. Not a good idea if it were ever to change again. Better to rely on option 015.

Is there not a way with NetSH to blank out the settings?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#121168 - 2004-06-12 01:23 AM Re: remote registry changes
Udaloy Offline
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
#121169 - 2004-06-12 01:53 AM Re: remote registry changes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't think you need RemoteExec() at all. Reading the manual, it would appear NetSH can be used against remote machines directly. Borrowing from the NetSH manual:
Quote:

· -r RemoteMachine
Specifies that the netsh commands are run on a remote computer specified by either its name or IP address.





You can dump your local config with the command:
NetSH Dump

It will give you a big long script that you should be able to glean info from.

i.e.
# ----------------------------------
# Interface IP Configuration
# ----------------------------------
pushd interface ip


# Interface IP Configuration for "Local Area Connection"

set address name="Local Area Connection" source=dhcp
set dns name="Local Area Connection" source=dhcp register=PRIMARY
set wins name="Local Area Connection" source=dhcp


popd
# End of interface IP configuration
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#121170 - 2004-06-12 02:15 AM Re: remote registry changes
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Kids... don't try this at home.

http://support.microsoft.com/default.aspx?scid=kb;en-us;317518
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#121171 - 2004-06-12 05:00 AM Re: remote registry changes
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Oops, I already did. Used it to revive a network-dead Windows XP computer and experimented with NETSH as part of a standard image roll-out.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.067 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org