Computing.Net > Forums > Programming > VB Script Help

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB Script Help

Reply to Message Icon

Original Message
Name: jdcomputing
Date: November 14, 2006 at 02:51:28 Pacific
Subject: VB Script Help
OS: WinXP
CPU/Ram: 1GB
Model/Manufacturer: DELL
Comment:

Hi,
I have created a script which is supposed to change a PC name and then add it to a domain. The problem im having is the Script needs to be run twice! - Once for the PC rename, then it needs a restart, and then the script needs to be run again to join the domain, and then another restart.

Is there a way of getting the PC renamed and joined to the domain by running the script once and having only to reboot once?

Thanks in advance...

Here is the script:
'Rename a Computer:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputers
err = objComputer.Rename("computernameXP1")
Next

'Join a Computer to a Domain:

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 = "domain.com "
strPassword = "Password"
strUser = "username"

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)

WScript.Echo "DONE!"


Report Offensive Message For Removal


Response Number 1
Name: Lamezz
Date: November 14, 2006 at 05:32:10 Pacific
Reply: (edit)

I do not know anything about VB so forgive me but why don't you put changing the computers name after the domain?

I started at 15...


Report Offensive Follow Up For Removal

Response Number 2
Name: jdcomputing
Date: November 14, 2006 at 05:57:01 Pacific
Reply: (edit)

Hi Lamezz,

If I change the computer name after I have added the computer to the domain, Active Directory will not see the correct name for the PC. I would have to create a script to change name in AD as well.
Also, renaming a PC while joined to a domain requires a few extra steps which basically complicates things.



Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software