Tag Archives: as administrator

Start programs elevated from a batch file

If you use batch files to automate tasks on a Windows 10, 8, 7 or Vista computer, you have probably encountered situations when you needed to start a program elevated (a.k.a. as administrator). For example, if you want to share a folder automatically from a batch file, you would use the net share command. However, unlike many other programs that ask for the administrator’s approval, net share does not do that and simply returns the error code 5 (“access denied”) if it was started by a standard user. How to force that program to start elevated from a batch file?

Password-protect and hide personal files and folders with Folder Guard for Windows 10,8,7, and XP.
User rating: 4.7/5
Purchase or download a free trial. Read more…

That’s the purpose of the Elevate utility that we’ve created to solve such a problem. Download the Zip file, uncompress it, and inside you should find two files: Elevate.exe and Elevate64.exe. (The latter is a native 64-bit compilation, if you require that, although the regular 32-bit version, Elevate.exe, should work fine with both the 32- and 64-bit versions of Windows).

Copy the file Elevate.exe into a folder where Windows can always find it (such as C:/Windows). To use it in a batch file, just prepend the command you want to execute as administrator with the elevate command, like this:

  elevate net share ...

and it should run the command net share as administrator. Of course, it does not relieve the administrator from the duty to approve the request (unless you have enabled the quiet mode of UAC or disabled the UAC altogether).

The syntax of the Elevate command is as follows:

  elevate [-opt1] [-opt2...] [path\]file[.exe] [param1 [param2...]]

Where -optN can be one of the following:

  -?         - Display the help screen and exit
  -info      - Open the web page with more information (the web page you are reading now!) and exit
  -wait4idle - Wait for the target process to initialize before returning
  -wait4exit - Wait for the target process to finish before returning
  -noui      - Don't display any messages, even if an error occurs

After the options, the following arguments should be entered:

  file       - The file name of the program to launch elevated
  paramN     - Optional parameters (as expected by the program being launched)

For example, if for some reason you want to run Notepad as administrator, and continue only after you exit Notepad, you would use a command like this:
  elevate   -wait4exit   notepad

If you use the elevate command while being logged in to Windows as a user that does not have a split token, that is as a non-administrator or a guest user, it will ask for the administrator’s password to continue. If you use it as the true administrator (that is, if UAC is disabled, or it you’ve launched the batch file itself as administrator), then no administrator’s approval would be required and it would launch the program as usual.

Encrypt and password-protect external drives with USBCrypt software for Windows 10,8,7, and XP.
User rating: 4.7/5
Purchase or download a free trial. Read more…

Can Elevate.exe be used on a Windows XP or Windows 2000 computer, even though they do not have UAC or users with the split tokens? Yes, it can! In such a case, if the batch file is executed by the administrator, then Elevate.exe runs the program as usual, without requiring any additional approval. If run by a restricted user, Elevate.exe has the same effect as the Run As command of Windows XP/2000: it gives the user an option to enter a different user’s credentials to lunch the program.

The return code of the elevate command depends on the result of its execution and whether you have specified the -wait4exit option or not. If the -wait4exit option is NOT specified, then elevate returns code 0 if it started the target process successfully, or an error code as reported by Windows. For example, if Windows could not find the target file, it usually returns code 2. If the file was found, but the administrator did not approve the request to start the program elevated, the return code is 5. And so on.

However, if you have specified the -wait4exit option on the command line, then if the target process was started successfully, the elevate command would wait for it to finish and return the exit code from that process. The returned value in such a case depends on the program being launched be the elevate command. As with other commands, you can access the return code in a batch file via the ERRORLEVEL variable.

It’s FREE. For Windows 2000 and later. License…

Download Elevate.zip

NOTE: There is a known Windows problem: you cannot start a batch file elevated while passing arguments with quotes to it. A possible workaround is not to use elevate.exe to run a batch file elevated. Instead, run the batch file itself as the standard user, and put the elevate.exe command inside of the batch file to run whatever program you need to run elevated.

If you want to link to this article, you can use this HTML code: <a href=”http://www.winability.com/elevate/”>How to start programs elevated from a batch file</a>

Read more

Software Discounts

How to make elevated programs recognize network drives

Take control of your files and folders with AB Commander file manager for Windows 10,8,7,Vista, and XP.
User rating: 4.8/5
Purchase or download a free trial. Read more…

One of the useful tools that Windows offers is the ability to assign drive letters to the network locations. You can use the Map Network Drive command of Windows Explorer or AB Commander to create the network drives. After a network drive has been created, you can use it just like any other drive: browse its contents, copy file to or from it, and so on.

A problem may occur, however, if you use Windows Vista or Windows 7 and need to access the network drive from an application that runs elevated (a.k.a. as administrator). For example, when you run AB Commander as usual, it runs as the standard user, and displays any network drive that you might have created, for example:

AB Commander shows a network drive in the Computer folder
enlarge the image

However, unlike Windows Explorer that always runs as a standard user, AB Commander offers you an option to run it as administrator. (You can do it by using the Restart as Administrator command on the Tools menu.) If you restart AB Commander as administrator, you might be surprised to see no network drive in its window:

Why is the network drive missing?
enlarge the image

(You can recognize that AB Commander is running as administrator by the presence of the Administrator label in its title bar).

To understand why the network drive is not visible to the programs running as administrator, we have to consider how Windows handles the standard and administrator user access internally. In simple terms, when UAC (User Account Control) is enabled, Windows creates a split personality for your user account: one with the standard user’s access rights to do the the regular tasks, and another one with the full administrative access to the system. When you log in to the computer, Windows tries hard to create the impression that these two personalities are the same: they share the login name and password, the desktop and documents, settings and preferences, and so on. However, when it comes to mapping the network drives, Windows prefers to treat them as separate accounts (for security reasons). That’s why the network drives created when you wear the hat of the standard user do not automatically become available when you put the administrator’s hat on. This Microsoft article explains it all in detail.

Password-protect and hide personal files and folders with Folder Guard for Windows 10,8,7, and XP.
User rating: 4.7/5
Purchase or download a free trial. Read more…

Such behavior is rather counter-productive: after all, the administrator account is supposed have more access to the system, it’s supposed to be able to see and do all things that are available to the standard user, plus some more. Why can’t it see the network drive created by the standard user?

In any case, there is a way to force Windows to make the network drives available to both the standard and administrator accounts automatically. All you need to do is run Registry Editor (regedit.exe), locate the following key:


and create a new DWORD entry with the name EnableLinkedConnections and value 1:

The value EnableLinkedConnections in the registry
enlarge the image

Caution: If you are not very experienced with Registry Editor, please be extra careful: it’s a powerful tool that can do a lot of damage to your system if used carelessly.

After you’ve added the EnableLinkedConnections value to the Registry, restart the computer, and after that the network drives you create should become available to the elevated applications, as well.

Happy networking!

Update for Windows 8

It appears that the EnableLinkedConnections setting is not always working correctly on Windows 8: if a standard user has created a mapped network drive pointing to a subfolder of a shared folder (for example, drive Z: connected to //server/share/subfolder), then the elevated user will see the drive Z:, but it will be pointing to the root share, //server/share/, not to the subfolder.

Take control of your files and folders with AB Commander file manager for Windows 10,8,7,Vista, and XP.
User rating: 4.8/5
Purchase or download a free trial. Read more…

If this error creates a problem for you, then it’s better not to use the EnableLinkedConnections registry fix at all. Instead, just create the mapped network drive twice: first time using a standard user’s account, and the second time using an administrator account. Sure, it’s twice the work, but it should work correctly in all situations.

Good luck!

If you want to link to this article, you can use this HTML code: <a href=”http://www.winability.com/how-to-make-elevated-programs-recognize-network-drives/”>How to make elevated programs recognize network drives</a>

More information

How to disable hibernation with AB Commander

Take control of your files and folders with AB Commander file manager for Windows 10,8,7,Vista, and XP.
User rating: 4.8/5
Purchase or download a free trial. Read more…

If you used Space Investigator to analyze the contents of your C: drive, you probably couldn’t help but notice a rather large file named hiberfil.sys in the root folder. This file is used by Windows to remember the state of your computer when you hibernate it.

OK, but what if you never hibernate your computer? (In most cases sleep is what it does, which is not the same as hibernate). The size of this file is about the same as the size of the RAM your computer has, it would be nice to delete the file and allow other files use that space. However, if you attempt to delete the file directly (using Space Investigator, AB Commander, or Windows Explorer), you might be surprised to discover that Windows does not let you delete it, even if you use your full powers of the administrator.

To solve this problem, you need to disable hibernation: when you do that, Windows deletes the hiberfil.sys file for you. Windows XP offers a special button in its Control Panel that you can use to disable or enable hibernation. However, Windows Vista and Windows 7 for some reason don’t offer a similar command. Fortunately, there is a way to disable or enable hibernation: by running the powercfg.exe command with the administrative privileges and the appropriate command line switches, as described in this Microsoft article.

If you have AB Commander, you might be surprised to know that it can be used to achieve the same result especially easy. To do this, you need to know three things:

  1. AB Commander lets you launch any command by entering it into its command bar (at the bottom of AB Commander window).
  2. You can start a command elevated (a.k.a “As Administrator”) by pressing the Ctrl+Shift+Enter keys.
  3. You have to know the correct command (and any parameters, if applicable) to run to perform the specific task you want.

For turning the hibernation on and off, the above mentioned Microsoft article gives us all information we need:

To disable hibernation, run this command:

powercfg.exe /hibernate off

To enable hibernation back, run this command:

powercfg.exe /hibernate on

Remember to launch these commands “As Administrator”, or they won’t work:

Press Ctrl+Shift+Enter to run a command As Administrator with AB Commander
enlarge the image

Happy computing!

More information