将托管线程上的模拟令牌传递给非托管线程
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否尝试过使用
SetThreadPrincipal
方法关闭AppDomain
?示例:
IPrinicipal userPrincipal = new MyCustomPrincipal();
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.SetThreadPrincipal(userPrincipal);
您在问题中提到,WMV 似乎以非托管方式运行,所以如果这个前提是正确的,这确实不应该起作用(请参阅我的第二个答案)。
Have you tried using
SetThreadPrincipal
method offAppDomain
?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).
我想您尝试使用
登录网络共享。
根据我的经验,它不关心线程。
如果您认为它有用的话,我可以向您展示一个使用示例。 在这里提及它有点遥远。
I suppose you tried using
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.
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.
假设 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.