<p>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?</p>

[{'answer_id': 64630, 'author': 'Alvaro Rodriguez', 'author_id': 1550, 'author_profile': 'https://Stackoverflow.com/users/1550', 'pm_score': 0, 'selected': False, 'text': '<p>I suppose you tried using  </p>\n\n<pre><code>[DllImport("advapi32.dll", SetLastError=true)]\npublic static extern int LogonUser(string pszUsername, string pszDomain, string pszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);  \n</code></pre>\n\n<p>to log in the network share.</p>\n\n<p>In my experience it doesn\'t care about threads.</p>\n\n<p>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.</p>\n'}, {'answer_id': 1596320, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 1633464, 'author': 'Brett Veenstra', 'author_id': 307, 'author_profile': 'https://Stackoverflow.com/users/307', 'pm_score': 1, 'selected': False, 'text': '<p>Have you tried using <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.setthreadprincipal.aspx" rel="nofollow noreferrer"><code>SetThreadPrincipal</code></a> method off <code>AppDomain</code>?</p>\n\n<p>Example:</p>\n\n<p><code>IPrinicipal userPrincipal = new MyCustomPrincipal();</code></p>\n\n<p><code>AppDomain currentDomain = AppDomain.CurrentDomain;</code></p>\n\n<p><code>currentDomain.SetThreadPrincipal(userPrincipal);</code></p>\n\n<p>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).</p>\n'}, {'answer_id': 1633475, 'author': 'Brett Veenstra', 'author_id': 307, 'author_profile': 'https://Stackoverflow.com/users/307', 'pm_score': 0, 'selected': False, 'text': '<p>Assuming WMV player runs outside your AppDomain, I would try to host the WPF / Silverlight media player to access the file over the network.</p>\n'}]
['https://Stackoverflow.com/questions/63379', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']