Page 1 of 1 1
Topic Options
#118804 - 2004-04-29 06:18 PM usrtogrp question
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
I am trying to write a script that will add users and or groups to the domain. I am using the usrtogrp executable, which seems to work fine execpt.... I was hoping to capture the results, dump it to a file and search for "Status: no such user.". Is this possible? thanks
Top
#118805 - 2004-04-29 07:20 PM Re: usrtogrp question
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
have never heard of such executable.
thus you need to specify how do you call the exe and does it produce output to console (if it's console exe) and does it set error-codes etc.
_________________________
!

download KiXnet

Top
#118806 - 2004-04-29 07:46 PM Re: usrtogrp question
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
Thanks for the quick response!
Here is my code:
****************************************
;BREAK OFF
SetConsole ("Show")

$filename = "*.txt" ; text files with Domain, Group, and user info

$startdir="g:\Groups\" ; directory to start search

$tmpfile = "c:\groups.txt" ; temporary file for search results

$GroupProgam = $startdir + "usrtogrp.exe"

; write search results to temporary file.

CD "$startdir"
SHELL "%comspec% /c dir /s /b $filename > $tmpfile"

; read results from temporary file.
OPEN(1,$tmpfile,2)
cls
?
?
?
?
?
? " Current Group Text Files"
? "_____________________________________________"
?
?
$string = READLINE(1)
WHILE @ERROR = 0


; split the result in path and filename.
$path = ""
$file = $string

If $string = ""
goto finish
Else
WHILE INSTR($file,"\")
$path = $path + SUBSTR($file,1,INSTR($file,"\"))
$file = SUBSTR($file,INSTR($file,"\")+1,LEN($file))
LOOP

$filename = $file

$length =len($filename)
$length2 =($length -4)
$filename2 =left($filename, $length2)
?$Filename2 ; This displays the names of the text files
$string = READLINE(1)

Endif

LOOP
?
?
CLOSE(1)
? "_________________________________________________"
?
? "Enter the Group Text File You Want to Add: "
gets $selecttextfile


$selecttextfile2 = $selecttextfile +".txt"

cls

$RunGrpProgram = "g:\groups\usrtogrp.exe " + $selecttextfile2
shell "%comspec% /c $RunGrpProgram"

goto finish

:finish
Del $tmpfile
exit
********************************

the results are shown in the dos window and as soon as the scripts finishes the results are gone.

Top
#118807 - 2004-04-29 07:53 PM Re: usrtogrp question
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
sorry I forgot.. the program is usrtogrp.exe out of the Windows 2000 Pro Resource Kit.

Thanks Again

Top
#118808 - 2004-04-30 07:01 AM Re: usrtogrp question
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you already seem to have correct start there...
just the same as you do your dir, you probably can do the redirect:

$RunGrpProgram = "g:\groups\usrtogrp.exe " + $selecttextfile2
shell "%comspec% /c $RunGrpProgram > %%temp%%\mytempfile.txt"

$nul=open(2,"%temp%\mytempfile.txt")
$line=readline(2)
while not @error
if instr($line, "success")
"this thing worked fine"
endif
$line=readline(2)
loop
$nul=close(2)

or something similar...
looking at the code, I suggest you read this thread:
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81592
_________________________
!

download KiXnet

Top
#118809 - 2004-04-30 08:46 AM Re: usrtogrp question
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh...
and if the proggie supports error-info, you could simply use:
$RunGrpProgram = "g:\groups\usrtogrp.exe " + $selecttextfile2
shell "%comspec% /c $RunGrpProgram >nul"
if @error
"damn, it failed"
else
"who would have quessed, it works after all"
endif
_________________________
!

download KiXnet

Top
#118810 - 2004-04-30 06:32 PM Re: usrtogrp question
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
thanks.....I will give that a try
Top
#118811 - 2004-04-30 09:19 PM Re: usrtogrp question
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
that seems to work....however its really wierd. When I run the script it will only pipe "Status: successfully added."
to the file. If the line say "Status: already a member." or "Status: no such user." it will show it on the screen but will not put it in the file. I will have to a search on google or Microsoft to see if I can find out why it is doing that.
Thanks for all your help

Top
#118812 - 2004-04-30 09:42 PM Re: usrtogrp question
jpeachman Offline
Fresh Scripter

Registered: 2002-11-18
Posts: 39
You're capturing the successes, which are on STDOUT, but not the failures, which are on STDERR. You should be able to redirect STDERR to STDOUT so that you'll get it all by modifying one line to:
Code:
shell "%comspec% /c $RunGrpProgram > %%temp%%\mytempfile.txt 2>&1"



Joe

Top
#118813 - 2004-05-04 08:05 PM Re: usrtogrp question
kbarnett Offline
Fresh Scripter

Registered: 2001-11-09
Posts: 28
Thanks Joe,
That worked great.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.058 seconds in which 0.023 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