Solved

Registry Changes using a script

Posted on 2004-09-27
14
1,217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ok I have been working on this for some time having learned and gained certification in XenDesktop 4 along came version 5 which was released last month. Since then I have been working to deploy XenDesktop 5 in a small environment with only 2 virt…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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