in reply to Does $> have a little extra magic?

$> and $< are unix UID RID's. Windows doesnt exactly use the same system. I am not too familiar with the WIN32 modules. But let me see if there is a way to get the admin info by other means.
#!/usr/bin/perl my $pid = open (PS, "net user $ENV{USERNAME}|") || die "Can't Execute" +; while (<PS>){ $root = 1 if (/^Local Group Memberships/ && /\*Administrators/); } print "user is admin" if $root;

This uses the net command within windows services. Gets your user information. if your local group includes admin then it sets root to 1. Whether this helps you or not it may be useful if you are designing group specific software

Replies are listed 'Best First'.
Re^2: Does $> have a little extra magic?
by chargrill (Parson) on Mar 21, 2006 at 16:50 UTC

    Having since arrived at the office,

    $root = eval "use Win32" || ! $@ ? Win32::IsAdminUser() ? 1 : 0 : $> = += 0 ? 1 : 0;

    ... has all appearances of working as expected. Win32::IsAdminUser() seems to report what I'm interested in. I guess I'm just puzzled by perl's adherance to unix-y properties (with regards to $>) when run on Windows.



    --chargrill
    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

      You have to admit - that's kinda ugly ;-)

      # Try Windows first. my $root = eval { require Win32; Win32::IsAdminUser(); }; # If that didn't work, try Unix. $root = $> == 0 if $@;
      Also has the advantage of avoiding eval STR. String evals are nasty and to be avoided where possible.

        Using $@ to decide whether eval failed is error prone, in my experience. Instead I end my 'eval' expression with "; 1" and check whether eval returns a true value or not:

        my $root= eval { require Win32; 1 } ? Win32::IsAdminUser() : $> == 0;

        - tye