Miscellaneous info regarding Vista and WDK

Just a couple issues I ran into while working with Vista and the WDK
today, and wanted to drop them somewhere public:

  1. Elevated Vista “Command Prompt” session defaults to
    %SystemRoot%\SYSTEM32, always.

I think this started in 5744, where if you right-click a Command
Prompt shortcut and select “Run as administrator” (and UAC is enabled,
and you are a member of the Administrators group), the CMD.EXE session
that gets opened has a current directory of %SystemRoot%\SYSTEM32,
rather than whichever directory the “Start in:” was set to in the
shortcut you were invoking.

Of more concern is the fact that the same is true when you right-click
and select “Run as administrator” on a batch file. e.g. If you
right-click and select “Run as administrator” on a cleanup.cmd at the
root of your source tree that intends to perform a “del *.obj /s & del
*.exe /s & del *.pdb /s”, you’ll end up trying to whack all the .EXEs
from your SYSTEM32 directory structure.

(Vista beta Feedback ID 229817, for what it’s worth.)

  1. WDK SETENV.BAT creates an environment variable named ERRORLEVEL.

The last line of SETENV.BAT attempts to ensure the errorlevel on exit
is 0 using the statement “SET ERRORLEVEL=0”. Although this does have
the immediate effect of causing errorlevel to be 0, it has nothing to
do with the “=0” in the command, and is simply because SET has
successfully performed the operation.

What it does do, as documented in the SET /? help screen, is create a
literal environment variable named “ERRORLEVEL” with a value “0”,
which overrides the dynamic pseudo-variable “ERRORLEVEL” that would
have otherwise tracked the current errorlevel.

So any batch file that runs after the WDK SETENV.BAT and tries to
check “%ERRORLEVEL%” will receive a value of “0”, instead of whatever
the real current errorlevel is. Note that the Server 2003 SP1 and
earlier DDK SETENV.BAT files did not have the “SET ERRORLEVEL=0” line
and did not create this issue.

(WDK beta Feedback ID 229037.)

Alan Adams

  1. I found that I could add a "-K cd " to the command line invoking
    cmd.exe to get it out of that directory. I had the start directory as
    %HOMEDRIVE%\ and it was ignored also. I did not notice that it was for
    elevated command windows only as I mostly use elevated for what I am
    testing. You can’t install drivers and mess with the drivers subdirectory
    without it.

“Alan Adams” wrote in message news:xxxxx@ntdev…
> Just a couple issues I ran into while working with Vista and the WDK
> today, and wanted to drop them somewhere public:
>
> 1. Elevated Vista “Command Prompt” session defaults to
> %SystemRoot%\SYSTEM32, always.
>
> I think this started in 5744, where if you right-click a Command
> Prompt shortcut and select “Run as administrator” (and UAC is enabled,
> and you are a member of the Administrators group), the CMD.EXE session
> that gets opened has a current directory of %SystemRoot%\SYSTEM32,
> rather than whichever directory the “Start in:” was set to in the
> shortcut you were invoking.
>
> Of more concern is the fact that the same is true when you right-click
> and select “Run as administrator” on a batch file. e.g. If you
> right-click and select “Run as administrator” on a cleanup.cmd at the
> root of your source tree that intends to perform a “del *.obj /s & del
> *.exe /s & del *.pdb /s”, you’ll end up trying to whack all the .EXEs
> from your SYSTEM32 directory structure.
>
> (Vista beta Feedback ID 229817, for what it’s worth.)
>
> 2. WDK SETENV.BAT creates an environment variable named ERRORLEVEL.
>
> The last line of SETENV.BAT attempts to ensure the errorlevel on exit
> is 0 using the statement “SET ERRORLEVEL=0”. Although this does have
> the immediate effect of causing errorlevel to be 0, it has nothing to
> do with the “=0” in the command, and is simply because SET has
> successfully performed the operation.
>
> What it does do, as documented in the SET /? help screen, is create a
> literal environment variable named “ERRORLEVEL” with a value “0”,
> which overrides the dynamic pseudo-variable “ERRORLEVEL” that would
> have otherwise tracked the current errorlevel.
>
> So any batch file that runs after the WDK SETENV.BAT and tries to
> check “%ERRORLEVEL%” will receive a value of “0”, instead of whatever
> the real current errorlevel is. Note that the Server 2003 SP1 and
> earlier DDK SETENV.BAT files did not have the “SET ERRORLEVEL=0” line
> and did not create this issue.
>
> (WDK beta Feedback ID 229037.)
>
> Alan Adams
>