以其他用户身份运行代码 [英] Run Code as a different user
问题描述
有没有办法告诉我的代码以其他用户身份运行?
Is there a way to tell my code to run as a different user?
我正在通过PInvoke调用NetUserSetInfo,我需要以其他用户身份调用它。有办法吗?
I am calling NetUserSetInfo via a PInvoke and I need to call it as a different user. Is there a way to do that?
推荐答案
假冒需要调用一些本机API(即LogonUser),因此可能不值得发布3页包装代码。该页面具有完整的工作示例: http: //platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/
Impersonation requires calling some native APIs (namely, LogonUser) so it's probably not worth posting 3 pages of wrapper code. This page has a complete working sample: http://platinumdogs.wordpress.com/2008/10/30/net-c-impersonation-with-network-credentials/
请注意,假冒很重要安全注意事项。确保您遵循最佳做法。
Note that impersonation has important security considerations. Make sure you follow best practices.
这篇关于以其他用户身份运行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!