Click here to Skip to main content
14,978,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Drag and Drop feature to fetch the file path in my application if run my exe without admin mode this features work but when i run thorugh admin mode cant able to drag and drop the file, in my application admin mode is must.any suggestion?

What I have tried:

the code which i used is

public void SelectedFileReading(string TemPath)
       {
           FileReading.tagFTN SelectedFileData = new FileReading.tagFTN();
           SelectedFileData = FileReading.ReadSelectedFile(TemPath);

           FileSiganture.Text = Encoding.ASCII.GetString(SelectedFileData.m_FileSign);
           FileExtension.Text = SelectedFileData.m_szExtension;
           FileOffset.Text = SelectedFileData.m_nSigOffset.ToString();
           FileSize.Text = SelectedFileData.m_ullFileSize_DFL.ToString();
           Description.Text = SelectedFileData.m_szFileTypeDescription;
           AllDataFilled();


       }
       private void DragStack_Drop(object sender, DragEventArgs e)
       {
           if (e.Data.GetDataPresent(DataFormats.FileDrop))
           {
               // Note that you can have more than one file.
               string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
               if(files[0] != "")
               {
                   SelectedFileReading(files[0]);
               }


           }
       }
Posted
Updated 21-Jun-21 22:30pm

1 solution

UAC - and particularly User Interface Privilege Isolation - prevents lower-privileged applications from sending messages to higher-privileged applications.

Windows Explorer runs with normal privileges. If you launch your application with elevated privileges, Windows Explorer cannot send messages to it, so you cannot drag and drop from Explorer to your elevated application.

You can allegedly P/Invoke the ChangeWindowMessageFilterEx function[^] to allow specific messages through. But this isn't recommended for drag and drop, due to the messages it uses.

You can't run Windows Explorer as an elevated process, so you're left with using a different file manager running elevated, or using a file dialog launched from an elevated application. For example, if you run notepad elevated and try to open a file, you should be able to drag from the "open file" dialog to your application.

Q: Why Doesn’t Drag-and-Drop work when my Application is Running Elevated? – A: Mandatory Integrity Control and UIPI | Microsoft Docs[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900