Question on this command

Hewlett-packard / Sd2100
May 20, 2009 at 21:28:24
Specs: Windows XP, 1024
Why does this command take along time to check the rights to vista , i use it in my batch file to check admin right under xp or vista but in xp it passes vary fast but in vista to take a min and half to check

heres the code

:for /f "delims=" %%a in ('2^>^&1 ^>nul defrag -a %systemdrive%') do set notadmin=%%a
:if defined notadmin (


if there something else to seed the process up let me know.

thank you

See More: Question on this command

Report •

May 20, 2009 at 23:36:02
I'm not sure how it will go on vista but this *seems* to work on xp:

for /f "tokens=4" %%a in ('net user "%username%"^|find /i "Local Group Memberships"') do (
	if /i "%%a"=="*Administrators" echo The current user has admin privileges

Report •

May 21, 2009 at 00:00:05
This one is probably better:

net user "%username%"|find /i "group Memberships"|>nul find /i "administrators"&&echo Admin account||echo not admin

Report •

May 21, 2009 at 06:47:13
nice one liner code

could it be simplify to:
net user %user%|>nul find/i "*Administrators"&& echo yes|| echo no

Report •

Related Solutions

May 21, 2009 at 16:30:39

It probably could be simplified that way, I was just trying to kill off the possibility that the users comment contained "*administrators", not likely but a possibility. Also I used %username% because it is a system variable that expands to the current username(or at least it does on xp).

Report •

May 23, 2009 at 23:29:13
Thank you all,

a piece from my batch:

@echo onclick=msgbox ("Please Run as Administrator!",16,"ERROR!") >admin.vbs

for /f "delims=" %%a in ('2^>^&1 ^>nul defrag -a %Systemdrive%') do set notadmin=%%a
if defined notadmin (
color c0
title ERROR!

start C:\Cleanup\admin.vbs
exit /b

I use that code when a person running vista opens it it will error stating please run as administrator, making them right click and run as administrator, now when doing that it seems to take along time.

the codes your post above is not what im really looking. BUT they are nice to have if i need them, so i must say thank you for your hard work. !

but i need something that will if open make the batch close and say please run as administrator makeing them Right Click and selct Run as Administrator.

use my code make a batch and you will see .

in XP the code is somewhat useless and only geared toward vista.

Thank you again all! :)

Report •

May 23, 2009 at 23:48:35
I though the problem was that defrag actually did something
(i.e analyzing) causing delay, the script could easily be
adapted avoiding this:

ver|>nul find "n 5"||net user "%username%"|find /i "group Memberships"|>nul find /i "administrators"|| (
@echo onclick=msgbox ^("Please Run as Administrator!",16,"ERROR!"^) >admin.vbs
color c0
title ERROR!
start Admin.vbs
exit /b

Using ver it won't even execute on xp.

Report •

May 24, 2009 at 22:56:13
True but i was using to to check and see if they right clicked and selected run as administrator. that allows the batch to process though.

i need a script that will check to see if they selected run as administrator.

Thank you for your help!!!!

Report •

May 25, 2009 at 00:25:59
Now I understand -> Vista ignorant.

I've only just though of it and have to look at something else first but what about a similar process to the defrag test using cacls to attempt to change the permissions of a system file?

Report •

May 25, 2009 at 00:41:15
hmm i dont know could work, got any suggestions?

Report •

May 25, 2009 at 01:55:21
On closer inspection it doesn't seem to be such a good idea....

All you need to do is find a command that bottoms out without admin privileges that doesn't actually do much if you do, a good one to try is:

echo exit|diskpart

I don't believe that there is much chance that this would be allowed to standard users(unlike defrag), give it a try and see how it goes.... On xp it errors out and leaves an errorlevel set to 4 for standard users and does little but print a message for admins, might be just what your looking for depending on how vista treats it....

Report •

May 25, 2009 at 20:39:10
I tried it works but the damn UAC keeps popping.

seems like the defrag version works but i hate the wait but it does what i need to it to. no UAC popup and checks if the user did select run as administrator.

but thank you again!

Report •

May 25, 2009 at 20:55:05
One last thought, the -a switch on the defrag command try removing it, on xp it does nothing without a drive letter or mount point, perhaps it analyzes all of the disks on vista...... and *maybe* with out it it might work....

I don't know what to believe anymore...

Edit: You might even want to try the /? help switch, xp doesn't even allow the help switch, so obviously vista will.....

Report •

May 25, 2009 at 21:22:17
hmm that /? worked vary well, and ran as admin right away, do me a favor and test that command i posted in my first post

instead of defrag -a

try this for me. with the /? see if that works on xp.


EDIT: i did a -? try that please, so -? worked on vista

Report •

May 25, 2009 at 21:47:54
Yep it does the same thing...

Does this mean the problem is finally solved?

All that command really does is test if the command in the for loop printed text using stand error, so if vista's defrag is printing to stderr using the help switch (both /? and -? work the same for xp's defrag and I assume vista's too) it should all be good.

Report •

May 26, 2009 at 14:07:14
Yes it did, Thank you again for your time and work with this.

Report •

Ask Question