Why does RUNAS command work but PSEXEC doesn't in this case?

5,166

What am I missing?

You need to run the command as the system account. That requires you to add -s to your commmand

Your command would then be:

psexec -s \\ServerBoxMachine -u mydomain\myusername -p MyPassword1 iisreset

PsExec v2.2

Additional Source

Share:
5,166
gardenofwine
Author by

gardenofwine

Updated on September 18, 2022

Comments

  • gardenofwine
    gardenofwine over 1 year

    When I try to restart a remove IIS, I run:

    runas /netonly /user:mydomain\myusername "iisreset ServerBoxMachine"
    

    It asks me for a password and then the command is ran successfully. However, I use PSEXEC as below, it doesn't work:

    psexec \\ServerBoxMachine -u mydomain\myusername -p MyPassword1 iisreset
    

    It comes back with Access denied, you must be an administrator of the remote computer to use this command.. So I ran gpresult /r to see if my login is part of the relevant security group and sure enough, it's part of the BUILTIN\Administrators group. So theoretically, it should work.

    What am I missing?

    • Frank Thomas
      Frank Thomas over 6 years
      have you confirmed that you can remote with psexec by executing cmd with it?
    • gardenofwine
      gardenofwine over 6 years
      @FrankThomas Yes, I did. I actually found the solution. See the P.S. in my post.
    • Mokubai
      Mokubai over 6 years
      If you found a solution it should be in an answer, not your question.
  • I say Reinstate Monica
    I say Reinstate Monica about 6 years
    This executes the command in the context of the remote machine's System account. That's not necessary when executing this locally...and idea why it's required remotely?
  • Ramhound
    Ramhound about 6 years
    @TwistyImpersonator The author determined that was their solution. Check the revision of the question. Only made what was an answer, submitted as an edit to a question, into an actual answer
  • I say Reinstate Monica
    I say Reinstate Monica about 6 years
    Bummer. I don't doubt it works. I was just hoping to learn something useful. (Don't worry, I won't shoot the messenger.)