views:

539

answers:

4

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?

A: 

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.

Alvaro Rodriguez
A: 

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.

L2Type
+1  A: 

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).

Brett Veenstra
A: 

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

Brett Veenstra