运行code作为一个不同的用户(C#) [英] Run Code as a different user (C#)
问题描述
有没有办法告诉我的code作为一个不同的用户身份运行?
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页包装纸code的。这页有一个完整的工作示例:<一href=\"http://platinumdogs.word$p$pss.com/2008/10/30/net-c-impersonation-with-network-credentials/\">http://platinumdogs.word$p$pss.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.
这篇关于运行code作为一个不同的用户(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!