如何使 Windows 软件在脚本中以不同用户身份运行?
我正在使用一个构建脚本来调用 Wise 来创建一些安装文件。 问题是 Wise 许可证只允许它在一个特定的用户帐户下运行,该帐户与我的构建脚本运行的帐户不同。 我知道 Windows 有 runas 命令,但这对于自动脚本不起作用,因为无法通过命令行输入密码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可能会有所帮助,这是我在另一个项目中使用的一个类,可以让人们创建自己的帐户; 每个人都必须有权访问该程序,但不能允许同一帐户访问 LDAP 内容,因此该程序使用此类以不同的用户身份运行它。
http://www.codeproject.com/KB/dotnet/UserImpersonationInNET.aspx
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
这可能会有所帮助: 为什么 RunAs 程序不接受密码在命令行上?
This might help: Why doesn't the RunAs program accept a password on the command line?
我建议查看 CPAU。
您可以像这样使用它(示例):
或者您可以创建一个“.job”文件,其中包含编码的用户和密码。 这样您就可以避免将用户的密码放入构建脚本中。
I recommend taking a look at CPAU.
You can use it like this (examples):
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.