How can I make Windows software run as a different user within a script?

北战南征 提交于 2019-12-05 15:52:05

I recommend taking a look at CPAU.

Command line tool for starting process in alternate security context. Basically this is a runas replacement. Also allows you to create job files and encode the id, password, and command line in a file so it can be used by normal users.

You can use it like this (examples):

CPAU -u user [-p password] -ex "WhatToRun" [switches]

Or you can create a ".job" file which will have the user and password encoded inside of it. This way you can avoid having to put the password for the user inside your build script.

It's a bit of a workaround solution, but you can create a scheduled task that runs as your user account, and have it run regularly, maybe once every minute. Yes, you'll have to wait for it to run then.

This task can then look for some data files to process, and do the real work only if they are there.

This might help, it's a class I've used in another project to let people make their own accounts; everyone had to have access to the program, but the same account couldn't be allowed to have access to the LDAP stuff, so the program uses this class to run it as a different user.

http://www.codeproject.com/KB/dotnet/UserImpersonationInNET.aspx

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