skysel Posted December 9, 2008 Posted December 9, 2008 Converting from VBS to AutoIt.. I'd need some help.. expandcollapse popupConst 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
Andreik Posted December 9, 2008 Posted December 9, 2008 Search on forum about scriptomatic to do what you want simple.
skysel Posted December 9, 2008 Author Posted December 9, 2008 Search on forum about scriptomatic to do what you want simple. something like.-.. expandcollapse popup; ---------------------------------------------------------------------------- ; ; 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
skysel Posted December 9, 2008 Author Posted December 9, 2008 Hmm, joining domain fails. Is there anything wrong with script? :s
skysel Posted December 10, 2008 Author Posted December 10, 2008 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 expandcollapse popup;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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now