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

我与影子孤独终老i 提交于 2019-12-12 09:45:18

问题


I'm using a build script that calls Wise to create some install files. The problem is that the Wise license only allows it to be run under one particular user account, which is not the same account that my build script will run under. I know Windows has the runas command but this won't work for an automated script as there is no way to enter the password via the command line.


回答1:


This might help: Why doesn't the RunAs program accept a password on the command line?




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/98134/how-can-i-make-windows-software-run-as-a-different-user-within-a-script

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