Jump to content

Computername, domain


skysel
 Share

Recommended Posts

Converting from VBS to AutoIt.. I'd need some help.. :)

Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
 
Dim sCmpName
Dim sUser, sPassword, sDomain, sOU
 
sUser = "<domainuserid>"
sPassword = "<domainpassword>"
sDomain = "<mydomain>"
sOU = "<ou=myou,dc=mydomain,dc=com>"
 
sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If sCmpName = "" Then
  Wscript.Echo "Exiting script."
  Wscript.Quit
End If
 
Dim oWMI, oCmp, oOS, sReturn
 
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
For Each oCmp in oWMI.InstancesOf("Win32_ComputerSystem")
  sReturn = oCmp.Rename(sCmpName)
  If sReturn <> 0 Then
    Wscript.Echo "Rename failed.  Error = " & Err.Number & _
      vbcrlf & "Exiting script."
  Else
    Wscript.Echo "Rename successful."
    sReturn = oCmp.JoinDomainOrWorkgroup(sDomain, sPassword, _
      sDomain & "\" & sUser, sOU, JOIN_DOMAIN+ACCT_CREATE)
    If sReturn <> 0 Then
      Wscript.Echo "Join domain failed.  Error = " & Err.Number & _
        vbcrlf & "Exiting script."
    Else
      Wscript.Echo "Join domain successful."
    End If
    Wscript.Echo "Rebooting computer..."
    For Each oOS in oWMI.InstancesOf("Win32_OperatingSystem")
      sReturn = oOS.Reboot
    Next
  End If
Next
Link to comment
Share on other sites

Search on forum about scriptomatic to do what you want simple.

something like.-..

; ----------------------------------------------------------------------------
;
; VBScript to AutoIt Converter v0.52
;
; ----------------------------------------------------------------------------



Const $JOIN_DOMAIN = 1
Const $ACCT_CREATE = 2

Dim $sCmpName
Dim $sUser, $sPassword, $sDomain, $sOU

$sUser = "user"
$sPassword = "pass"
$sDomain = "domain"
$sOU = "<ou=myou,dc=domain.local,dc=company>"

$sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If $sCmpName = "" Then
  MsgBox(0,"Fail","Exiting script.")
  Exit
EndIf

Dim $oWMI, $oCmp, $oOS, $sReturn

 $oWMI = ObjGet("winmgmts:\\.\root\cimv2")
For $oCmp in $oWMI.InstancesOf("Win32_ComputerSystem")
  $sReturn = $oCmp.Rename($sCmpName)
  If $sReturn <> 0 Then
    MsgBox(0,"Fail","Rename failed.  Error = " & @error &       @CRLF & "Exiting script.")

  Else
    MsgBox(0,"Rename","Rename successful.")
    $sReturn = $oCmp.JoinDomainOrWorkgroup($sDomain, $sPassword, $sDomain & "\" & $sUser, $sOU, $JOIN_DOMAIN+$ACCT_CREATE)

    If $sReturn <> 0 Then
      MsgBox(0,"Fail","Join domain failed.  Error = " & @error &         @CRLF & "Exiting script.")

    Else
      MsgBox(0,"Success","Join domain successful.")
    EndIf
      MsgBox(0,"Reboot","Rebooting computer...")
    For $oOS in $oWMI.InstancesOf("Win32_OperatingSystem")
      $sReturn = $oOS.Reboot
    Next
  EndIf
Next

:)

Link to comment
Share on other sites

I was playing around some more with this, and I'm really really annoyed on why it is not working...And FYI, all the joindomain scripts using JoinDomainOrWorkgroup on this forum fail to work :s

;Constants

Const $JOIN_DOMAIN = 1
Const $ACCT_CREATE = 2
Dim $sCmpName
Dim $sUser, $sPassword, $sDomain, $sOU

;User / Domain Data

$sUser = "user"
$sPassword = "password"
$sDomain = "COMPANY"
$sOU = "<ou=Computers,dc=COMPANY,dc=local>"

;Input new Computer Name

$sCmpName = InputBox("Enter the new computer name:", "Computer Name")
If $sCmpName = "" Then
  MsgBox(0,"Fail","Exiting script.")
  Exit
EndIf

Dim $oWMI, $oCmp, $oOS, $sReturn

;Rename Computer

$oWMI = ObjGet("winmgmts:\\.\root\cimv2")
    
    For $oCmp in $oWMI.InstancesOf("Win32_ComputerSystem")
    $sReturn = $oCmp.Rename($sCmpName)
    If $sReturn <> 0 Then
    MsgBox(0,"Fail","Rename failed.  Error = " & @error &       @CRLF & "Exiting script.")
    Else
    MsgBox(0,"Rename","Rename successful.")
    EndIf

Next

;Join to Domain
$ReturnValue = $oCmp.JoinDomainOrWorkGroup($sDomain, $sPassword, $sDomain & "\" & $sUser, $sOU, $JOIN_DOMAIN + $ACCT_CREATE)

    If $ReturnValue <> 0 Then
    MsgBox(0,"Fail","Join domain failed.  Error = " & @error &         @CRLF & "Exiting script.")
    Exit
    Else
    MsgBox(0,"Success","Join domain successful.")
    MsgBox(0,"Reboot","Rebooting computer...")
    RunWait("shutdown -r -t 00")
    EndIf
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...