Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Discover if a user account has been created

4 views
Skip to first unread message

Robert

unread,
Aug 11, 2006, 9:25:13 AM8/11/06
to
Hi,

I have written a batch file that installs a user account on Windows XP. The
user is then prompted to restart the PC.

Once the system restarts and the batch file is run again, I would like a
different menu to show.
I was doing it like this:
IF EXIST "%hd%:\Documents and Settings\USERACCOUNT" goto startmenureboot

The problem I am finding is if the user does not log into the account named
"USERACCOUNT" then windows does not create the directory "%hd%:\Documents
and Settings\USERACCOUNT".

Does anyone know another way to see if an account has been created? I
searched the registry for the new users, but was unable to find them.


billious

unread,
Aug 11, 2006, 9:47:17 AM8/11/06
to

"Robert" <r.f.ri...@bigpond.com> wrote in message
news:Zy%Cg.10574$rP1....@news-server.bigpond.net.au...
Not really sure what you're looking for, but the following should create a
list of a machine's users:

[1]@echo off &setlocal enabledelayedexpansion
[2]for /f "skip=4 delims=" %%i in ('net users^|find /v "The command
completed" ') do (
[3] set ynu=%%i
[4] echo !ynu:~0,25!
[5] if not "!ynu:~25,25!"=="" echo !ynu:~25,25!
[6] if not "!ynu:~50,25!"=="" echo !ynu:~50,25!
[7] )
[8] set ynu=

Now if you were to compare this list with a prior list, possibly by
directing it to a file, and sorting it then comparing with the previous
version using "fc" then you'd likely get a list of changes (new users and
deleted users)

Judicious filtering of the FC output could get you what you want.

Not really sure what you actually want to do if your create script creates
USER_ONE but the user then logs on as USER_TWO. Could you simply record the
name created in a file or in the registry and do whatever you need to from
there?

If your user signs in as USER_TWO does it really matter? Wouldn't you do
whatever it is you want to do then ext time USER_ONE signs in?


Ted Davis

unread,
Aug 11, 2006, 4:17:49 PM8/11/06
to
On Fri, 11 Aug 2006 13:25:13 GMT, "Robert" <r.f.ri...@bigpond.com>
wrote:

lsuser -a | find "username" > nul
if errorlevel 1 goto :not_created

where lsuser is from the (orphaned) AINTX toolkit - Google can tell
you where to find it.


--
T.E.D. (tda...@gearbox.maem.umr.edu)
Remove "gearbox.maem." from address - that one is dead

billious

unread,
Aug 11, 2006, 4:42:07 PM8/11/06
to

"Ted Davis" <tda...@gearbox.maem.umr.edu> wrote in message
news:d9ppd2h7ggsgnbpq4...@4ax.com...

Not reliable.

if USERNAMEONE is an established user, but USERNAME is not, FIND will report
"found" because USERNAME is a substring of USERNAMEONE.

FINDSTR /B /E "username" may work - provided the utility simply produces a
username per line - which seems logical.


Clay Calvert

unread,
Aug 11, 2006, 7:35:27 PM8/11/06
to
On Fri, 11 Aug 2006 13:25:13 GMT, "Robert" <r.f.ri...@bigpond.com>
wrote:

>Does anyone know another way to see if an account has been created? I

>searched the registry for the new users, but was unable to find them.

This may do it, as long as the account name is unique enough, that is,
as long as it wouldn't likely be a subset of another name. For
example: looking for "Fred" would be found under "Frederick".

net user | find /i "NewUserName" &&goto:startmenureboot

If you want something more reliable, let us know, though it'll cost
ya' double. ; )

Cheers,
Clay Calvert
CCal...@Zanguru.com
Replace "Z" with "L"

Ted Davis

unread,
Aug 11, 2006, 9:21:26 PM8/11/06
to

Actually, a space following the username makes FIND work properly.

The report is in this format:

User ID Full Name Last Login
------- --------- ----------
Administrator 2006/08/09 21:06:07
ASPNET ASP.NET Machine Account 1969/12/31 18:00:00
Guest 1969/12/31 18:00:00
etc.

Syntax is

Syntax: lsuser [-h hostname] {-u userid | -acnt]}
Switches
-a: list all accounts
-c: list only computer accounts
-n: list only normal user accounts
-t: list only interdomain trust accounts

--
T.E.D. (tda...@gearbox.maem.umr.edu) Remove "gearbox.maem" to get real address - that one is dead

Clay Calvert

unread,
Aug 11, 2006, 10:42:50 PM8/11/06
to
On Fri, 11 Aug 2006 21:47:17 +0800, "billious"
<billio...@hotmail.com> wrote:

>Not really sure what you're looking for, but the following should create a
>list of a machine's users:

Sorry, Billous. I hadn't read all of your response before I posted my
Net User answer. Your method is definitely more reliable.

Robert

unread,
Aug 11, 2006, 10:52:18 PM8/11/06
to

"Clay Calvert" <ccal...@Zanguru.com> wrote in message
news:kl4qd2985v6f9cq9n...@4ax.com...

Well if I'm going to pay double will it make me a cup of coffee?? :>
Seriously though, thanks. Your code works a gem!


Clay Calvert

unread,
Aug 11, 2006, 10:56:37 PM8/11/06
to
On Fri, 11 Aug 2006 13:25:13 GMT, "Robert" <r.f.ri...@bigpond.com>
wrote:

>Does anyone know another way to see if an account has been created? I

>searched the registry for the new users, but was unable to find them.

Since this is XP, this one-liner is an option.

for /f %%a in ('wmic useraccount get name') do if /i
"%%a"=="UserAccount" goto startmenureboot

Another option is that the new user should be in a group. By default
new accounts get put into the Users group, but your previous script
may have put them elsewhere. Assuming the Users group, and using a
technique Billious recently posted.

net localgroup users | findstr /i /b /e "UserAccount"

And since this is XP we can put both techniques together which isn't
limited to a particular group.

wmic useraccount get name | findstr /i /b /e "UserAccount"

Thanks

billious

unread,
Aug 12, 2006, 1:50:10 AM8/12/06
to

"Clay Calvert" <ccal...@Zanguru.com> wrote in message
news:r1gqd210ulva3h4fd...@4ax.com...

And if we want to get around the use of external utilities and wmic (not
installed on my machine - I've only half a broken toolkit, it seems...)

[1]@echo off
[2]set yur=UseridRequired
[3]set yuf=N
[4]for /f "tokens=1-3skip=4" %%i in ('net users^|find /v "The command
completed" ') do for %%I in (%%i %%j %%k) do if "%%I"=="%yur%" set yuf=Y
[5]set y

shows the User Found flag (yuf)


Noting that
[x]for /f "tokens=1-3skip=4" %%i in ('net users^|find /v "The command
completed" ') do for %%I in (%%i %%j %%k) do echo %%I

shows a neat list of users, one-to-a-line.


Clay Calvert

unread,
Aug 12, 2006, 10:15:16 AM8/12/06
to
On Sat, 12 Aug 2006 13:50:10 +0800, "billious"
<billio...@hotmail.com> wrote:

>And if we want to get around the use of external utilities and wmic (not
>installed on my machine - I've only half a broken toolkit, it seems...)

Do you have XP Home? Microsoft Technet articles imply WMIC comes with
Home, but other sites flat out say it isn't part of that OS version.

>Noting that
>[x]for /f "tokens=1-3skip=4" %%i in ('net users^|find /v "The command
>completed" ') do for %%I in (%%i %%j %%k) do echo %%I
>
>shows a neat list of users, one-to-a-line.

True, If none of the users have spaces in their name. I inherited a
network where usernames are typically in "Last First MI" format.

billious

unread,
Aug 12, 2006, 10:40:49 AM8/12/06
to

"Clay Calvert" <ccal...@Zanguru.com> wrote in message
news:8vnrd2hgkpli6i2s8...@4ax.com...

> On Sat, 12 Aug 2006 13:50:10 +0800, "billious"
> <billio...@hotmail.com> wrote:
>
>>And if we want to get around the use of external utilities and wmic (not
>>installed on my machine - I've only half a broken toolkit, it seems...)
>
> Do you have XP Home? Microsoft Technet articles imply WMIC comes with
> Home, but other sites flat out say it isn't part of that OS version.
>

Yes. XP/H. No wmic anywhere. I deliberately left the machine exactly as it
was installed by the retailer I acquired it from on the theory that I would
have a "standard" installation of what the "typical" user would have.

But TLIST works happily for me - and others reckon it's part of a
toolkit...search me (i quite enjoy it, actually...)


Clay Calvert

unread,
Aug 12, 2006, 9:25:01 PM8/12/06
to
On Sat, 12 Aug 2006 22:40:49 +0800, "billious"
<billio...@hotmail.com> wrote:

>Yes. XP/H. No wmic anywhere. I deliberately left the machine exactly as it
>was installed by the retailer I acquired it from on the theory that I would
>have a "standard" installation of what the "typical" user would have.

ISTR,, that WMIC, along with TaskList and TaskKill, was not included
with Home.

>But TLIST works happily for me - and others reckon it's part of a
>toolkit...search me (i quite enjoy it, actually...)

I don't think Tlist was ever included with any MS OS. I believe it
was renamed to TaskList for XP Pro.

Has anyone ever seen a definitive list of what commands are on what
OS? Including 64-bit versions of the OS? That sure would be handy.

Simon Sheppard are you reading this? I could help with the chart if
you'd host it, and then the chart could link to the individual command
pages.

0 new messages