Page 1 of 1 1
Topic Options
#115723 - 2004-03-09 02:20 AM What am I doing wrong?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
I am trying to enum all computers in a domain so that I can move them to another domain. The code that I am using is from the ComNetView UDF. For some reason it keeps returning users instead of computers.

Below is the code that I am using. Any help is appreciated.

Code:
 

Break On
$System = CreateObject("Kixtart.System")

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.Height = 147
$Form.Text = "Domain Move"
$Form.Width = 223
;**************************************

;************* TextBox1 **************
$TextBox1 = $Form.Controls.TextBox()
$TextBox1.Height = 20
$TextBox1.Left = 105
$TextBox1.Text = ""
$TextBox1.Top = 0
$TextBox1.Width = 100
;**************************************

;************* TextBox2 **************
$TextBox2 = $Form.Controls.TextBox()
$TextBox2.Height = 20
$TextBox2.Left = 105
$TextBox2.PasswordChar = "*"
$TextBox2.Text = ""
$TextBox2.Top = 30
$TextBox2.Width = 100
;**************************************

;************* TextBox3 **************
$TextBox3 = $Form.Controls.TextBox()
$TextBox3.Height = 20
$TextBox3.Left = 105
$TextBox3.Text = ""
$TextBox3.Top = 30
$TextBox3.Width = 100
$TextBox3.Visible = False
;**************************************

;************* Label1 **************
$Label1 = $Form.Controls.Label()
$Label1.BackColor = 212,208,200
$Label1.Height = 23
$Label1.Left = 0
$Label1.Text = "UserName"
$Label1.Top = 0
$Label1.Width = 100
;**************************************

;************* Label2 **************
$Label2 = $Form.Controls.Label()
$Label2.BackColor = 212,208,200
$Label2.Height = 23
$Label2.Left = 0
$Label2.Text = "Password"
$Label2.Top = 30
$Label2.Width = 100
;**************************************

;************* Label3 **************
$Label3 = $Form.Controls.Label()
$Label3.BackColor = 212,208,200
$Label3.Height = 23
$Label3.Left = 0
$Label3.Text = "Domain"
$Label3.Top = 60
$Label3.Width = 100

;************ Label4 ******************
$Label4 = $Form.Controls.Label()
$Label4.BackColor = 212,208,200
$Label4.Height = 23
$Label4.Left = 0
$Label4.Top = 30
$Label4.Width = 100
$Label4.Visible = False
;**************************************

;************* Button1 **************
$Button1 = $Form.Controls.Button()
$Button1.Height = 23
$Button1.Left = 0
$Button1.Text = "Start"
$Button1.Top = 90
$Button1.Width = 75
$Button1.OnClick = "DoIt ()"
;**************************************

;************* Button2 **************
$Button2 = $Form.Controls.Button()
$Button2.Height = 23
$Button2.Left = 120
$Button2.Text = "Exit"
$Button2.Top = 90
$Button2.Width = 75
$Button2.OnClick = "Quit"
;**************************************

;************* Button3 **************
$Button3 = $Form.Controls.Button()
$Button3.Height = 23
$Button3.Left = 0
$Button3.Text = "Convert"
$Button3.Top = 90
$Button3.Width = 75
$Button3.OnClick = "Moving ($List, $User, $Pass)"
$Button3.Visible = False
$Button3.Enabled = False
;**************************************

;************* ComboBox1 **************
$ComboBox1 = $Form.Controls.ComboBox()
$ComboBox1.DropDownWidth = 121
$ComboBox1.Height = 21
$ComboBox1.Left = 105
$ComboBox1.Sorted = "False"
$ComboBox1.List = "HSSANCFY", "HSSJNUFY", "HSSFAIFY"
$ComboBox1.ListIndex = 0
$ComboBox1.Top = 60
$ComboBox1.Width = 100
;**************************************


;KD END

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1

Global $list, $objDomain, $objComputername, $filter[0], $ComNetView
Global $User, $Pass
SetOption("NoVarsInStings", "On")



Function DoIt ()

;**************************************
; Validation logic
;**************************************
If $TextBox1.Text = ""
$nul= MessageBox ("You must enter all information before continuing", "OOPS")
Exit
Else $User = $TextBox1.Text
EndIf

If $TextBox2.Text = ""
$nul= MessageBox ("You must enter all information before continuing", "OOPS")
Exit
Else $Pass = $TextBox2.Text
EndIf

;**************************************
; Turn off extra information not needed
;**************************************

$label1.visible = False
$Textbox1.visible = False
$label2.visible = False
$Textbox2.visible = False
$label3.visible = False
$ComboBox1.visible = False
$Button1.Visible = False
$Button1.Enabled = False
$Button3.Visible = True
$Domain = $combobox1.text

;**************************************
; Begin getting list of workstations
;**************************************

Debug On
$Label4.Text = "Working"
$Label4.visible = True

;**************************************
; Taken from Sealeopards UDF ComNetView
;**************************************

if val(@INWIN)<>1 or val(@DOS)<5
exit 196
endif

$domain = trim($domain)

if $domain=''
$domain=@DOMAIN
endif

$filter[0]='Computer'
$objDomain = GetObject('WinNT://' + $domain + ',domain')


if @ERROR
exit @ERROR
endif

$objDomain.Filter=$filter

if @ERROR
exit @ERROR
endif

For Each $objComputername In $objDomain
redim preserve $list[ubound($list)+1]
$list[ubound($list)] = $objComputername.Name
Next

$objDomain = 0

;**************************************
; should have an array now, but don't
;**************************************

;**************************************
; Change labels and set up for site entry
;**************************************

$label4.text = " Enter Site Code"
$TextBox3.visible = True
$TextBox3.SetFocus
$Button3.Enabled = True

EndFunction


Function Moving ($List, $User, $Pass)

;**************************************
; Check to see if Site ID is long enough
;**************************************

If Len ($textbox3.text) <> 3
$nul= MessageBox ("You must enter all information before continuing", "OOPS")
Exit
Else
$site = $textbox3.text
EndIf

;**************************************
; Now we look for a match and move the
; computer from one domain to another
;**************************************

For each $Computer in $List
if Left($Computer, 3) = $site
; Run "CMD NETDOM MOVE " +$Computer +"DOMAIN:HSSOCS USERD:"+$User+" PASSWORDD:"+$Pass
; Write completion results to a file
endif
Next
EndFunction

_________________________
Today is the tomorrow you worried about yesterday.

Top
#115724 - 2004-03-09 04:19 AM Re: What am I doing wrong?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Computers are users... See this thread. Sorry I can't locate the original thread listed in this post.
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=40251&page=&view=&sb=5&o=&vc=1

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#115725 - 2004-03-09 04:34 AM Re: What am I doing wrong?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I just tested ComNetView() and it works fine for me. Looking at your code again...

Why did you change jens' function? You could have simply called it.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#115726 - 2004-03-09 04:52 AM Re: What am I doing wrong?
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Have you checked the object class?

Make this change to check the class what is returned.
Code:

For Each $objComputername In $objDomain
redim preserve $list[ubound($list)+1]
$list[ubound($list)] = $objComputername.Name
? "Name: " + $objComputername.Name
? "Class: " + $objComputername.Class
Next


What is the class of the objects returned?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#115727 - 2004-03-09 06:31 PM Re: What am I doing wrong?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
It is returning both User and Computer. After further debugging I have found that for some reason the incrementing of the $list array is not happening so I changed the code to look like this.

Code:
 For Each $objComputername In $objDomain 
If $objComputername.Class = "Computer"
redim preserve $list[$count]
$list[$count] = $objComputername.Name
? UBound($list) $list[$count]
$count=$count + 1
EndIf
Next



But for some reason the $list finishes with a -1 value for the Ubound($list)
_________________________
Today is the tomorrow you worried about yesterday.

Top
#115728 - 2004-03-09 07:23 PM Re: What am I doing wrong?
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
This is what I use to retrieve all computers in a domain. Maybe this will help you.

Code:
$Domain = GetObject("WinNT://" + @DOMAIN)
For Each $Obj IN $Domain
IF $Obj.class = "Computer"
? $Obj.name
ENDIF
NEXT




Top
#115729 - 2004-03-09 07:29 PM Re: What am I doing wrong?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Which is exactly what he's doing!

However, COMNetView() should work. The only thing his work-around code is not doing is filtering the list of users to only include computers.
_________________________
There are two types of vessels, submarines and targets.

Top
#115730 - 2004-03-09 07:37 PM Re: What am I doing wrong?
Everyone Offline
Getting the hang of it

Registered: 2003-10-19
Posts: 81
Loc: Beale Air Force Base, CA
Too much to read.
No, not exactly. My example provides filtering for computer objects. Which, like you said, his does not filter. So to stop getting everything and only get computer objects returned, he should do something like this:
Code:
If $objComputername.Class = "Computer"

"do all his stuff"
Endif


So that it only tries to do his thing to objects in that domain of the Computer class. Hence my example.


Edited by Everyone (2004-03-09 07:40 PM)

Top
#115731 - 2004-03-09 08:18 PM Re: What am I doing wrong?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
If you look at the code update you will see that I am filtering for "Computer" only. The problem that I am having is that when I leave the For-Next loop the array is returning a value of -1

Code:
 For Each $objComputername In $objDomain 
If $objComputername.Class = "Computer"
$count=$count + 1
redim preserve $list[$count]
$list[$count] = $objComputername.Name
EndIf
Next

_________________________
Today is the tomorrow you worried about yesterday.

Top
#115732 - 2004-03-09 08:31 PM Re: What am I doing wrong?
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
You just need to DIM the $list first.

Code:
Dim $list
$objDomain = GetObject("WinNT://"+@Domain)
$count=0
For Each $objComputername In $objDomain
If $objComputername.Class = "Computer"
redim preserve $list[$count]
$list[$count] = $objComputername.Name
$count=$count+1
EndIf
Next
$null=messagebox(UBound($list),"Computer",0)



Works fine for me...

Top
#115733 - 2004-03-09 08:55 PM Re: What am I doing wrong?
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Thanks found out the problem....

I had my globals defined in the wrong place.
_________________________
Today is the tomorrow you worried about yesterday.

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 774 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.061 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org