I'm trying to find a way to query the user for a new computer and workgroup name and then to set those values appropriately. I have a script that sets the value in the registry, but after rebooting the name hasn't actually changed.
I have looked at the netdom utility, but from all the documentation I've read it will only work when in a domain environment. I've run a few tests with the software and it does seem to need to be either adding a machine to a domain or removing it from one.
We clone all our PC using Ghost so needed a way to 'individualize' them. The following is a VBS script I cobbled together that uses WMI and netdom.exe to carry this out. It might not be the best example of programming but it works. Hope it's useful...
Notes:
1) Delete or comment out any lines or sections you don't need, e.g. the default printer lines in section 3 or the call to delete the desktop shortcut link in section 5.
2) The script - as is - is for a WORKGROUP environment, not DOMAIN. Change the last but 1 line in section 3 if you want DOMAIN environment.
Copy and paste the following into Notepad then save with .vbs extension.
'===============================================================================
' Script name : xp-clone-changer-v04.vbe
' Creation Date : 29-10-2003
' OS : Windows XP
' Amendments : See below
' Added auto-capitalization of Asset no. and Workgroup (26-01-2004)
' Added changes to Computername in printer section of registry (26-01-2004)
' Added check for installed memory (03-07-2004)
'
' PURPOSE
' This script carries out the following function(s):-
' 1) Changes the IP address, subnet mask and gateway.
' 2) Changes the Autologon to the 'Windows User' account.
' 3) Changes the Computername and Workgroup.
' 4) Removes the 'Windows User' account from the 'Administrators' group.
' 5) Deletes the desktop shortcut to 'Clone Changer'.
' 6) Shows amount of installed RAM.
' 7) Re-boots the PC so the changes are carried out.
'
'==============================================================================='
'**Start Encode**
Option Explicit 'Enforce strict naming
Dim WSH, FSO
Dim objComputer, objWMIService, objOperatingSystem, objNetAdapter
Dim strTitle, strVersion, strThisPC, strComputername, strCompNameRegPath, strWorkgroup
Dim strCCS, strTcpipParamsRegPath, strIPAddress, strSubnetMask, strGateway, strGatewayMetric
Dim colMEM, colNetAdapters, colOperatingSystems
Dim errEnable, errGateways
'Setup scripting environment
Set WSH = CreateObject ("WSCript.shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set Version info
strVersion = "v04"
'Set target PC for WMI
strThisPC = "."
'Set the Title for any dialogs
strTitle = "XP Clone Changer " & strVersion
'------------------------------------------------------------------------
'Section 1 - Use WMI to change IP address, subnet mask and gateway
WSH.Popup "Preparing to change IP address, subnet mask and gateway... Please wait.",2, strTitle 'Inform user
'Setup WMI
Set objWMIService = GetObject("winmgmts:\\" & strThisPC & "\root\cimv2")
'Set specific WMI query so 1394 adapter is excluded
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
'Get user input into an array
strIPAddress = Array(InputBox("Enter the new IP address"))
strSubnetMask = Array(InputBox("Enter the new Subnet mask"))
strGateway = Array(InputBox("Enter the new Gateway address"))
'Inform user
WSH.Popup "Please be patient whilst changes are made. This could take 10 seconds or more.",3, strTitle 'Inform user
strGatewayMetric = Array(1)
'Make the changes
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WSH.Popup "The IP address has been changed.",2,strTitle 'Inform user of success
Else
WSH.Popup "The IP address could not be changed automatically." & vbCrLf & vbCrLf &_
"This may be because the PC/Laptop is not connected to an active network." & vbCrLf & vbCrLf &_
"Please check the IP settings manually afterwards.",2,strTitle 'Inform user of failure
End If
Next
'------------------------------------------------------------------------
'Section 2 - Change the Autologon to 'Windows User' account
WSH.Popup "Preparing to change AutoLogon to Windows User account... Please wait.",2, strTitle
'Change details in the Registry
WSH.RegWrite "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName", "Windows User"
WSH.Popup "OK... Done!",2, strTitle 'Inform user
'------------------------------------------------------------------------
'Section 3 - Change Computername and Workgroup
WSH.Popup "Preparing to change Computername.",2, strTitle 'Inform user
'Get user input
strComputername = InputBox("Enter the asset no. to use as the Computername, e.g A051468")
strComputername = UCase(strComputername) 'Force capitalization
WSH.Popup "Please wait.",2, strTitle 'Inform user
'Delete current settings in registry and write new ones
With WSH
.RegDelete strTcpipParamsRegPath & "Hostname"
.RegDelete strTcpipParamsRegPath & "NV Hostname"
'Workgroup
WSH.Popup "Preparing to change Workgroup.",2, strTitle 'Inform user
'Get user input
strWorkgroup = InputBox("Enter the name to use as the Workgroup, e.g SS38COL")
strWorkgroup = UCase(strWorkgroup) 'Force capitalization
WSH.Popup "Please wait.",2, strTitle 'Inform user
'Use Win2k resource kit utility to make change
WSH.Run "NETDOM.EXE MEMBER \\" & strComputername & " /JOINWorkgroup " & strWorkgroup, 0, True
WSH.Popup "OK... Done!",2, strTitle 'Inform user
'------------------------------------------------------------------------
'Section 4 - Remove Windows User account from Administrators group
WSH.Popup "Preparing to remove Windows User account from Administrators group.",2, strTitle 'Inform user
'Use commandline to carry out removal forcibly in hidden mode
WSH.Run "cmd /c NET LOCALGROUP Administrators " & """Windows User""" & " /DELETE", 2, True
WSH.Popup "OK... Done!",2, strTitle 'Inform user
'------------------------------------------------------------------------
'Section 6 - Show amount of installed RAM
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strThisPC & "\root\cimv2")
Set colMEM = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer In colMEM
objComputer.TotalPhysicalMemory = Left((objComputer.TotalPhysicalMemory/1000000),3)
If objComputer.TotalPhysicalMemory < 512 Then
WSH.Popup "Installed memory:" & vbTab & (objComputer.TotalPhysicalMemory) & "Mb"_
& VbCrLf & VbCrLf & "Warning: This PC has less than 512 Mb of memory installed."_
& VbCrLf & "The swap size is set incorrectly and performance will suffer."_
& VbCrLf & VbCrLf & "Please install more memory ASAP." &_
VbCrLf & VbCrLf & "Click on the OK button.", 0, strTitle
Else
WSH.Popup "Installed memory:" & vbTab & (objComputer.TotalPhysicalMemory) & "Mb"_
& VbCrLf & VbCrLf & "Click on the OK button.", 0, strTitle
End If
Next
'------------------------------------------------------------------------
'Section 7 - Use WMI to re-boot PC
WSH.Popup "Re-booting the PC so changes take effect. Please wait...",2, strTitle 'Inform user
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & strThisPC & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Reboot()
Next
'------------------------------------------------------------------------
'Finish up
Set WSH = Nothing
Set FSO = Nothing
Set objWMIService = Nothing
Set colNetAdapters = Nothing
Set colMEM = Nothing
WScript.Quit 'Yay!
Both your last post and my reply have been removed by Tek-Tips forum management because I included an email address in my reply. I've received a very nice email to my 'real' email address explaining why.
This is the right of the Tek-Tips forum management and I fully agree with it. Tek-Tips is too valuable a resource to have it spoiled.
My revised answer is... the version of NETDOM.EXE you're looking for is on the Windows 2000 CD.
I really appreciate the info and agree with the policy as well. I will grab my 2k cd the next time I rotate back into my office. Thanks again for your help.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.