Solved

Registry Changes using a script

Posted on 2004-09-27
14
1,181 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
window s 8 to 10 err 9 115
Remote Exchange powershell-ing 25 104
symbolic link problem 6 85
Windows print sharing 1 63
Most of the time we are in fix when all of sudden our systems behave weirdly.  Such problems cost time and effort... so it's best to take some preventive actions so that we can avoid such issues or overcome such problems more easily. Preventive M…
Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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