Page 1 of 1 1
Topic Options
#201452 - 2011-01-27 06:10 PM list power user
jcaspar Offline
Fresh Scripter

Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
Hello ! \:D

Id like to list in a text file all user having power user rights

the command to use in the shell is that one

net localgroup " utilisateurs avec pouvoir" >

could you explain to me how to script this with kixtart

i imagine will be something like shell "net localgroup 'utilisateurs avec pouvoirs' > pouvoir.txt"

Thansk for your advices and tricks ;\)

Jean-Marc

Top
#201453 - 2011-01-27 06:38 PM Re: list power user [Re: jcaspar]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Redirection requires using the cmd shell. Something like:

 Code:
shell '%comspec% /c net localgroup "utilisateurs avec pouvoirs" > pouvoir.txt'
_________________________
(... better days ahead)

Top
#201457 - 2011-01-28 12:23 PM Re: list power user [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
If you later plan on parsing the output file with Kix, you might want to look at WshPipe(), which runs a command and collects the output into a Kix variable.

The version posted here combines STDOUT and STDERR output streams, just as you'd see on the screeen. I have a modified version on my web site that returns a two element array - one for STDOUT and one for STDERR - making things a bit easier to process.

Either UDF eliminates the SHELL command and the need to open/read/parse the data in the file you collected. Same command syntax, but without the final redirection.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#201461 - 2011-01-29 06:58 PM Re: list power user [Re: Allen]
jcaspar Offline
Fresh Scripter

Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
Hello !

Thanks for your answer but the syntax doesn't seem to be correct

i think the part in red is the cause of the problem

Shell '%comspec% /c net localgroup "utilisateurs avec pouvoirs" > pouvoir.txt'

[b][/b]

Thanks a lot for your new advices !

Top
#201462 - 2011-01-29 09:15 PM Re: list power user [Re: jcaspar]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I just tested that line, works fine for me. Must be an error somewhere else in your script?

 Code:
Shell '%comspec% /c net localgroup "administrators" > users.txt'


Also, I think it gives an error if the group doesnt exist, so maybe thats a problem?


Edited by CitrixMan (2011-01-29 09:16 PM)

Top
#201463 - 2011-01-30 03:52 PM Re: list power user [Re: ShaneEP]
jcaspar Offline
Fresh Scripter

Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
Thanks for your answer !

Yes afer checking more it runs fine just i was surprised to see no information on the shell

I have 50 users in my network and i would like it wrote in the same file

and only one time.

Could you explain to me how i can read a file and write only the information if the user has not been connected before ?

Thanks a lot for your advices !

Top
#201465 - 2011-01-30 07:15 PM Re: list power user [Re: jcaspar]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
That's a little bit more complicated, but certainly possible. Here is one method. It writes to a central .INI file. Just change the first 2 lines to the location you want the central file to be, and what group you want to check for. It also doesnt run the group check if they are already in the central file for that group. Good luck!

-Shane

 Code:
$collectionfile = @ScriptDir+"\users.ini"
$grouptocheckfor = "ADMINISTRATORS"

if ReadProfileString($collectionfile,$grouptocheckfor,@UserID)=""
   if ReadProfileString($collectionfile,"Non-"+$grouptocheckfor,@UserID)=""
      Shell '%comspec% /c net localgroup '+$grouptocheckfor+' > %temp%\users.txt'
      $groupinfo = ReadFile("%temp%\users.txt")
      for each $line in $groupinfo
         if instr($line,@UserID)
            $null = WriteProfileString($collectionfile,$grouptocheckfor,@UserID,@WkSta)
         endif
      next
      if readprofilestring($collectionfile,$grouptocheckfor,@UserID)=""
         $null = WriteProfileString($collectionfile,"Non-"+$grouptocheckfor,@UserID,@WkSta)
      endif
   endif
endif

Function ReadFile($file)
	Dim $lf, $f, $_, $t
	$lf=chr(10)
	$f=freefilehandle
	$_=open($f,$file)
		if @error   exit @error   endif
		do $t=$t+$lf+readline($f) until @error
		$_=close($f)
	$ReadFile=split(substr($t,2),$lf)
EndFunction

Top
#201614 - 2011-02-16 09:09 PM Re: list power user [Re: ShaneEP]
jcaspar Offline
Fresh Scripter

Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
Hello !

Thanks for your answers ! \:D

I have a new question about that script i 'd like
to add an information in the text file : i'd like to add the username
i was thinking to act like in the following code but my idea doesn't function ... could you help me to resolve that question ?

Shell '%comspec% /c net localgroup "Utilisateurs avec pouvoir" & @wuserid>>gogo.txt'


Thank you very much for your suggestions !


Jean Marc

Top
#201615 - 2011-02-16 09:33 PM Re: list power user [Re: jcaspar]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
It should already be writing the Username and Computername to the central INI file via this these lines...
 Code:
$null = WriteProfileString($collectionfile,$grouptocheckfor,@UserID,@WkSta)
$null = WriteProfileString($collectionfile,"Non-"+$grouptocheckfor,@UserID,@WkSta)

Assuming that you're talking about the code that I posted anyways.

Top
#201616 - 2011-02-16 09:47 PM Re: list power user [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
But if for whatever reason you want to add to the temp text file, you can always use the WriteLine() right after it is created from the command prompt.
 Code:
Shell '%comspec% /c net localgroup '+$grouptocheckfor+' > "%temp%\users.txt"'
$fh = FreeFileHandle()
If Open($fh,"%temp%\users.txt",4)=0
   $null = WriteLine($fh,"USER: "+@UserID)
   $null = WriteLine($fh,"COMPUTER: "+@WkSta)
   $null = Close($fh)
EndIf

Of course doing this will ruin the rest of the code I posted that checks for the existence of the username in the file to verify their group membership, since this will put all of the members of the group into the file, and then the current username as well. This doesn't make much sense to me anymore.

Top
#201617 - 2011-02-17 05:38 PM Re: list power user [Re: ShaneEP]
Bryce Offline
KiX Supporter
*****

Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
I got a question...

Do you just need this list in a text file, or you going to use this list later on in your script?

you can use ADSI to query the power users group and return everything in a variable with out having to shell out and recapture the data from a command line.

Top
#201618 - 2011-02-18 10:23 AM Re: list power user [Re: Bryce]
jcaspar Offline
Fresh Scripter

Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
T :)hanks for your answer !

The initial idea was to list all poweruser of my domain in a text file
but if you have a better idea i'm interested ! \:D

Of course the perfect solution would write only one time the name of a user
but this i can modify manually ...

Top
#201620 - 2011-02-18 04:36 PM Re: list power user [Re: jcaspar]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Well the code i posted about 3 posts ago, will put all users into central .INI file for you, categorized according to whether or not they are a member of the specified group. All that you need to be change is the group to check for, and the location of the file you want to save the info to (the first 2 lines of the script). Did you try it?
Top
#201621 - 2011-02-18 05:02 PM Re: list power user [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
And here is an even simpler method...I don't know why I was leaving it so complicated...

 Code:
$collectionfile = @ScriptDir+"\users.ini"
$grouptocheckfor = "Utilisateurs avec pouvoir"

if ReadProfileString($collectionfile,$grouptocheckfor,@UserID)=""
   if ReadProfileString($collectionfile,"Non-"+$grouptocheckfor,@UserID)=""
      if InGroup("\\"+@WkSta+"\"+$grouptocheckfor)
         $null = WriteProfileString($collectionfile,$grouptocheckfor,@UserID,@WkSta)
      else
         $null = WriteProfileString($collectionfile,"Non-"+$grouptocheckfor,@UserID,@WkSta)
      endif
   endif
endif


Edited by CitrixMan (2011-02-18 05:13 PM)

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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.092 seconds in which 0.044 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