Solved

Registry Changes using a script

Posted on 2004-09-27
14
1,205 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Process prvSGxBA.exe 100 % CPU, is this a virus? 7 75
If XP support has stopped, why am I still getting updates? 3 326
How to install Windows XP Driver 28 171
active directory 5 65
We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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