Home > Articles > Programming > Windows Programming

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

But I Hate the Command Prompt!

Many developers are comfortable using the command prompt to get tasks done. For example, I much prefer netsh for configuring my IP settings over messing around with the GUI. But for some tasks in Windows, using a GUI is pretty much unavoidable. For example, the command-line ACL editor, [2] cacls, doesn't correctly propagate inheritable ACEs (in English this means it can screw up your file system ACLs over time), so I prefer to use the GUI to modify my file system ACLs. You really need a special Explorer window for performing administrative tasks. Unfortunately, simply typing explorer from your admin command prompt will very likely not do what you want. explorer.exe normally uses a single process, and when the new process starts it simply sends a message to the earlier instance and terminates. This means that the new window you get is not running in a different security context. There is an option to force every Explorer window to run in its own process, however I've never managed to get it to solve this problem. On the other hand, there is another facade that you can use to start an Explorer window in its own process: iexplore.exe. If you type \program files\internet explorer\iexplore.exe from your admin command prompt, the new Explorer window will run in its own process, with admin privileges. If you type "Control Panel" into the address bar, you'll quickly see that there's not much you can't do from here. One odd thing that I've noticed, and that you should watch out for, is that this copy of Explorer won't refresh things automatically. For example, if you create a new file, it might not show up in your admin Explorer window. Don't fret, though, just press F5 to force a refresh.

Take a close look at this new window. You likely can't distinguish the admin Explorer window from any other Explorer window, and you will make a royal mess of your system if you leave things this way. For example, you might accidentally create a directory with your admin Explorer when you really intend to have your normal account own and manage that directory. Take it from my own painful experience: You don't want to stop here. The trick is to use per-user customization to make the admin window stand out so you can't miss it. There's an utterly cool way to do this, too. Skin it! Run regedit from your admin command prompt and drill down to the following registry key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar. Add a named string value, BackBitmap, whose value is the path to a bitmap file. At the moment, I use a boring little red 32×32-pixel bitmap, but you can get more fancy if you like. Since Explorer tiles this all over the toolbar, this means my admin Explorer ends up with a bright red toolbar that I can't miss. The Toolbar key has a sibling called Main. Surf over there and add a named string value, Window Title. Set this to "ADMIN" or whatever you like. This will help you see which window is which when you press Alt-Tab repeatedly to switch between programs.

  • + Share This
  • 🔖 Save To Your Account