Question

I have a batch file where I want to run some commands, but not all of them as administrator. I do not want to run the command prompt as administrator or run the entire batch job as administrator. An example of a command that I want to run as administrator is:

appcmd.exe recycle apppool \apppool.name -DefaultApp

Appcmd is the command for managing IIS 7, and this example I want to recycle an App Pool.
I have tried:

runas /profile /user:MYPC\administrator "appcmd.exe recycle apppool \apppool.name -DefaultApp"

I get a 1326: Logon failure: unknown user or bad password, but I know the user and password exist. Any suggestions as to how I can do this?

Was it helpful?

Solution

I found that running runas without the /profile parameter worked fine. But if you must run it with /profile then you could execute this command just prior:

runas /profile /user:MYPC\administrator "cmd"

Which will unfortunately prompt you twice.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top