Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

A Sample Setup for a VS.NET Developer

To be productive, it's important to have an admin command prompt ready at all times, so I find it useful to automate as much as possible the process of getting one. I suggest creating a couple of batch files to help (I call mine adminShell.cmd and adminShellInit.cmd). Use the first batch file to house two runas commands, the first initializing a local admin shell and the second creating a new shell that has your domain credentials. Here's my adminShell.cmd. Note that XYZZY\la is the local admin account on my box (I always rename the Administrator account to annoy potential hackers).

REM adminShell.cmd
REM Starts a command prompt running as the local admin (XYZZY\la)
REM but with my domain credentials (ps\kbrown)
runas /u:xyzzy\la "runas /netonly /u:ps\kbrown \"cmd /K c:\etc\utils\adminShellInit.cmd\""

I've heard reports that, on some systems, allowing the first command prompt to exit results in painting problems for applications. I've not personally run into this, but if you do you might find knowledge base article 322906 helpful. In short, the workaround is to modify the batch file just shown so that the second reference to runas becomes cmd /K runas.

My second batch file initializes the environment and makes the command prompt stand out by changing its color to black on red and setting an obvious title. Because the current directory of the admin prompt will be SYSTEM32, I change to a less dangerous directory by default. I don't want to accidentally modify anything in there!

REM adminShellInit.cmd
@echo off
title *** ADMIN ***
color C0
call  "c:\program files\microsoft visual studio .net 2003\common7\tools\vsvars32.bat"
cd "%USERPROFILE%\My Documents"
cls

Figure 9.2 shows what my desktop looks like with my normal and admin command prompts running.

09fig02.gifFigure 9.2 An admin secondary logon

  • + Share This
  • 🔖 Save To Your Account