Solved

Registry Changes using a script

Posted on 2004-09-27
14
1,169 Views
Last Modified: 2008-01-09
Further to my earlier question regarding DNS registry settings I now have an issue.

I need to use a script to look up the following registry key

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Interfaces

Then for each interface that appears in the key it needs to update the following two values

Domain = "mydomain.org"
RegisterAdapterName = 1

I need this to work under a certain username and password as I am going to run the script through the login script.

Can anyone provide a script that will do this

0
Comment
Question by:JordansGhost
  • 3
  • 3
  • 3
  • +3
14 Comments
 
LVL 40

Expert Comment

by:Fatal_Exception
ID: 12159857
This is pretty simple.  You can distribute registry changes by using a .reg file, and package/distribute them using Group Policy and your login scripts.

Here is an article explaining .reg files:

http://support.microsoft.com/default.aspx?kbid=310516

and how to distribute them:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnw2kmag01/html/DistributingRegistryChanges.asp

0
 

Author Comment

by:JordansGhost
ID: 12160249
I know I can add a key. The problem I have is that I need to retreive the adapter GUID's to update the keys for each seperate PC so a script needs to do it. I cannot just stamp the same reg key across all machines.
0
 
LVL 2

Expert Comment

by:dev8
ID: 12160330
Your .reg would look like this:
_________________________________________________________________________________
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Interfaces\INTERFACE_NAME]
"Domain"="mydomain.org"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Interfaces\INTERFACE_NAME]
"RegisterAdapterName"="1"
_________________________________________________________________________________

INTERFACE_NAME would be whatever your registry specifies as the name for that adapter.  This would of course be done in notepad then saved with the .reg extension.  All this is explained in more detail in the links Fatal_Exception provided as far as how to distribute to your group policy.

//j

0
 
LVL 34

Accepted Solution

by:
sramesh2k earned 400 total points
ID: 12160441
Hi,

To determine the GUID, WMI functions have to be used ("Win32_NetworkAdapterConfiguration")

Win32_NetworkAdapterConfiguration:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapterconfiguration.asp

For more information on the enumeration of the GUID, you can try this (or point to this thread) at the Scripting topic area.
0
 
LVL 34

Expert Comment

by:sramesh2k
ID: 12160471
Sample script

Setting Network Parameters Using WMI (Part 1):
http://www.serverwatch.com/tutorials/article.php/1548421
0
 
LVL 3

Expert Comment

by:zamoti
ID: 12160764
All you need is a copy of your .reg file and a simple command line:

regedit /s \\myshare\regkey.reg

No user intervention required.

If you want to have regedit generate the .reg file for you, click on the key you want to distribute, and choose "File" and "'Export".  This way there are no worries about typos or any such errors.

Cheers
0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 40

Expert Comment

by:Fatal_Exception
ID: 12404949
Seems to me that Ramesh answered this correctly, including links to the proper script...  Just my opinion of the comments..  :)
0
 

Author Comment

by:JordansGhost
ID: 12409337
This question is not abandoned, I have not yet had the time due to a DR test to attempt the resolutions offered
0
 
LVL 34

Expert Comment

by:sramesh2k
ID: 12410060
>> including links to the proper script

Thanks William! Let's see how it goes.
0
 
LVL 40

Expert Comment

by:Fatal_Exception
ID: 12410200
Sure, I would like to see how this turns out too..  :)
0
 
LVL 1

Assisted Solution

by:rsealock
rsealock earned 100 total points
ID: 12460217
Here is a simple script that should show how to do this.

The resources I used to find the answer are as the following:
http://www.microsoft.com/technet/scriptcenter/tools/wmimatic.mspx for the Scriptomatic tool, and
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_networkadapterconfiguration.asp

'Sample WMI script to read NetworkAdapterConfiguration, and then
'set one of the properties.
'Note: The WMI ExecQuery use a filter of "Where IPEnabled=True" to isolate valid adapters.
'For a complete list of all NetworkAdapterConfiguration properties, download Scriptomatic.exe and
'select the default Win32_NetworkAdapterConfiguration script.
'
'To correlate the proper Win32_NetworkAdapterConfiguration Class to use to Set the property, you may
'need to do a bit of homework.

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=True",,48)
For Each objItem in colItems
    If objItem.DomainDNSRegistrationEnabled = False Then
      iReturn = objItem.SetDynamicDNSRegistration(True,True)
      If Not iReturn = 0 Then
        'Failed for some reason.  See "SetDynamicDNSRegistration Method of the Win32_NetworkAdapterConfiguration Class" for error codes
      End if
    End If
Next

0
 

Author Comment

by:JordansGhost
ID: 12556402
OK, i've managed to put together a script using the the info above so this is just about answered. A small issue.

it works fine on my machine but although it seems to run without error on a users machine it doesnt seem to make the required changes.

Do i need to specify credentials to ensure the user has rights to make the changes. Here is the script

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select SettingID from Win32_NetworkAdapterConfiguration WHERE IPEnabled=True",,48)
For Each objItem in colItems

   strnetsettingid = objItem.SettingID

Set objRegistry = _
    GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & strnetsettingid
strValueName1 = "Domain"
strValueName2 = "RegistrationEnabled"
strValueName3 = "RegisterAdapterName"

strValueEntry1 = "my.org"
strValueEntry2 = "1"
strValueEntry3 = "1"

objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath,_
    strValueName1, strValueEntry1
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath,_
    strValueName2, strValueEntry2
objRegistry.SetDWORDValue HKEY_LOCAL_MACHINE, strKeyPath,_
    strValueName3, strValueEntry3

Next

Set objShell = CreateObject("WScript.Shell")
objShell.Run "%COMSPEC% ipconfig /release",0,True
objShell.Run "%COMSPEC% ipconfig /renew",0,True
objShell.Run "%COMSPEC% ipconfig /flushdns",0,True
objShell.Run "%COMSPEC% ipconfig /registerdns",0,True
Set objShell = Nothing
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

There are 2 things you must have in order to connect to the internet behind a router, The "Gateway IP" of the router, which is usually something like 192.168.xxx.1, I've seen routers with default values of: 192.168.0.1, 192.168.1.1, 192.168.11.1, …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now