I'm trying writing a batch file that needs to run some commands using a local admin account (start/stop a service) and some commands using the logged in user (copy files from the user directory) and I'm encountering problems. I have tried the following commands:
runas with /savecred
runas /user:(PC name)\(admin username) /savecred "net stop \"(service name)\""
runas /user:(PC name)\(admin username) /savecred "sc stop \"(service name)\""
When using /savecred
I am not prompted for a password. Instead a command prompt window briefly flashes up and disappears. I am not able to tell what is in this window. The service is not stopped.
runas without /savecred
runas /user:(PC name)\(admin username) "net stop \"(service name)\""
runas /user:(PC name)\(admin username) "sc stop \"(service name)\""
These commands do prompt me for a password but then exhibit the same behaviour as the above commands - a command prompt window briefly pops up and the service is not stopped.
Ideally I would like to save the password for the session as I will need to run more commands with the details.
Is this possible and if so, what am I doing wrong?
No comments:
Post a Comment