Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 (exit
)if there something else to seed the process up let me know.
thank you

I'm not sure how it will go on vista but this *seems* to work on xp:
@ECHO OFF 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 )

This one is probably better:
net user "%username%"|find /i "group Memberships"|>nul find /i "administrators"&&echo Admin account||echo not admin

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

@reno
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).

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 (
cls
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! :)

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 cls color c0 title ERROR! start Admin.vbs exit /b )Using ver it won't even execute on xp.

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!!!!

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?

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|diskpartI 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....

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!

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.....

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.
Thanks
Brock
EDIT: i did a -? try that please, so -? worked on vista

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.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |