Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsWindows VistaWindows XPWindows MeWindows 98Windows 95Virtual PCInternet ExplorerOutlook ExpressWindows MediaSecurity
Related Topics
MS Server ProductsMS OfficePC HardwareMore Topics ...

Windows Forum / Windows XP / Setup and Deployment / October 2003

Tip: Looking for answers? Try searching our database.

Setting computername from file in scripting (WINXP)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Allan Fog - 31 Oct 2003 14:26 GMT
Hi
My problem is that i want to rename or set the
computername before 1.st boot after a ghost clone
according to a plain text file containing a line for each
computer on the network where  mac_adr + computername is
the key elements. i have the script below to join the
computer to the domain, but is it possible for me to set
the computername before joining the domain so that i dont
need to rename both the computer and the computer account
in the AD/domain. i would imagine something like set
objcomputer.computername = "####" where i replace
the "####" with the information from the textfile
containing computername & mac_adr.

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144

strDomain = "MyDomain"
strPassword = "somepwd"
strUser = "someuser"

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

Set objComputer = GetObject("winmgmts:
{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain,
_
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)

Set Ws = WScript.CreateObject("Wscript.Shell")

ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultDomainName","somedomain"

ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\DefaultUserName",""

ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultUserName",""

ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultDomainName","somedomai
n"

ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AltDefaultDomainName","somedomai
n"

ws.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon\AutoAdminLogon","0"

Sub ShutDown

nLogOff=0
nReboot=2
nForceLogOff=4
nForceReboot=6
nPowerDown=8
nForcePowerDown=12

Set oOS = GetObject("winmgmts:{(Shutdown)}").ExecQuery
("Select * from Win32_OperatingSystem")

For Each oOperatingSystem in oOS
   oOperatingSystem.Win32Shutdown(nForcePowerDown)
Next

End sub

ShutDown
Patrick J. LoPresti - 31 Oct 2003 14:48 GMT
objcomputer.Rename(...) should do the trick.  See
<http://msdn.microsoft.com/library/en-us/wmisdk/wmi/rename_method_in_class_win32_
computersystem.asp
>.

Note that a reboot is required after performing this operation, so you
will need to set up autologon and arrange to run your "join domain"
script afterwards.

- Pat
  <http://unattended.sourceforge.net/>

> Hi
> My problem is that i want to rename or set the
[quoted text clipped - 80 lines]
>
> ShutDown
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.