开发者

Drag/Drop from user process to elevated process

I have a C# app that requires elevating with runas for certain functions to run. The problem I now have, is a picturebox that I have a drag/drop attached to is not working after runas. I've been reading posts all night so I'm familiar with the reason. I have also found a lot of info about accepting those messages through the filter. http://msdn.microsoft.com/en-us/library/ms632675(v=VS.85).aspx

What I haven't found, and I hope someone can help me with this, is how and where in the code to implement this. I've been trying various approaches and I can't get it to work. Here is a snippet of code that has my attempt at getting this to work. By the way, I also tried making changes with the filter in the manifest, but no go t开发者_如何转开发here as well. Thanks in advance for assistance anyone can offer.

public partial class Form1 : Form
{
    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr ChangeWindowMessageFilter(uint message, uint dwFlag);

    public Form1()
    {
        InitializeComponent();
        ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
        ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
        ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
        GetAndDisplayRights();
    }

    private const uint WM_DROPFILES = 0x233;
    private const uint WM_COPYDATA = 0x004A;
    private const uint WM_COPYGLOBALDATA = 0x0049;
    private const uint MSGFLT_ADD = 1;


This is not possible, no workaround for it either. D+D cannot drop an object into an elevated process from an unelevated one. UIPI (the UI component of UAC) prevents this. The ChangeWindowMessageFilter() workaround doesn't work, D+D isn't message based, it uses COM. WM_DROPFILES dates back to Windows 3 and is no longer used.

I suspect some future version of Windows to provide a workaround, it isn't possible yet as of Windows 7.


Here's how I worked around this problem.

I embedded a directory list and file list in my form and setup a mouse click listener for the file list. I have it configured to only show image files and as soon as you click an image, it gets set as the picturebox image. It's not drag and drop, but pretty darn close. The most important thing is it works regardless of privilege level of the app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜