How to call a program to be run with admin privileges but under the same user (Windows Command Prompt)

2

I need to invoke a program with admin privileges from command prompt. it should prompt to the user an alert such as:

enter image description here

I found many answers like:

runas.exe /user:administrator %~dp0\MY_PROGRAM.BAT

But it does not help me, because that in this way, the program run under Administrator account while I need this program to be run under the same user that invokes my script.

I'm working on Win7/8 and Server 2008 R2

elady

Posted 2014-09-11T10:05:25.530

Reputation: 275

How are you trying to launch the software from the command prompt whilst logged in as the user? UAC prompt will pop up for the user then ask for credentials to make changes however the actual software will still run as the end user... – CharlesH – 2014-09-11T10:12:37.187

I didn't get you, why UAC prompt will pop up for the user? Let's say that the script & the program are stored in a local shared folder (e.g. C:\Shared_Folder) – elady – 2014-09-11T10:44:56.027

Ok sorry let me approach this another way. How are you going to be invoking this program? – CharlesH – 2014-09-11T10:48:24.030

I'm just calling the program directly from the script – elady – 2014-09-11T11:41:44.233

More high level though, are in front of the pc running the script or does it run at login or as a scheduled task, etc? – CharlesH – 2014-09-11T11:42:31.907

The user runs the script, and the script calls the program. – elady – 2014-09-11T12:26:55.920

Answers

1

Sudo for Windows lauches configured programs with elevated privileges while keeping the current user environment. So the program will be run with full admin privileges but under the current user. IIRC it installs a window service (admin required for installation) which does the heavy lifting. It does not seem to be developed anymore but works fine on Windows 7, 8 and 8.1.

Vamsi

Posted 2014-09-11T10:05:25.530

Reputation: 806

This is like the "Run as Administrator" of the item menu. I'm asking how to do the same, but from the command prompt, rather than the GUI interface. – elady – 2014-09-11T12:25:23.783

There is also a command line interface. Just run sudo your-program in your batch file or command prompt. It will then prompt you for the password in the command line, but you can configure it to cache authentication or even supply the password as an argument (in plain text though). Note that sudo.exe is an executable that is installed. The context menu is just a wrapper for the exe. – Vamsi – 2014-09-11T12:36:33.457