简体   繁体   English

为什么Windows在模仿其他用户时不允许启动WinSock

[英]Why does Windows not allow WinSock to be started while impersonating another user

Using my own program or others I can't get winsock to run when calling if the process is created with CreateProcessWithLogonW or CreateProcessAsUserW. 使用我自己的程序或其他程序,如果使用CreateProcessWithLogonW或CreateProcessAsUserW创建进程,则无法在调用时运行winsock。 It returns this error when I create the socket: 我在创建套接字时返回此错误:

 WSAEPROVIDERFAILEDINIT 10106 

Service provider failed to initialize. 服务提供商无法初始化。

 The requested service provider could not be loaded or initialized. 

This error is returned if either a service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or NSPStartup function failed 如果无法加载服务提供程序的DLL(LoadLibrary失败)或提供程序的WSPStartup或NSPStartup函数失败,则会返回此错误

.

However, WSAStartup seems to go w/o an error. 但是, WSAStartup似乎没有错误。 Just creating the socket with WSASocket returns this. 只需使用WSASocket创建套接字即可返回此信息。

UPDATE: 更新:

Errors: 错误:

LoadUserProfile: Error Code 2. Can't find file specified LoadUserProfile:错误代码2.找不到指定的文件

AdjustTokenPrivs: Error Code 5. Access Denied AdjustTokenPrivs:错误代码5.访问被拒绝

I encountered exactly the same problem and it was due to the environment (!): Apparently WinSock expects a valid SystemRoot environment variable to be set. 我遇到了完全相同的问题,这是由于环境(!):显然WinSock期望设置一个有效的SystemRoot环境变量。 In my case I was calling CreateProcess() by specifying only one environment variable specific to my app (without inheriting the caller's environment), and it was failing. 在我的情况下,我通过仅指定一个特定于我的应用程序的环境变量来调用CreateProcess() (没有继承调用者的环境),并且它失败了。

Check that you created your process by either passing NULL to lpEnvironment to inherit the caller's environment, or specify a valid SystemRoot environment variable. 通过将NULL传递给lpEnvironment以继承调用者的环境或指定有效的SystemRoot环境变量来检查是否已创建过程。

Completely undocumented AFAIK, but it worked for me. 完全无证的AFAIK,但它对我有用。

Perhaps the user you executed the process with isn't allowed to use the TCP/IP stack? 也许您执行该过程的用户不允许使用TCP / IP堆栈?

Try to start the application with an administrator user that is not your own account. 尝试使用不是您自己的帐户的管理员用户启动该应用程序。

您必须拥有法案作为运营权限

May be you lack the required privileges to run the process as another user. 可能是您缺少以另一个用户身份运行该过程所需的权限。 Try getting the handle to the access token by a call to OpenProcessToken and add SE_IMPERSONATE_NAME by a call to AdjustTokenPrivileges and then call CreateProcessAsUserW. 尝试通过调用OpenProcessToken获取访问令牌的句柄,并通过调用AdjustTokenPrivileges添加SE_IMPERSONATE_NAME,然后调用CreateProcessAsUserW。 I have not tried this myself though. 我自己也没试过。
Code snippet in Python to do something similar with win32 calls Python中的代码片段用于执行与win32调用类似的操作

Run Process Monitor on it and see if it is failing to find a file or registry key. 在其上运行Process Monitor,看它是否找不到文件或注册表项。 Perhaps the impersonated user's profile is not loaded and Winsock (or a service provider it is trying to load) is looking for something there. 也许没有加载模拟用户的配置文件,Winsock(或它正在尝试加载的服务提供商)正在寻找那里的东西。

Always start WinSock near the top of main and leave it running. 始终在主要顶部附近启动WinSock并使其保持运行。 The need to start winsock is an accident of architecture and not germain to any problem domain anymore. 启动winsock的需要是架构的意外,而不再是任何问题域的germain。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM