+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
Scripts Thread, script to rename computer and join it to domain ... in Coding and Web Development; seems to work fine for me ,Sorry cant help as i didnt write this script ....
  1. #16

    Join Date
    Dec 2009
    Posts
    603
    Thank Post
    8
    Thanked 36 Times in 34 Posts
    Rep Power
    17
    seems to work fine for me ,Sorry cant help as i didnt write this script .

  2. #17

    Join Date
    Mar 2010
    Location
    Australia
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Quote Originally Posted by box_l View Post
    something like

    Code:
    Dim computername
    computername=InputBox("Enter your computername:")
    
    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(computername)
    Next
    What needs to be changed to get it to work on windows 7? I did test it and it works fine on xp.
    Cheers,
    Nick

  3. #18
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    424
    Thank Post
    67
    Thanked 89 Times in 74 Posts
    Rep Power
    61
    It runs fine in windows 7, well, if you discount the fact that you have to run it with elevated privileges !

    disable UAC and all is well. (I do not recommend this)
    run from an administrator cmd and all is well.

    If you run actually logged as the local administrator (disabled by default), it also does the job.

    I found a bit of code to loop the script back into itself with a UAC popup

    Code:
    If WScript.Arguments.length =0 Then
      Set objShell = CreateObject("Shell.Application")
      'Pass a bogus argument with leading blank space, say [ uac]
      objShell.ShellExecute "wscript.exe", Chr(34) & _
      WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    Else
    
    Name = InputBox("Enter your computername:")
    
    Set objWMIService = GetObject("Winmgmts:root\cimv2")
    
    ' Call always gets only one Win32_ComputerSystem object.
    For Each objComputer in _
        objWMIService.InstancesOf("Win32_ComputerSystem")
    
            Return = objComputer.rename(Name)
            If Return <> 0 Then
               WScript.Echo "Rename failed. Error = " & Err.Number
            Else
               WScript.Echo "Rename succeeded." & _
                   " Reboot for new name to go into effect"
            End If
    
    Next
    
     
    End If
    This works for me.

    OOOps!

    that was different code to the original

    this is the version i should have posted..

    Code:
    If WScript.Arguments.length =0 Then
      Set objShell = CreateObject("Shell.Application")
      'Pass a bogus argument with leading blank space, say [ uac]
      objShell.ShellExecute "wscript.exe", Chr(34) & _
      WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    Else
    
    Dim computername
    computername=InputBox("Enter your computername:")
    
    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(computername)
    Next
    
    End if
    Both work tho'.

    Just different implementations of the same thing.


    BoX
    Last edited by box_l; 27th March 2010 at 08:34 PM.

  4. #19

    Join Date
    Feb 2009
    Location
    Chesterfield
    Posts
    13
    Thank Post
    1
    Thanked 1 Time in 1 Post
    Rep Power
    0
    sorry to resurect an old thread, but I could really use this script. When renaming the domain, I get a return value of 87 and it fails. Any ideas??

    Many thanks

  5. #20

    Join Date
    Mar 2010
    Location
    Australia
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi,
    Thanks for that, the rename script works fine.
    I cant get the join domain script to work though, on windows 7 and server 2008R2
    Any ideas?
    Cheers

  6. #21
    box_l's Avatar
    Join Date
    May 2007
    Location
    Herefordshire
    Posts
    424
    Thank Post
    67
    Thanked 89 Times in 74 Posts
    Rep Power
    61
    Code:
    If WScript.Arguments.length =0 Then
      Set objShell = CreateObject("Shell.Application")
      'Pass a bogus argument with leading blank space, say [ uac]
      objShell.ShellExecute "wscript.exe", Chr(34) & _
      WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    Else
    
    
    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
    Const strOU = "ou=oucomputers, ou=test, dc=boxtech, dc=Co, dc=uk"
    strDomain   = "domain"
    strPassword = "password"
    strUser     = "Administrator"
    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, _
        strOU, _
        JOIN_DOMAIN + ACCT_CREATE ,True)
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
            strComputer & "\root\cimv2")
    
    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")
    
    For Each objOperatingSystem in colOperatingSystems
        objOperatingSystem.Reboot()
    Next
    end if
    tested on my xen setup: 2008r2 and windows 7
    Last edited by box_l; 2nd April 2010 at 09:26 PM.

  7. #22

    Join Date
    Mar 2010
    Location
    Australia
    Posts
    3
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hi,
    I still can not get it working.
    Attached below is the code i was using, was there anything i missed?
    Regards,
    Nick
    Code:
    If WScript.Arguments.length =0 Then
      Set objShell = CreateObject("Shell.Application")
      'Pass a bogus argument with leading blank space, say [ uac]
      objShell.ShellExecute "wscript.exe", Chr(34) & _
      WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    Else
    
    
    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
    Const strOU = "ou=computers, dc=ogps, dc=wan"
    strDomain   = "ogps"
    strPassword = "password"
    strUser     = "administrator"
    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, _
        strOU, _
        JOIN_DOMAIN + ACCT_CREATE ,True)
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
            strComputer & "\root\cimv2")
    
    Set colOperatingSystems = objWMIService.ExecQuery _
        ("Select * from Win32_OperatingSystem")
    
    For Each objOperatingSystem in colOperatingSystems
        objOperatingSystem.Reboot()
    Next
    end if

  8. #23

    Join Date
    May 2013
    Location
    France Lille
    Posts
    1
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Smile

    Hello

    Do you have posted somewhere the vbs in order to rename and add a computer in AD ?

    Thanks in advance !!

SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. [Fog] Rename w/ serial # and join domain
    By Onslow in forum O/S Deployment
    Replies: 15
    Last Post: 20th July 2010, 09:42 AM
  2. Rename My Computer Via Registry
    By FN-GM in forum Windows 7
    Replies: 10
    Last Post: 14th September 2009, 08:43 PM
  3. No Domain Join during Setup
    By Nick_Parker in forum Windows 7
    Replies: 19
    Last Post: 24th August 2009, 01:13 PM
  4. Replies: 4
    Last Post: 6th August 2009, 10:25 AM
  5. Domain Rename = Anyone done it ?
    By pooley in forum Windows
    Replies: 3
    Last Post: 25th May 2006, 12:57 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •