将托管线程上的模拟令牌传递给非托管线程

发布于 2024-07-04 11:59:57 字数 288 浏览 5 评论 0原文

我有一个 VB.Net winforms 应用程序需要通过网络播放 WMV 文件的情况。 运行应用程序的用户无法直接访问网络共享。 通过模拟,我可以看到文件存在(如果没有模拟,File.Exists 对于网络共享上的文件返回 false)。 然后,当我尝试将文件加载到 Windows Media Player 控件中时,该控件仍保持黑色。 我推断,当 Windows Media Player 控件加载到内存中时,它在与 .Net 托管线程不同的单独非托管线程上运行。 有什么方法可以将该安全令牌从托管线程传递到非托管线程吗? 我完全错过了什么吗?

I have a case where a VB.Net winforms app needs to play WMV files from across the network. The user running the app cannot be given direct access to the network share. Through impersonation, I can see that the files exist (without impersonation, File.Exists returns false for the files on the network share). When I then try to load the file into a Windows Media Player control, the control just remains black. I have deduced that when the Windows Media Player control is loaded into memory, it is running on a separate unmanaged thread than the .Net managed thread. Is there any way to pass that security token from the managed thread to the unmanaged thread? Am I missing something completely?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仙女山的月亮 2024-07-11 11:59:57

您是否尝试过使用 SetThreadPrincipal 方法关闭AppDomain

示例:

IPrinicipal userPrincipal = new MyCustomPrincipal();

AppDomain currentDomain = AppDomain.CurrentDomain;

currentDomain.SetThreadPrincipal(userPrincipal);

您在问题中提到,WMV 似乎以非托管方式运行,所以如果这个前提是正确的,这确实不应该起作用(请参阅我的第二个答案)。

Have you tried using SetThreadPrincipal method off AppDomain?

Example:

IPrinicipal userPrincipal = new MyCustomPrincipal();

AppDomain currentDomain = AppDomain.CurrentDomain;

currentDomain.SetThreadPrincipal(userPrincipal);

You mentioned in your question, that WMV seems to run unmanaged, so if that premise is correct, this really shouldn't work (see my second answer).

比忠 2024-07-11 11:59:57

我想您尝试使用

[DllImport("advapi32.dll", SetLastError=true)]
public static extern int LogonUser(string pszUsername, string pszDomain, string pszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);  

登录网络共享。

根据我的经验,它不关心线程。

如果您认为它有用的话,我可以向您展示一个使用示例。 在这里提及它有点遥远。

I suppose you tried using

[DllImport("advapi32.dll", SetLastError=true)]
public static extern int LogonUser(string pszUsername, string pszDomain, string pszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);  

to log in the network share.

In my experience it doesn't care about threads.

I can show you a usage example if you think it can be useful at all. Kind of a long shot to mention it here.

疑心病 2024-07-11 11:59:57

WMP 很有可能启动它自己的线程,这些线程继承自您的进程令牌,这是 ::CreateThread() 的默认行为。 我很确定不可能从外部更改线程令牌,除非控件接受令牌作为参数,否则您无能为力。

我不确定除了将其放入另一个进程并使用 ::CreateProcessAsUser() 和您拥有的令牌创建该进程或将文件缓冲到本地某个地方之外是否还有答案。

There is a very good chance that WMP is starting it's own threads that are inheriting from your process token, this is the default behaviour of ::CreateThread(). I'm pretty sure it's not possible to change a threads token from the outside and unless the control accepts a token as a parameter there is not a lot you can do.

I'm not sure there is an answer outside of putting it into another process and creating that process using ::CreateProcessAsUser() with the token you have or buffering the file down to somewhere local.

一萌ing 2024-07-11 11:59:57

假设 WMV 播放器在您的 AppDomain 之外运行,我将尝试托管 WPF / Silverlight 媒体播放器以通过网络访问文件。

Assuming WMV player runs outside your AppDomain, I would try to host the WPF / Silverlight media player to access the file over the network.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文