Cynosure.X International LLC

:

Add Comment | Related Links | TrackBack
Related Content

Run As Administrator (GPL)

"RunAsAdministrator.cmd" is Windows batch program that elevates a script or program to admin level. This script does the same thing as you right-clicking on a program and select "Run as administrator", except it allows you to do it from the command-line or within a batch script.

"RunAsAdministrator.cmd" takes advantage of the following batch files. They are also available on this web site. So to use "RunAsAdministrator.cmd", you'll have to download these other batch scripts, if you don't already have them.

GetTempPathName.bat
HasAdminPrivilege.cmd
SetNumberOfArguments.bat
SetVariableToOutput.bat

"RunAsAdministrator.cmd" is distributed as executable source code under the GNU General Public License. Please see the license agreement elsewhere on this site. If you make changes to this batch file, please feel free to upload it back here to share it with others.

Usage

  "RunAsAdministrator.cmd" "program" [ "arg 1" . . . "arg N" ]

Chieh Cheng
Sat, 06 Dec 2014 05:33:47 +0300

Looks like I forgot to attach the batch script. It is now attached below.

Attached File: RunAsAdministrator.cmd (1 KB)

Chieh Cheng
Sat, 25 Jul 2015 23:33:56 +0400

Found a single character typo that causes this script to fail in obscure cases. I've updated the script. New version is attached below.

Attached File: 1 - RunAsAdministrator.cmd (1 KB)

Chieh Cheng
Fri, 24 Aug 2018 02:05:05 -0700

While fixing the single character typo bug, I saw a possible improvement to the script. So I decided to implement it. Now the script takes a new optional argument, allowing you to specify the window mode for the elevated command execution. The new version of the script is attached. And the following is the new usage page.

Usage

"RunAsAdministrator.cmd" [ /w mode ] "program" [ "arg 1" . . . "arg N" ]

Window Modes:
hide = 0
normal = 1
min = 2
max = 3
restore = 4
current = 5
min/inactive = 7
default = 10

Windows mode has no effect if privilege is already elevated.

Examples

The following runs the command in a hidden window:

  > RunAsAdministrator.cmd /w 0 echo hello

The following runs the command in maximized window:

  > RunAsAdministrator.cmd /w 3 echo hello

Attached File: 2 - RunAsAdministrator.cmd (3 KB)

Chieh Cheng
Sat, 25 Aug 2018 00:34:51 -0700

Made two minor enhancement. One is adding debug functionality. Two is making it more concurrent with other instances. New version is attached below.

Attached File: 3 - RunAsAdministrator.cmd (3 KB)

Chieh Cheng
Sun, 26 Aug 2018 02:46:07 -0700

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

TrackBack

TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.

Send Ping | TrackBack URL | Spam Control

Title: Has Administrator Privilege (GPL)
Weblog: Cynosure.X International
Excerpt: "HasAdminPrivilege.cmd" is a Windows batch program that can helps you determine whether your script is running as administrator or not. "HasAdminPrivilege.cmd" outputs 1 (for true) when it is running with admin privilege. Otherwise, it outputs 0 (for false). "HasAdminPrivilege.cmd" takes advantage o . . .
Tracked: Sat, 06 Dec 2014 05:45:52 +0300

Add Comment

Spam Control | * indicates required field
Your Name: *
E-mail:
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 1 + 6?
Click button only once, please!

Messages, files, and images copyright by respective owners.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

28 Users Online

Hacking Digital Cameras
Fun for Photographers



Amazon Associate

Copyright © 1996 - 2018. All Rights Reserved.