2

I have remotely connected to a Windows 7 computer via psexec and am running a remote command prompt on the Windows 7 computer. The command I am trying to execute requires that it be run in an elevated command prompt for it to work.

How do I get to an elevated command prompt if my starting point is a command prompt that is not elevated and I don't have access to the GUI?

2
  • Are there any switches in the latest versions of PSEXEC for choosing an elevated context?
    – nray
    Oct 25, 2009 at 17:58
  • No-------------
    – Izzy
    Oct 25, 2009 at 21:09

4 Answers 4

5

I've wrestled with this in the past, and it can't be done. Only way is to create a scheduled task that you then execute from your cmd session.

4
  • So are you saying that from the command line I can create a scheduled task that will execute under elevated privileges and then manually execute that scheduled task from my current underprivileged command prompt? Oct 25, 2009 at 17:47
  • Yes. Silly isn't it. Make sure you a) select "run with highest privs" and b) don't set a run time for the task. Then execute using schtasks /run
    – Izzy
    Oct 25, 2009 at 17:48
  • Can I create the task from the command prompt itself or do I have to create the task trough the GUI to get the elevated privileges? Oct 25, 2009 at 17:53
  • Yes using schtasks Oct 25, 2009 at 18:58
1

Seems hard to do after you've connected. Microsoft has a Powertoy to install to force elevation in a command, but as the prompt needs to be displayed and accepted I'm at a loss how that would work in your scenario (I guess not at all).

elevate cmd.exe

However, using say Powershell remoting instead would probably solve this as it will elevate when connecting remotely afaik. I guess psexec should be able to implement this kind of support as well - but you'd have to request an elevated context on connection - not afterwards.

Of course, the scheduled tasks trick does seem to work... ^^

0

In vista you could disable UAC from the cmdline using a script. We used this to disable UAC, reboot the computer, run our scripts/installs, and then enable UAC again before giving the computer a last restart.

I bet Win7 has a similar way of doing this, although I think the command has changed. Thay are just registry settings, though, so it would be fairly easy to script them directly in the registry.

As long as your script is reboot-aware this shouldn't be too hard to implement...

-Trond

0

PSExec has options to specify a username and password, which is required when running a task on a remote computer that requires access to network resources (otherwise PSExec is limited to local resources). Connecting with the appropriate account should give you the access you require: try psexec -u < username > -p

Additionally, the runas command runs a command (even cmd) with the specified privileges. I don't know how nicely it plays with PSExec due to the issue mentioned above, but use the following syntax to elevate priveleges:

runas /user:<domain>\<username> cmd

You will be prompted for a password; if typed correctly, you will be running in a new command prompt with the privileges of the specified account. The privileges may be limited by the privileges PSExec is running with, though.

2
  • 1
    That isn't the same as the elevated token. You can be domain admin, and still not have the elevated token in a command window. May 25, 2013 at 4:04
  • 2
    what about the -h argument of psexec? davidovitz.blogspot.mx/2010/07/…
    – user236697
    Aug 8, 2014 at 6:43

You must log in to answer this question.

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