简体   繁体   English

如何在Windows上使用其他用户帐户创建新进程?

[英]How can I create a new process with another User Account on Windows?

Is it possible to create a new process on windows with a different user account? 是否可以在具有不同用户帐户的Windows上创建新进程? I know there are a context menu "Run as" but I want do it from Java. 我知道有一个上下文菜单“Run as”但我想用Java做。 I have the username and the password. 我有用户名和密码。

You need to write a DLL using the Java Native Interface (JNI) as you cannot do this with pure Java code. 您需要使用Java Native Interface(JNI)编写DLL,因为您无法使用纯Java代码执行此操作。

The DLL itself needs to call the CreateProcessAsUser function to create a process in the context of another user. DLL本身需要调用CreateProcessAsUser函数以在另一个用户的上下文中创建进程。 To successfully create that process you need to provide an access token to the function, which was itself created by calling the LogonUser function (it takes the username and password to authentify that other user). 要成功创建该进程,您需要为该函数提供访问令牌,该函数本身是通过调用LogonUser函数创建的(它使用用户名和密码来验证其他用户)。

There is a program called "runas.exe." 有一个名为“runas.exe”的程序。 You could run that process and supply the appropriate arguments for your process and username/password. 您可以运行该过程并为您的进程和用户名/密码提供适当的参数。 I think that's the simplest method. 我认为这是最简单的方法。

I just ran across an alternative to the runas.exe program called MiniRunAs which will take the password on the command line - http://www.source-code.biz/snippets/c/1.htm 我刚刚遇到了一个名为MiniRunAs的runas.exe程序的替代程序,该程序将在命令行上输入密码 - http://www.source-code.biz/snippets/c/1.htm

If you are able to install it along with your application, that may prove simpler than writing a JNI DLL. 如果您能够将其与应用程序一起安装,那么这可能比编写JNI DLL简单。

Depending on your needs the Win32 API " CreateProcessWithLogonW " is easier to use than the "CreateProcessAsUser / LogonUser" functions. 根据您的需要,Win32 API“ CreateProcessWithLogonW ”比“CreateProcessAsUser / LogonUser”函​​数更易于使用。

From MSDN Docs: 来自MSDN文档:

The CreateProcessWithLogonW and CreateProcessWithTokenW functions are
similar to the CreateProcessAsUser function, except that the caller 
does not need to call the LogonUser function to authenticate the user 
and get a token

RUNAS has the "/savecred" switch that let you enter the credential only the first time. RUNAS具有“/ savecred”开关,只允许您第一次输入凭证。 One potential problem is that when /SaveCred saves the credentials it saves it for whenever RUNAS invokes that user account. 一个潜在的问题是,当/ SaveCred保存凭据时,它会在RUNAS调用该用户帐户时保存它。 This can be a huge security risk so be careful using it! 这可能是一个巨大的安全风险,所以要小心使用它!

Example at http://www.rgagnon.com/javadetails/java-0014.html (at the end) http://www.rgagnon.com/javadetails/java-0014.html上的示例(最后)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建 firebase 用户帐户 - How can I create firebase user account 当用户在聊天中收到另一个用户的新消息时,如何创建通知? - How can I create a notification when a user receives new message from another user in my chat? 将 Intellij 许可证用户帐户更改为新帐户后,如何恢复 maven 依赖问题? - How can I recover maven dependency issues after changing my Intellij license user account to a new account? 我需要以其他用户的身份使用流程生成器来调用流程...我该怎么做? - I need to invoke a process using process builder as another user…How can I do it? 如何创建从Java类到GlassFish的新用户? - How I can create new user from Java class to GlassFish? 我可以使用Java在Windows上创建新的Windows组吗 - Can I create a new Windows group on windows using Java 如何获得Java流程的用户 - How can I get the user of a process in Java 我如何在一个Java进程中创建和写入文件并从另一个进程中读取而不会遇到读/写问题(Java / EE) - How can I create and write a File one Java Process and read from another process without facing read/write problems(Java/EE) 如何在不更改当前用户的情况下在 Parse 中创建新用户? - How can I create a new user in Parse, without changing the current user? 如何用Java创建新流程? - How to create a new Process in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM