Computing.Net > Forums > Programming > Question on this command

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Question on this command

Reply to Message Icon

Name: brockey01
Date: May 20, 2009 at 21:28:24 Pacific
OS: Windows XP
CPU/Ram: 1024
Product: Hewlett-packard / Sd2100
Subcategory: Batch
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: May 20, 2009 at 23:36:02 Pacific
Reply:

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
)


0

Response Number 2
Name: Judago
Date: May 21, 2009 at 00:00:05 Pacific
Reply:

This one is probably better:

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


0

Response Number 3
Name: reno
Date: May 21, 2009 at 06:47:13 Pacific
Reply:

nice one liner code

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


0

Response Number 4
Name: Judago
Date: May 21, 2009 at 16:30:39 Pacific
Reply:

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


0

Response Number 5
Name: brockey01
Date: May 23, 2009 at 23:29:13 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: Judago
Date: May 23, 2009 at 23:48:35 Pacific
Reply:

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.


0

Response Number 7
Name: brockey01
Date: May 24, 2009 at 22:56:13 Pacific
Reply:

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


0

Response Number 8
Name: Judago
Date: May 25, 2009 at 00:25:59 Pacific
Reply:

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?


0

Response Number 9
Name: brockey01
Date: May 25, 2009 at 00:41:15 Pacific
Reply:

hmm i dont know could work, got any suggestions?


0

Response Number 10
Name: Judago
Date: May 25, 2009 at 01:55:21 Pacific
Reply:

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


0

Response Number 11
Name: brockey01
Date: May 25, 2009 at 20:39:10 Pacific
Reply:

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!


0

Response Number 12
Name: Judago
Date: May 25, 2009 at 20:55:05 Pacific
Reply:

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


0

Response Number 13
Name: brockey01
Date: May 25, 2009 at 21:22:17 Pacific
Reply:

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


0

Response Number 14
Name: Judago
Date: May 25, 2009 at 21:47:54 Pacific
Reply:

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.


0

Response Number 15
Name: brockey01
Date: May 26, 2009 at 14:07:14 Pacific
Reply:

Yes it did, Thank you again for your time and work with this.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Question on this command

help with question www.computing.net/answers/programming/help-with-question/8317.html

Help on Borland command line tools www.computing.net/answers/programming/help-on-borland-command-line-tools/6863.html

Question on structures www.computing.net/answers/programming/question-on-structures/7400.html