"Matt Hickman" <> wrote ...
> Using quotes around "%0" caused me problems as well. (If you allow
> the "FOR" command to echo, you wll see that "%0" is implemented with
> quotes already)
Actually, the quote marks you see there are inserted by Explorer. When you
run the batch file from Explorer it internally puts quote marks around the
string, I guess to deal with path names containing spaces. If you run the
batch file from a command prompt, %0 is plain unadorned, wthout quotes.
> I am not sure that is the case. Do a "set" at the command line after
> you start cmd.exe selecting "Run as administrator", When I did, I
> found I was in the context of my own ID:
> ...
> USERNAME=Matt
> USERPROFILE=F:\Users\Matt
Right. Actually, it gets more complicated :-) and I kind of glossed over the
complexity (didn't want to drown the post with superfluous information).
If your Administrator account is explicitly enabled (ie, the user with SID
S-1-5-21-2621085430-3789323321-3897899910-500) and you "Run as
Administrator" then you get the environment of the Administrator. In this
case you really do see:
USERNAME=administrator
USERPROFILE=C:\Users\administrator
etc
By default in Vista, the built-in Administrator account is disabled, and the
"user" you first create at setup is a member of the Administrator's group.
Except when you log in as this user, they don't get a full administrative
security token straight way - Vista uses the concept of the "split token".
When you elevate, either via Run As" or via an internal EXE manifest, then
you get a full administrative token for the particular operation you
elevated for. Exactly what bits of the user context remain the same and
which vary is, I will concede, a bit mixed up. You'll probably find, for
example, that any drives you had mapped as a "regular user" no longer work
in the elevated context; because drive mappings aren't carried across to the
elevated context (I shouldn't say "environment" because the "User
Enviroment" strings are only one partial aspect of the user's total
context).
Some detailed info (admittedly a bit mind-numbing) here:
http://msdn2.microsoft.com/en-us/library/bb530410.aspx
> I explicitly hope that MS developers pay more attention to down-level/
> cross-level compatibility -- especially when there is no apparent
> reason to change system behavior.
Well, there *was* a reason to change the behaviour - security. The behaviour
you're seeing is a side effect of improved security in Vista. Microsoft
certainly would not have bothered making these particular changes, unless
there was a good reason (granted, in Vista they did seem to dick around with
Explorer, Control Panel, etc, on a mere whim. But CMD is old, gnarly code,
which no-one touches if they can help it). The security benefits may not be
immediately obvious, but then, most of security is a subtle cat-n-mouse game
which moved beyond the obvious, comon-sense stage, sometime around 1996.
But wait! There's good news. CMD and batch files are bing superceded by
PowerShell:
http://www.microsoft.com/windowsserv...l/default.mspx.
PowerShell is an entirely new comand processor and scritping language,
designed from scratch. It is available for Vista and will be installed by
default in Windows Server 2008 and Windows 7. CMD will still be there for
legacy batch files; but PowerShell gives you vastly more control (in a
consistent, understandable, predicable, composible manner) than CMD.
Cheers,
--
Andrew McLaren
amclar (at) optusnet dot com dot au