Sign in to follow this  
Followers 0
Haferkamp

Convert vbs to autoit

5 posts in this topic

#1 ·  Posted (edited)

I have a script.. which parses my machine name.. into an array.. of Group names.. which I then want to use to add the computers domain account to the corresponding domain level groups...

; AUTOIT script to add workstations to domain groups...
#Include <Array.au3>
$COMPUTERNAME = EnvGet("COMPUTERNAME")
$Groups = StringSplit($COMPUTERNAME, "-")
$TempArray = StringSplit($Groups[1], "1234567890")
_ArrayDisplay($TempArray)
$Groups[2] = $TempArray[1]
_ArrayDisplay($Groups)
;Look to handle old Naming scheme.. add media.. else exit
If UBound($Groups) = 3 Then
    If $Groups[1] = "MEDIA" Then; Old naming scheme.
        _ArrayPop($Groups)
    Else
        Exit
    EndIf
EndIf
$x=1
While $x < UBound($Groups)
    $cmd = 'net group OAL-G-' & $Groups[$x] & ' ' & $COMPUTERNAME & ' /add /domain'
    RunWait(@Comspec & " /c " & $cmd, "", @SW_HIDE)
    $x = $x + 1
WEnd

The While loop.. does not function.. becouse the net group command does not allow me to add computer accounts to groups.. only user accounts..

I have the following vbs script.. which I would like to convert to Autoit Script.. and embed inside the While loop above...

Dim ArgObj, strGroup
Set ArgObj = WScript.Arguments

strGroup = ArgObj(0)

Set objSysInfo = CreateObject( "ADSystemInfo" )
strComputerName = objSysInfo.ComputerName

' Constants for the NameTranslate object. 
Const ADS_NAME_INITTYPE_GC = 3 
Const ADS_NAME_TYPE_NT4 = 3 
Const ADS_NAME_TYPE_1779 = 1 

' Determine DNS name of domain from RootDSE. 
Set objRootDSE = GetObject("LDAP://RootDSE") 
strDNSDomain = objRootDSE.Get("defaultNamingContext") 

' Use the NameTranslate object to find the NetBIOS domain name from the DNS domain name. 
Set objTrans = CreateObject("NameTranslate") 
objTrans.Init ADS_NAME_INITTYPE_GC, "" 
objTrans.Set ADS_NAME_TYPE_1779, strDNSDomain 
strNetBIOSDomain = objTrans.Get(ADS_NAME_TYPE_NT4) 

' Remove trailing backslash. 
strNetBIOSDomain = Left(strNetBIOSDomain, Len(strNetBIOSDomain) - 1) 

' Use the Set method to specify the NT format of the group name. 
objTrans.Set ADS_NAME_TYPE_NT4, strNetBIOSDomain & "\" & strGroup 
strGroupDN = objTrans.Get(ADS_NAME_TYPE_1779) 
Set objGroup = GetObject("LDAP://" & strGroupDN) 

Set objSysInfo = CreateObject("ADSystemInfo")
strComputerDN = objSysInfo.ComputerName  

Set objComputer = GetObject("LDAP://" & strComputerDN) 
If (objGroup.IsMember(objComputer.ADsPath) = False) Then 
    objGroup.Add(objComputer.ADsPath) 
End If

Basicly the vbs script takes 1 argument.. (the group name).. and adds the current computer name to the corresponding group.. (in the machines current domain)

MORE info...

Computer name structure is in process of change.. old machine names = LOCATION "-P" Number... Ex.. "MEDIA-P1001"

New naming structure = Building Room "-" Number "-" Purpose (optional aditional "-" purpose(s) Ex... SCC102-023-I-A

Edited by Haferkamp

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

;~ Dim ArgObj, strGroup
;~ Set ArgObj = WScript.Arguments; means commandline, look at $CmdLine in the helpfile

;$strGroup = $ArgObj(0); number of parameters, same as $CmdLine[0]
$strGroup = $CmdLine[0]

;~ Set objSysInfo = CreateObject( "ADSystemInfo" );     ObjCreate("ADSystemInfo")
;~ strComputerName = objSysInfo.ComputerName;           $objSysInfo.ComputerName
$strComputerName = @ComputerName

;' Constants for the NameTranslate object. 
Const $ADS_NAME_INITTYPE_GC = 3 
Const $ADS_NAME_TYPE_NT4 = 3 
Const $ADS_NAME_TYPE_1779 = 1 

;' Determine DNS name of domain from RootDSE. 
$objRootDSE = ObjGet("LDAP://RootDSE")
$strDNSDomain = $objRootDSE.Get("defaultNamingContext") 

;' Use the NameTranslate object to find the NetBIOS domain name from the DNS domain name. 
$objTrans = ObjCreate("NameTranslate")
$objTrans.Init ($ADS_NAME_INITTYPE_GC, "") 
$objTrans.Set ($ADS_NAME_TYPE_1779, $strDNSDomain) 
$strNetBIOSDomain = $objTrans.Get($ADS_NAME_TYPE_NT4) 

;' Remove trailing backslash. 
$strNetBIOSDomain = StringLeft($strNetBIOSDomain, StringLen($strNetBIOSDomain) - 1) 

; Use the Set method to specify the NT format of the group name. 
$objTrans.Set ($ADS_NAME_TYPE_NT4, $strNetBIOSDomain & "\" & $strGroup) 
$strGroupDN = $objTrans.Get($ADS_NAME_TYPE_1779) 
$objGroup = ObjGet("LDAP://" & $strGroupDN) 

$objSysInfo = ObjCreate("ADSystemInfo")
$strComputerDN = $objSysInfo.ComputerName  

$objComputer = ObjGet("LDAP://" & $strComputerDN) 
If ($objGroup.IsMember($objComputer.ADsPath) = False) Then 
    $objGroup.Add($objComputer.ADsPath) 
EndIf

Edited by Pain

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

download the 2003 server resource kit and look at the dsadd command, it can do what you want.

You don't have to have the resource kit installed on the machine to run the script, you just need it to grab the files.

You can uninstall it after that if you want.

You should see a dll in the folder too it was needed for one of the ds commands, so keep that in mind if you have trouble.

I'm sure theirs probably some way to do it in AutoIT with a WIN_API or DLL sommand but I don't know how.

Kenny

Edited by ken82m

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

I'm sure there's a way to do this natively in AutoIT with WIN_API or something but I don't know how.


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

Here is the current version of my script.. all in autoit.. seems to be worksing now.. thnks 4 the help

; AUTOIT script to add workstations to domain groups...
#Include <Array.au3>

;' Constants for the NameTranslate object. 
Const $ADS_NAME_INITTYPE_GC = 3 
Const $ADS_NAME_TYPE_NT4 = 3 
Const $ADS_NAME_TYPE_1779 = 1 

$Groups = StringSplit(@ComputerName, "-")
$TempArray = StringSplit($Groups[1], "1234567890")
$Groups[2] = $TempArray[1]
;Look to handle old Naming scheme.. add media.. else exit
If UBound($Groups) = 3 Then
    If $Groups[1] = "MEDIA" Then; Old naming scheme.
        _ArrayPop($Groups)
    Else
        Exit
    EndIf
EndIf

;' Determine DNS name of domain from RootDSE. 
$objRootDSE = ObjGet("LDAP://RootDSE")
$strDNSDomain = $objRootDSE.Get("defaultNamingContext") 
;' Use the NameTranslate object to find the NetBIOS domain name from the DNS domain name. 
$objTrans = ObjCreate("NameTranslate")
$objTrans.Init ($ADS_NAME_INITTYPE_GC, "") 
$objTrans.Set ($ADS_NAME_TYPE_1779, $strDNSDomain) 
$strNetBIOSDomain = $objTrans.Get($ADS_NAME_TYPE_NT4) 
;' Remove trailing backslash. 
$strNetBIOSDomain = StringLeft($strNetBIOSDomain, StringLen($strNetBIOSDomain) - 1) 

$x=1
While $x < UBound($Groups)
; Use the Set method to specify the NT format of the group name. 
    $objTrans.Set ($ADS_NAME_TYPE_NT4, $strNetBIOSDomain & "\OAL-G-" & $Groups[$x]) 
    $strGroupDN = $objTrans.Get($ADS_NAME_TYPE_1779) 
    $objGroup = ObjGet("LDAP://" & $strGroupDN)
    $objSysInfo = ObjCreate("ADSystemInfo")
    $strComputerDN = $objSysInfo.ComputerName
    $objComputer = ObjGet("LDAP://" & $strComputerDN) 
    If ($objGroup.IsMember($objComputer.ADsPath) = False) Then 
        $objGroup.Add($objComputer.ADsPath) 
    EndIf
    $x = $x + 1
WEnd

Share this post


Link to post
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
Sign in to follow this  
Followers 0