#201452 - 2011-01-27 06:10 PM
list power user
|
jcaspar
Fresh Scripter
Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
|
Hello ! 
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
|
|
|
|
#201461 - 2011-01-29 06:58 PM
Re: list power user
[Re: Allen]
|
jcaspar
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
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?
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
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
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
$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
Fresh Scripter
Registered: 2008-09-05
Posts: 7
Loc: FRANCE ALSACE
|
Hello !
Thanks for your answers !
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
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...
$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
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.
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
|
|
|
|
#201618 - 2011-02-18 10:23 AM
Re: list power user
[Re: Bryce]
|
jcaspar
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 ! 
Of course the perfect solution would write only one time the name of a user but this i can modify manually ...
|
|
Top
|
|
|
|
#201621 - 2011-02-18 05:02 PM
Re: list power user
[Re: ShaneEP]
|
ShaneEP
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...
$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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|