Sign in to follow this  
Followers 0
Saymaad Mansoor

Get windows usernames

15 posts in this topic

is it possible to get the usernames in windows using Autoit and save them into a txt file or something ?

If yes please tell me how and give me the code as I have never ever used Autoit

Share this post


Link to post
Share on other sites



is it possible to get the usernames in windows using Autoit and save them into a txt file or something ?

If yes please tell me how and give me the code as I have never ever used Autoit

Current username ? or All usernames that ever logged in to your computer?

Precise your question a bit more.


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Current username ? or All usernames that ever logged in to your computer?

Precise your question a bit more.

All the usernames as shown in user accounts in the control panel (for windows 2000 and above)

Share this post


Link to post
Share on other sites

This will give you all the folder names in Documents and Settings...which includes all the usernames plus some extra folders:

#include <File.au3>
$path = StringTrimRight (@DocumentsCommonDir,19); trims documents common directory path by removing All Users\Documents part to get Documents and settings folder path
$folders = _FileListToArray($path); Lists all folders in Documents and settings folder
$i = 0
For $i = 1 to $folders[0] Step 1
    MsgBox(0,'',$folders[$i])   
Next

I believe we should all pay our tax with a smile. I tried - but they wanted cash!

Share this post


Link to post
Share on other sites

but where will I get the result ?

and wont this script get any other folders created there ?

Share this post


Link to post
Share on other sites

And how can I distinguish between the username & other folders that the script fetches ?

Share this post


Link to post
Share on other sites

Have a look at This Topic it may help you get what you want.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Well I check the script can you guys please modify it to send the usernames to a .txt file so that I can make use of the usernames ?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Well I check the script can you guys please modify it to send the usernames to a .txt file so that I can make use of the usernames ?

May I write your script for you? Really? :o

How about something that runs a command line like: net users > users.txt

For other interested parties I've used something like this to get a list of users by group membership, works on Win XP and requires the AutoIt3 beta version:

Dim $names, $users
; Run command line, keeping a connection to read the console output
$net_exe = Run(@SystemDir & "\net.exe localgroup users", @SystemDir, @SW_HIDE, 2)
; Read all STDOUT-put
While 1
   $users &= StdoutRead($net_exe)
   If @error = -1 Then ExitLoop
WEnd
; Split the output into lines and populate an array with the lines
$user_array = StringSplit($users, @CRLF, 1)
; Step over each line
For $userStep = 1 To $user_array[0]
 ; The user names start on line 7 of the NET.EXE output (in the US English version of XP),
 ; and there's a 'completed' message afterward, so check the line # and test only names.
    If ($userStep > 6) And ($userStep < ($user_array[0] - 2)) Then
     ; $user_array[$userStep] is an user name, do whatever you need with it
        $names = $names & $user_array[$userStep] & @CRLF
    EndIf
Next
; For this example show the collected names
MsgBox(0, "Debug", $names)

[Edit: Clarified requirements.]

Edited by DaveF

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

You mean I cant use this on win 2000 if that is what you mean I dont think its much usefull cause my program is multi windows platform and how to get the output to a text file 1 user per line please even reply to get usernames with the script

http://www.autoitscript.com/forum/index.ph...059?entry121059

Share this post


Link to post
Share on other sites

Well I check the script can you guys please modify it to send the usernames to a .txt file so that I can make use of the usernames ?

You mean I cant use this on win 2000 if that is what you mean I dont think its much usefull cause my program is multi windows platform and how to get the output to a text file 1 user per line please even reply to get usernames with the script

http://www.autoitscript.com/forum/index.ph...059?entry121059

So you wrote a "Program", but... you need someone to 're-write the UDF' so it writes to a .txt file???

Read FileWriteLine() in the help file.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

So you wrote a "Program", but... you need someone to 're-write the UDF' so it writes to a .txt file???

Read FileWriteLine() in the help file.

i already did in his other post

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

i already did in his other post

8)

Mine was total sarcasim...

He asked for someone to re-write it before he even tried to do it himself is why. Either that, or he spent a total of 16 minutes trying ... (I spend longer answering post than that.)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

you just beat my ass ... on the other post

i was on it way too long

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Hello

I had the same Problem, but want to use the normal AutoIt Version (not a BETA-Version like DaveF-solution).

Therefore I tried to write a script with only cmd-Commands.

I use it on a German-WIN200-System, so you might change it .

Hope it can be useful to someone.

$Group = "Benutzer"
$first = "-------------------------------------------------------------------------------"; one line bevore user-List = last Line in Header of the text-file
$last = "Der Befehl wurde erfolgreich ausgef"; one line after user-List

$val = RunWait(@ComSpec & " /c net localgroup " & $Group & " >Benutzer.txt", "C:\", @SW_HIDE)
$file = FileOpen("C:\Benutzer.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
; Anfang der Benutzerliste suchen
While 1
    $line = FileReadLine($file)
    If @error = -1 or StringInStr($line, $first) Then ExitLoop
Wend
$Benutzer = ""
; Ende der Benutzerliste suchen
While 1
    $line = FileReadLine($file)
    If @error = -1 or StringInStr($line, $last) Then ExitLoop
    $Benutzer = $Benutzer & $line & @CRLF
Wend
FileClose($file)

MsgBox(0, $Group &" :", $Benutzer)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0