Page 1 of 2 12>
Topic Options
#87992 - 2002-09-16 11:51 PM Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
I am trying to automate my callcenter user builds. We have 2 or 3 classes a week of 15 - 20 agents. I read from an excel file (Thanks Kynder [Cool] ) the user ID, full name, description , password, logon script and dept. (which I'll use to assign groups if I can get this working) I get the user account built ok, but none of the other values for name, description etc are working. If the user ID is 9999 I'll get an account 9999 with full name as 9999 and no other info... I have checked my values using ? $value1 ? and all come out ok!
Help! [Confused] [Confused] [Confused]

code:
 Break ON

CLS

$Class = "C:\training\current_build.xls"
ReadData($Class)
? "ID's Have Been Successfully Created"

Function ReadData($Class)
$object = CreateObject("Excel.Application")
If $Class = ""
? "Class File not found"
? "The Excel File "+$Class+" Must exist before ID Build is run"
Goto Clear
EndIf
; Open Workbook
$_=$object.workbooks.Open ($Class)
$Cell = 2 ;Set start value, Row one and two are column and group Headings

$x = $object.cells($Cell, 1).value

While $object.cells($Cell, 1).value <> ""
$Cell = $Cell + 1
If $object.cells($Cell, 1).value = ""
Goto Clear

EndIf

$value1 = $object.cells($Cell, 1).value

$value2 = $object.cells($Cell, 2).value

$value3 = $object.cells($Cell, 3).value

$value4 = $object.cells($Cell, 4).value

$value5 = $object.cells($Cell, 5).value

CreateUser ($Value1, "CCC")

Loop
:clear
$object.application.Quit
$object = ""
EndFunction


Function CreateUser ($XName, $XDomain)

? "Creating Account..."

$UserName = $Value1
$DomainName = "CCC"

;Create the objects Domain and User.

$Domain = GetObject("WinNT://" + $DomainName + ",domain")
$User = $Domain.Create("user", $UserName)

;Set user account flags.

$User.FullName = $Value2
$User.Description = $Value3
$User.SetPassword = $Value4
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)

$User.SetInfo


;Cleanup Objects Domain and User

Set $User = 0
Set $Domain = 0
Set $UserName = 0
Set $DomainName = 0
? "ID complete"
EndFunction


Top
#87993 - 2002-09-17 12:21 AM Re: Where are my Values? need help!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
You're not passing the values into the CreateUser function, only $value1, and your not making use of $XDomain either.

[ 17. September 2002, 00:21: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#87994 - 2002-09-17 12:32 AM Re: Where are my Values? need help!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, he is not passing anything there...
in sense that he passes only the required fields but does not use them.

in this way of thinking, he populates the vars alright, but there is something else...
_________________________
!

download KiXnet

Top
#87995 - 2002-09-17 01:22 PM Re: Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
I used Xname and Xdomain because they were required, but I did not need them (or so I thought) because I read/set the vars I want to use in another function. I am still pretty new at this so my code is prob not very efficent. Is there a better or more standard way? (obviously better as mine doesn't work...) [Big Grin]
Top
#87996 - 2002-09-17 02:00 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Well,

you could make it work by passing $value2 through $value4 as function arguments to CreatUser()

right ?

J.
_________________________



Top
#87997 - 2002-09-17 02:02 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Plus ,

just noticed that you use invalid code :

replace

set $var = 0

by

$var = 0
_________________________



Top
#87998 - 2002-09-17 02:10 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Try these ammendments :

call CreateUser() as this :

code:
$ = CreateUser ($Value1, $Value2, $Value3, $Value4)

CreateUser() should look like this (No error checking / untested)

code:
Function CreateUser ($Name, $FullName, $Desc, $pwd)

? "Creating Account..." ;don't know how this looks , but think it gets better commented out :D

;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
$User = $Domain.Create("user", $Name)

;Set user account flags.

$User.FullName = $FullName
$User.Description = $Desc
$User.SetPassword = $pwd
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)

$User.SetInfo

;Cleanup Objects Domain and User
$Domain = 0
$user = 0

? "ID complete"
EndFunction

hth

Jochen

[ 17. September 2002, 14:13: Message edited by: jpols ]
_________________________



Top
#87999 - 2002-09-17 02:34 PM Re: Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
jpols,
Thanks for helping! [Cool]
I fixed the set statements. I also tried the script changes... I get the same results. They values for $value1 $value2 ... $value5 all display the correct values when printed to screen but when the create user function executes (your way is so much cleaner) I only get user 9999 ($vaule1) and fullname 9999 ($value1... should be $vaule2) and nothing else, no logon.bat, no description [Frown]
I'm still stumped

Top
#88000 - 2002-09-17 02:38 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
JJ,

can you please give a sample of how your Excel table looks ? I will then try to re-write that part [Wink]
_________________________



Top
#88001 - 2002-09-17 02:46 PM Re: Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
jpols,
Sure! rows 1 and 2 are headers row 3 is where data starts:
3a is "9999" agent ID (I am testing with 9999)
3b is "Lastname, First"
3c is "Representative (group), x9999" (description in the format we use)
3d is "password" (default password will be randomly assigned to each class)
3e "dept" (is the dept the will be a mamber of)

Then the next user would start on row 4 repeat.

I hope to use 3e later to assign the user, once created, to groups.

Thanks again for your time. [Smile]

Top
#88002 - 2002-09-17 02:48 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
K,

give me some minutes

l8r
_________________________



Top
#88003 - 2002-09-17 02:51 PM Re: Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
The thing that I just don't get is if I ? $value1 ? for all the values after reading from excel I get the correct values for each var... $value1 is the ID "9999" $value2 is the full name "lastname, first" $value3 is the description... but when I try to pass them to createuser something breaks.
Top
#88004 - 2002-09-17 03:42 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ok,

I see ... try this one (Made sure that all variables are passed to CreateUser()) :

code:
break on cls

$Class = "C:\training\current_build.xls"

$ = ReadData($Class)

? "ID's Have Been Successfully Created"


exit 1


Function ReadData($Class)
If not exist($Class)
? "Class File not found"
? "The Excel File " + $Class + " Must exist before ID Build is run"
exit ()
EndIf
$xl = CreateObject("Excel.Application")

; Open Workbook

$ = $xl.Workbooks.Open($Class)
$Cell = 3 ;Set start value, Row one and two are column and group Headings

while $xl.Range("A"+$Cell+"").value

$value1 = $xl.Range("A"+$Cell+"").value

$value2 = $xl.Range("B"+$Cell+"").value

$value3 = $xl.Range("C"+$Cell+"").value

$value4 = $xl.Range("D"+$Cell+"").value

$value5 = $xl.Range("E"+$Cell+"").value

$ = CreateUser ($Value1, $Value2, $Value3, $Value4, $Value5)

$Cell = $Cell + 1
loop
$xl.UserControl = 1
$ = $xl.Quit
$xl = ""
endfunction


Function CreateUser ($Name, $FullName, $Desc, $pwd, $Group)

? "Creating Account..."
;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
$User = $Domain.Create("user", $Name)

;Set user account flags.

$User.FullName = $FullName
$User.Description = $Desc
$User.SetPassword = $pwd
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)
;add the user to group here !

$User.SetInfo

;Cleanup Objects Domain and User
$Domain = 0
$user = 0

? "ID complete"
EndFunction

_________________________



Top
#88005 - 2002-09-17 03:51 PM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
By the way ,

here a version that should (?) add the user to a group :

code:
break on cls

$Class = "C:\training\current_build.xls"

$ = ReadData($Class)

? "ID's Have Been Successfully Created"


exit 1


Function ReadData($Class)
If not exist($Class)
? "Class File not found"
? "The Excel File " + $Class + " Must exist before ID Build is run"
exit ()
EndIf
$xl = CreateObject("Excel.Application")

; Open Workbook

$ = $xl.Workbooks.Open($Class)
$Cell = 3 ;Set start value, Row one and two are column and group Headings

while $xl.Range("A"+$Cell+"").value

$value1 = $xl.Range("A"+$Cell+"").value

$value2 = $xl.Range("B"+$Cell+"").value

$value3 = $xl.Range("C"+$Cell+"").value

$value4 = $xl.Range("D"+$Cell+"").value

$value5 = $xl.Range("E"+$Cell+"").value

$ = CreateUser ($Value1, $Value2, $Value3, $Value4, $Value5)

$Cell = $Cell + 1
loop
$xl.UserControl = 1
$ = $xl.Quit
$xl = ""
endfunction


Function CreateUser ($Name, $FullName, $Desc, $pwd, $Group)

? "Creating Account..."
;Create the objects Domain and User.

$Domain = GetObject("WinNT://CCC,domain")
$User = $Domain.Create("user", $Name)
$GroupObj = GetObject("WinNT://CCC/$Group")
;Set user account flags.

$User.FullName = $FullName
$User.Description = $Desc
$User.SetPassword = $pwd
$User.LoginScript = "logon.bat"
$User.Put ("PasswordExpired", 1)

$User.SetInfo

$groupObj.Add ("WinNT://CCC/$Name")


;Cleanup Objects Domain and User
$Domain = 0
$user = 0
$groupObj = 0

? "ID complete"
EndFunction

Totally untested [Razz]

J.

[ 17. September 2002, 16:31: Message edited by: jpols ]
_________________________



Top
#88006 - 2002-09-17 05:15 PM Re: Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
Jpols,
...sigh I ran your script and I get the same result. user 9999 named 9999 and no other values. I checked the var in your script and just like the ones in mine they display correctly but do not seem to write to createuser() correctly. Back to square one. Thank you, I have learned several things from your help! [Smile]

[ 17. September 2002, 17:34: Message edited by: JJscorpio ]

Top
#88007 - 2002-09-17 07:59 PM Re: Where are my Values? need help!
JJscorpio Offline
Fresh Scripter

Registered: 2002-06-17
Posts: 34
Loc: Houston, Tx
I know this post is getting long... I am running Kixtart 4.11. PDC is an NT 4.0 server. I have been runnig this from a W2K workstation (maybe a problem?) I tried it from an NT 4.0 (sp 6a) pc and gett an error---
Script error: expected expression:
$User = $Domain.Create("user", $UserName)

I usually get this when my vars are not consistant... but I am not seeing the problem here.

<<< Doh >>> I know why the NT pc gets the error... It doesn't have the WMI dependencies.
My initial problem stands

[ 18. September 2002, 00:01: Message edited by: JJscorpio ]

Top
#88008 - 2002-09-19 09:23 AM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hmmm ,

I think the problem is not the pass of variables to CreateUser() but the ADSI function calls ... Unable to test right now , Anyone else ?

J.
_________________________



Top
#88009 - 2002-09-19 09:27 AM Re: Where are my Values? need help!
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jpols good notice...
like I said in the first reply, the problem is elsewhere.

he does not need to pass the vars as they are global.
_________________________
!

download KiXnet

Top
#88010 - 2002-09-19 09:28 AM Re: Where are my Values? need help!
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Ok,

seems to be that Howard solved your problem !

For all interested : you can find this here

J.
_________________________



Top
#88011 - 2002-09-19 09:48 AM Re: Where are my Values? need help!
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well,
I have a question I don't see asked or answered here.

Are you trying to add accounts to NT or AD?

Maybe try taking a look at this post as well for AD.

Enumerate User Info with ADSI

Top
Page 1 of 2 12>


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

Who's Online
0 registered and 464 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.074 seconds in which 0.024 seconds were spent on a total of 13 queries. Zlib compression enabled.

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