Can't run batch file from runas command

徘徊边缘 提交于 2019-12-06 16:14:16

I don't know how to get the runas command to run in the same window. But a trick is to spawn the cmd window yourself with the /k switch to prevent it from closing when done:

runas /user:username "cmd /k {fullpath}\file.bat"

Note that you need the full path to the file because the new window opens to your user directory.

Or you just put pause at the end of your .bat file instead of doing the above.

Use PsExec instead (MS SysInternals suite). Much better and secure (password used).

psexec -user Administrator -p Passwd "xcopy file.bat {fullpath}\file.bat"

Use PsExec instead (MS SysInternals suite). Much better and secure (password >used).

psexec -user Administrator -p Passwd "xcopy file.bat {fullpath}\file.bat"

Thanks! but I'm looking for a solution that will run portably, without installation...

I don't know how to get the runas command to run in the same window. But a trick is to spawn the cmd window yourself with the /k switch to prevent it from closing when done:

runas /user:username "cmd /k {fullpath}\file.bat"

Note that you need the full path to the file because the new window opens to your user directory.

Or you just put pause at the end of your .bat file instead of doing the above.

I did put the pause command at my batch file, but an error occurred before it so the file terminated. Thanks a lot!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!