NirCmd Elevate Switch Added – Some Useful Uses

We’ve covered the excellent multi-purpose command-line tool NirCmd from Nirsoft earlier. 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:

nircmd elevate notepad.exe

or by including the full path:

nircmd elevate c:\windows\system32\notepad.exe

If the path contains spaces, enclose the path within double-quotes. For example:

nircmd elevate "C:\Program Files\Windows NT\Accessories\wordpad.exe"

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:

nircmd elevate Notepad "C:\Windows\System32\Drivers\Etc\HOSTS"

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:

nircmd elevate regsvr32 c:\windows\system32\jscript.dll

Example #3 – Take Ownership of a File or Folder

To Take Ownership of a folder, use:

NirCmd elevate cmd /k takeown /f <foldername> /r /d y



Followed by ICacls to assign Permissions.

NirCmd elevate cmd /k icacls <foldername> /grant administrators:F /T

(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.)

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).

nircmd elevate cmd.exe /k cd /d "D:\Test"

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.

NirCmd elevatecmd regsetval sz "HKLM\Software\Test" "Value1" "test-data"

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.


One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

1 thought on “NirCmd Elevate Switch Added – Some Useful Uses”

Comments are closed.