Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Registry Changes using a script

Posted on 2004-09-27
14
Medium Priority
?
1,263 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Accepted Solution

by:
sramesh2k earned 1200 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

cPanel is a Unix based web hosting control panel that provides a graphical interface and automation tools designed to simplify the process of hosting a web site. cPanel utilizes a 3 tier structure that provides functionality for administrators, rese…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

610 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