3

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

6
  • 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
    Sep 11, 2014 at 10:12
  • 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
    Sep 11, 2014 at 10:44
  • Ok sorry let me approach this another way. How are you going to be invoking this program?
    – CharlesH
    Sep 11, 2014 at 10:48
  • I'm just calling the program directly from the script
    – elady
    Sep 11, 2014 at 11:41
  • 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
    Sep 11, 2014 at 11:42

1 Answer 1

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.

2
  • 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
    Sep 11, 2014 at 12:25
  • 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
    Sep 11, 2014 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .