We’ve covered the excellent multi-purpose command-line tool NirCmd from Nirsoft several times before. This post talks about the new command-line switches added in the current version of NirCmd. Earlier this month, I sent a NirCmd feature request to Nir Sofer, asking to include an "elevate" switch, which should launch an application elevated (Windows Vista, Windows 7 & 2008.) Nir was kind enough to incorporate this feature in the immediate version update (v2.40). Later another update, to fix a bug I reported, v2.41 was released.
NirCmd v2.40 and higher includes the "elevate" and "elevatecmd" switches to run and execute commands with administrator rights under Windows 7/Vista/2008. Here are some useful uses of this all-in-one tool.
Of course, you’ll see the User Account Control elevation dialog when you use NirCmd with "elevate" or "elevatecmd" switches. There is no way bypassing that without disabling UAC or without relaxing UAC settings.
Launch an application elevated ("Run as Administrator")
To launch an application, say Notepad as administrator, use the following shortcut/command from the Run dialog:
or by including the full path:
If the path contains spaces, enclose the path within double-quotes. For example:
Launch an application elevated & Passing a parameter
IMO, this is probably the most needed thing in Windows 7 & Windows Vista. Windows allows you to run an application elevated by right-clicking the shortcut or executable, and choosing "Run as Administrator". However, there is no option to pass a parameter to the elevated application.
Example #1 – Edit the HOSTS file
To create a shortcut to edit the HOSTS file (you’ll have to elevate the editor in order to write to HOSTS), you use this command:

Example #2 – Register or Unregister a DLL
Want to register/unregister a DLL or OCX file quickly, without having to open the Command Prompt (as Administrator) first? Use this command from Start/Run:

Example #3 – Take Ownership of a File or Folder
To Take Ownership of a folder, use:

Followed by ICacls to assign Permissions.

(Usage of TakeOwn and ICacls for files/folders are explained in our article How to Take Ownership of a file or folder using command-line in Windows 7 and Vista.)
Example #4 – Open an Elevated Command Prompt at a Specified Folder
When you open an elevated Command Prompt using Start menu or using the Command Prompt shortcut, the default start directory is C:\Windows\System32. You use the CD command to change to a different directory. Using NirCmd, you can open an elevated Command Prompt window mentioning the start directory (say D:\Test, in this example).
The "Elevatecmd" Switch
As noted earlier, there is also an elevatecmd switch added to NirCmd. Note that this is different from the command-line switch elevate. The elevatecmd switch runs a NirCmd command (internal commands of NirCmd) with administrator rights.
Writing to the Registry using NirCmd
Writing to HKEY_LOCAL_MACHINE requires elevation, and you’ll have to use elevatecmd if you’re using NirCmd’s "regsetval" switch to write to a registry value.
This writes the data "test-data" under the registry value "Value1" in the above registry key.
Download NirCmd – Windows command line tool from NirSoft. Refer to NirCmd Command Reference Guide as well, to make the most of this tool.
Related Posts
- Fun Tip: Add “Speak” Option to the Context Menu for Text Files
- How to Disable the Empty Recycle Bin Confirmation Box in Windows 7
- Add Enhanced Shutdown Button to the Windows XP Start Menu
- Create Shortcuts to Eject and Close CD/DVD Drive
- Make Windows 7 Gadgets (Sidebar) Work With UAC Disabled
- Disable Empty Recycle Bin Confirmation in Windows XP and Vista
- Shortcut to Switch User Accounts in Windows XP and Vista – tsdiscon.exe
- Quickly Switch Your Internet Explorer Proxy Settings Using IEProxy
- Using the Desktop Background Slideshow Feature in Windows 7
- Sysinternals Desktops – Organize Your Applications on Up to Four Virtual Desktops
If you enjoyed this post, make sure you subscribe to our RSS feed! We feature Tips, Troubleshooting information, Scripts and Utilities for Microsoft Windows Operating Systems!
Prefer an E-mail subscription?




›
Most useful. He updated ProduKey on my request to support Office 2010 product keys.