dcsimg
Results 1 to 33 of 33

Thread: [RESOLVED] Brainstorming: Drag-Drop to Elevated VB App

  1. #1

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Resolved [RESOLVED] Brainstorming: Drag-Drop to Elevated VB App

    Kinda looking for ideas, more so for a mental exercise or proof of concept, regarding dragging files from Windows Explorer to your elevated VB app... We know that on modern O/S, this isn't allowed until Microsoft gives us an easy way to override it. So, is it worth it to get creative to override it ourselves? And if so, how?

    Caveat: The easiest workaround is to use another app as a go-between, i.e., NotePad. If NotePad is opened elevated, we can choose its File|Open menu and use that browser to drag from and drop to our elevated app -- done. But we coder's like challenges...

    Is it worth it? Can be argued. But if an app queries the content of the dragged items, then I feel it should be allowed to accept or deny what was dragged. Microsoft makes this decision for us in this case: No you can't accept anything. So for argument's sake, let's say that as an app creator, we feel it's worth it

    So, how do we work around the problem. My gut instinct is to run another app with user-rights and overlay that app on our elevated app. The lower-rights app could accept drag/drop. Here's the idea in outline form

    1. Use separate app that can accept OLE drops which is overlayed on elevated app
    2. Drag events, as desired, are forwarded to the elevated app for direction: accept, don't accept, etc
    3. If dropped files are accepted, pass the file list to the elevated app

    Sound simple enough, but that idea is rather complex. Should only apply to Vista and above? Or is this problem related to Win8.1 and above? Not really sure.

    Step 1: Overlaying app? We can use SetParent to do that. The lower-elevated app can be "hosted" by the elevated app and still accept drag/drops. It would need to be "unhosted" before hosting app unloads

    -- But we don't want that lower-level app to visually impair our elevated app. Idea: have the lower app be rectangle, roughly a 2 pixel border, 99% transparent. The inner rectangle contains areas of the elevated form's areas that would normally accept drag/drop. All other areas are cutout by being made 100% transparent or via window regions. We use SetParent API to do the overlay & position as needed. Based on this, this lower-level app is a nearly transparent "cutout" of the elevated form's areas that can accept dropped files

    -- This lower-level app would need to be able to know when dragging is in play and when it is not. When it is in play, the areas of the form that can accept dragged files would become "active". When it is not in play, then those areas become "inactive". When inactive, mouse events fall through the lower-level overlay via 100% transparency. The 2-pixel border is always active. Whenever a drag operation travels over that border, then "active" areas are made active. When drag operation is canceled or completed, then "active" areas are made inactive again. Major problem here is how to know when dragging is canceled. From that 2-pixel border we can determine when the drag enters/leaves the overall rectangle, but not if the user hits the ESC key while dragging

    Step 2: Communication. Lower-level apps can't send many messages to higher-level apps due to security. However, we can use a hidden textbox to communicate between the two apps: one on each app. We use SendMessage WM_SETTEXT to communicate back & forth. The higher-level app can send to lower level, but the lower level app can't send that to the higher unless we use ChangeWindowMessageFilterEx API to allow it. Tested that. If not using textboxes with formatted messages, we can use other methods of IPC, but my initial thoughts are to try this without subclassing.

    Step 3: Running the lower level app at a lower level. This is complex. If we try to load that other app (a separate exe) from our higher-level app's code, it runs at the higher level and defeats the overall purpose: won't accept files dragged from lower level apps. However, Raymond Chen offers a solution to this problem. My thoughts are that this lower-level app can only be activated with command-line arguments, one of which is the hWnd of the host's textbox used for IPC. If no Command$ arguments received, the app silently unloads.

    Visuals. In the image below, the black rectangle is our elevated-form. The red rectangle is that lower-level app with a 2ish pixel border that is always active. The yellow rectangle (overlaps entire textbox on main form) toggles between active/inactive depending on whether a drag operations is in play. When in play, that rectangle is not 100% transparent/cutout and accepts drops. When not in play, that rectangle is 100% transparent/cutout so that mouse events are not intercepted.

    Name:  SShot.png
Views: 363
Size:  2.5 KB
    Last edited by LaVolpe; Mar 16th, 2019 at 10:58 AM. Reason: added Raymond Chen link
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  2. #2
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    382

    Re: Brainstorming: Drag-Drop to Elevated VB App

    You can also run Windows Explorer elevated by using Run as Administrator, and any program you start from it would be elevated too. CreateProcess/ShellExecute work that way by design(and it's documented in these functions). Advantage: you only get UAC prompt once, when you start Windows Explorer; but not any program or shelled apps thereafter from that Explorer process/window. This doesn't affect the whole shell, just that window/process. Desktop icons will still start unelevated. Disadvantage: If you forget that the window is elevated, you might start something elevated by mistake, which is a security risk.

  3. #3

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by qvb6 View Post
    You can also run Windows Explorer elevated by using Run as Administrator, and any program you start from it would be elevated too.
    That's not correct. On Win8.1 (at least) thru Win10, you have that option, but it is not elevated in the end. On those O/S, open VB elevated and start new project with the form's OLEDropMode property set to Manual & run the test project. Now open Explorer elevated and try to drag a file onto the form. You'll see it is always the "no drop target" icon, circle with diagonal line through it. In fact, in this case, if you open task manager and display the "Elevated" column, it will show "No" whereas your "VB6.exe" will show "Yes"

    Additionally, in that test project. Add this in the Form_OLEDragOver event: MsgBox "Dragging". It'll never get triggered.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,308

    Re: Brainstorming: Drag-Drop to Elevated VB App

    What is the issue here?

    I can see that testing a drop-target in the elevated IDE can be an issue, but aside from that I don't see the purpose in defeating this security boundary.

    For that sort of testing I have a tiny program I call "Drag File Source" (DFS.exe). I can drop a copy of that into a folder I want to test dragging from. Running it, it requests elevation and if approved it lists the folders and files within its own Current Directory. You can select one or more items to drag from there.

    Name:  sshot.png
Views: 296
Size:  3.9 KB

    By just using a ListBox with no icons or other fanciness the program is small and nimble enough that leaving copies around shouldn't be a massive concern.

    But maybe my needs are just very modest.

  5. #5

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Here's a really simple example. Let's say that you have an app where the creator wants the ability to drag and drop files from Explorer onto the app. If the app wasn't run elevated, no problem. Why should I not be allowed to drag a file to that app when the app is run elevated instead, but can if I don't run it elevated? This isn't pertaining to the IDE specifically.

    In my opinion we are not defeating security, but simply offering a way around what one can possibly call an unwanted feature. Even if this feature was circumvented, the code using such a workaround would need to accept/decline what was dragged since I don't think we can circumvent and keep the OLEDropMode as Automatic

    I already mentioned we can use NotePad, for example, as a workaround. Just contemplating another option.

    Edited: IMO Microsoft simply broke this when they offered Explorer to be elevated but doesn't elevate it. Either offer it or don't, but don't offer it with an implied "PSYCH!"
    Last edited by LaVolpe; Mar 16th, 2019 at 03:30 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,308

    Re: Brainstorming: Drag-Drop to Elevated VB App

    This was almost certainly done because the exploit was in common use. I don't think Microsoft "broke" drag/drop across a security boundary by accident.

  7. #7
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,255

    Re: Brainstorming: Drag-Drop to Elevated VB App

    I'm trying to remember what exactly is restricted again... I opened two instances of a VB app, one running as admin, one not, and can dragdrop between them and between each one and Explorer (using IDropTarget and SHDoDragDrop).

    But I remember a problem like this.... is it because my account itself is admin and this would be a problem if it weren't?

  8. #8

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    fafalone, what O/S are you using. I remember a posting awhile back from you where stuff worked for you on Win7. But others confirmed what I'm experiencing -- it doesn't work on Win10 going back to at least Win8.1

    Also, logging in with an admin account is not the same as "Run As Administrator" on modern O/S. On my box, I'm an Administrator.

    If in doubt, open task manager and click the "Details" tab. Right click on one of the column headers and opt to "Select columns". Now find "Elevated" in the listing and select it. Now double check the two VB instances.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,255

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Ah that's it. I'm still on Win7. Checked on my laptop which runs Win10 and can drag from elevated to non-elevated but not to elevated from non-elevated.

    Something might be screwy with Win7 too, apparently if a process is elevated the 'UAC Virtualization' column in taskmgr should be blank, but it's always 'Not allowed', whether I run normal non-elevated, right click and 'Run as administrator', or set 'Run this program as an administator' in the Compatibility tab. And not just VB6 apps that goes for every program.


    IIRC the only workaround we had found was the uiAccess thing, which was either wildly impractical or impossible for VB apps.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,308

    Re: Brainstorming: Drag-Drop to Elevated VB App

    I think the issues are:

    1 - The uiAccess flag MUST be set to True in your application's manifest.

    2 - Your code MUST be digitally signed.

    3 - Your application MUST reside in a trusted location (e.g.; Program Files), otherwise the uiAccess flag is ignored.
    The manifest may have to be embedded as well. But I'm not sure what prevents a VB program from meeting these requirements.

  11. #11

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Just FYI. My initial dry-run is looking fairly good. I can overlay a separate application (not elevated) onto an elevated one. By using SetLayeredWindowAttributes on that overlay, I can "cut-out" no-drop areas while keeping "drop areas" at an alpha value of 1 (transparent to the human eye but still receives drag events). Raymond Chen's link (post #1) was the key for that tidbit -- launching an app from an elevated one without that launched one being elevated so it can be a drop target. The two apps talk together via WM_SETTEXT.

    Still have other issues to resolve. But for simple drag & drop of files, looking good so far. The end result, if I get that far, will be a separate app, i.e., DragDropHelper10.exe (overlay window), and a companion class to be added to a project that launches & communicates with that app.

    If I can get a working sample up & running tomorrow, I'll post it here for feedback and ideas. One thing that would make it nearly perfect would be a way to forward the DataObject from the drag events from the lower-level app to the high-level app; otherwise, kinda stuck with passing content of the DataObject vs the DataObject itself
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  12. #12
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,475

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by fafalone View Post
    Something might be screwy with Win7 too, apparently if a process is elevated the 'UAC Virtualization' column in taskmgr should be blank, but it's always 'Not allowed', whether I run normal non-elevated, right click and 'Run as administrator', or set 'Run this program as an administator' in the Compatibility tab. And not just VB6 apps that goes for every program.
    Probably Task Manager itself has to be elevated to figure out elevation status ("UAC Virtualization" or whatever fantasy name they put:-))). Btw, I'm using processhacker for way too long now to remember all taskmgr's idiosyncrasies.

    cheers,
    </wqw>

  13. #13
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    382

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Process Explorer has both Integrity Level(High/Medium/Low) and UAC Virtualization column:

    https://docs.microsoft.com/en-us/sys...ocess-explorer

  14. #14
    Hyperactive Member
    Join Date
    Feb 2019
    Posts
    382

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Duplicate post.

  15. #15
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    306

    Re: Brainstorming: Drag-Drop to Elevated VB App

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:06 AM.

  16. #16

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    @dz32. That API appears to work prior to Win8.1 from what I can gather. I'm not sure what version it stopped working on. Even MSDN has this note for both that API and the Ex version:
    Certain messages with a value less than WM_USER are required to pass through the filter regardless of the filter setting
    In other words, you can't prevent all messages less than WM_USER from being rejected. Microsoft has some hardcoded blacklist within the OS.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  17. #17
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,255

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by qvb6 View Post
    Process Explorer has both Integrity Level(High/Medium/Low) and UAC Virtualization column:

    https://docs.microsoft.com/en-us/sys...ocess-explorer
    The integrity column says 'High' whether it's run as admin or not, and the 'virtualized' column is blank for everything.

    And yes I ran it as admin itself, @wqweto I ran taskmgr as admin too and no change.

    I'm getting the distinct impression 'Run as administrator' isn't actually doing anything; is there some conclusion way to test it, like creating a new folder somewhere, deleting a file somewhere, renaming, etc? I'm testing with my shell browser so can try just about anything.

  18. #18

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Here's a small project as proof-of-concept. I will probably continue this because I find it a challenge. For any of you that are comfortable with passing COM objects across processes manually, hints would be helpful. Ideally, I'd like to pass the DataObject from the lower-level app to higher-level one.

    Anyway, to set this up... Both projects are in the same zip.

    1. Recommend unzipping into a new test folder and unzip both projects into same folder
    2. Open the prjDragDropHelper.vbp project first & compile it to the same folder. This is the overlay & needs to be compiled
    3. Load the prjDragDropSample.vbp project after starting the IDE elevated "As Administrator" so you can test the overlay
    4. Run the project. The overlay is hardcoded in this sample project using App.Path, just FYI. If you compiled that overlay elsewhere, change the path & filename as needed

    Now to test this. The project is no where near complete, so don't mess with the code too much because it will break. Again, just provided for feedback and proof-of-concept

    -- Open Windows Explorer and drag a file onto the top textbox. It should take it
    -- To test without DropTargets, rem out the "DragDropHlpr.AddDropTargetRECT" line in the DragDropHlpr_Initialized event

    The overlay is nearly opaque (almost completely white) so you can kinda get a feel for what is happening. When a file is dragged across the thin white borders in the form's client area, the overlay can catch that and then displays the new DropTarget area in white. Only one DropTarget in this example: that textbox. When the drop is finished or the user cancels with "Esc" key or drops it on some other window, the overlay should catch that too and then remove the DropTarget areas. The textbox will no longer be covered up.

    Known bug and haven't been able to track it down yet. Sometimes, the overlay fails to unload. When this happens, I need to kill it from TaskManager. This is likely a problem with trying to unload the project from the txtIPC change event -- minor annoyance. It's only a problem in testing when I need to recompile the overlay. If it's running, can't overwrite it.

    If you want to play with it with the overlay being nearly transparent...
    - Open that prjDragDropHelper project and look inside pvRepaint. Change the SetLayeredWindowAttributes alpha parameter from 222 to 1
    - Recompile it to apply the changes
    Attached Files Attached Files
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,308

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by fafalone View Post
    The integrity column says 'High' whether it's run as admin or not, and the 'virtualized' column is blank for everything...
    Are you doing something weird?

    For example is UAC disabled? Are you logging on as the (normally hidden) Administrator account?

    Otherwise it is hard to imagine what is going on.

  20. #20
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    432

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by dilettante View Post
    Are you doing something weird?
    For example is UAC disabled? Are you logging on as the (normally hidden) Administrator account?
    Otherwise it is hard to imagine what is going on.
    I think I triggered this...
    See here for the reason:
    http://www.vbforums.com/showthread.p...=1#post5370331

  21. #21
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    2,255

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by dilettante View Post
    Are you doing something weird?

    For example is UAC disabled? Are you logging on as the (normally hidden) Administrator account?

    Otherwise it is hard to imagine what is going on.
    UAC is set to 'Never notify'.. account has admin priveleges but isn't Administrator.
    Does that make it so there's no difference between 'Run as administrator' and normal? Or that the taskmgr/procxp can't tell? Should figure out a test...

  22. #22
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,308

    Re: Brainstorming: Drag-Drop to Elevated VB App

    "Never notify" is a euphemism for "Don't protect me when logged on with an Admistrators group account" i.e. UAC is disabled.

    • You won't be notified before any changes are made to your PC.

    • If you're signed in as an administrator, apps can make changes to your PC without your knowledge.

    • If you're signed in as a standard user, any changes that require administrator permissions will automatically be denied, or still be prompted by UAC.

    • This is the least secure setting. When you set UAC to never notify, you open up your PC to potential security risks.

    • If you set UAC to never notify, you should be careful about which apps you run, because they'll have the same access to the PC as you do. This includes reading and making changes to protected system areas, your personal data, saved files, and anything else stored on the PC. Apps will also be able to communicate and transfer info to and from anything your PC connects with, including the Internet.
    Last edited by dilettante; Mar 18th, 2019 at 06:03 AM.

  23. #23

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    FYI. Regarding post 18 where I offered a proof-of-concept project for feedback... That project attempt to be a trap for dragged items into the the form. But it has serious logic flaws that I don't think can be overcome

    - If window dragging from is partially overlapping your form, then that overlay/monitor can be bypassed on up to 3 of its 4 edges
    - For a notepad-like app where entire form is filled by a textbox, there is no room for that overlay window, as it needs a few pixels around the inside edges of your form
    - Because that overlay needed a few pixels, a user dragging something quickly across those thin edges may not trigger the overlay

    I think I'm going to go another route which is more passive, but timer-reliant. I'm confident I can determine when a drag operation is taking place anywhere on the desktop, without message hooks or subclassing. The idea will be to look for drags and when found, activate the overlay. When the drag is finished/canceled, remove/hide the overlay. The largest obstacle remaining is how to pass the dragged DataObject between processes. I know I can use the clipboard (and very well might), to pass dropped files, pictures and text but would prefer not to

    This new approach will not require the overlay to be hosted on the user's form permanently, nor require any space on that form. More to follow, including another proof-of-concept sample project.

    Follow-up: Really like the timer-based attempt!!! Won't work on it much today, but maybe have something to post tomorrow?
    Last edited by LaVolpe; Mar 18th, 2019 at 03:10 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  24. #24

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Regarding transferring the DataObject across processes...

    The VB DataObject doesn't seem possible if following the rules. VB somehow keeps track of its objects and fires off an error via the API call if I try. Here's the API call & translated error
    CoMarshalInterface ObjPtr(IStream), riid, ObjPtr(Data) returns error 98:
    A property or method call cannot include a reference to a private object, either as an argument or as a return value
    However, I can successfully transfer the IDataObject interface that is related to VB's DataObject -- so that's a plus. Unfortunately, to make things easier on the class consumer, this means implementing VB's DataObject myself and accessing the IDataObject interface methods low-level or via TLBs. Since I'm comfortable with DispCallFunc low-level API, not a big deal really.

    Now it's just a matter of wrapping all my test code up into a usable sample project. There will still be hurdles, but for simple things like dragging files, bitmaps and text, this looks very promising and not overly inconvenient for typical use. Since I no longer need to have the overlay/helper permanently visible on the host or even hosted until needed, this means all previously mentioned obstacles no longer exist -- just some new ones, not many.
    Last edited by LaVolpe; Mar 19th, 2019 at 05:39 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  25. #25

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    And yet another follow up... Almost at a point of letting this go

    Background. VB offers just 1 IDropTarget interface for the entire form and its constituent controls. Other controls, i.e., RichTextBox, etc, will have their own IDropTarget interfaces. So, VB uses just one interface. That in itself is not a problem. But because it uses just one, it needs to know what control or form portion the mouse is over so it can reroute DragDrop events to that control. In order to do this, it is using something like WindowFromPoint API -- understandable. However, if we have an overlay on top of the form, then that API returns the overlay's hWnd -- unfortunate.

    Though we can still do this for simple drag/drop stuff, it is in no way perfect (though I have one more idea). The major problems with this overaly and VB not being able to use WindowFromPoint accurately is that the drop target application, i.e., your app, is responsible for scrolling windows due to dragging, placing the caret in textboxes due to dragging and a couple other things. This is done for us behind the scenes. Well, if VB can't use WindowFromPoint, then it assumes drag/drop is not on its windows. So, in these cases, the scrolling, caret placement are not done.

    I can get the IDropTarget that VB uses. I can call it directly, passing it a DataObject, valid X,Y coords and the other required parameters. However, VB won't process the DragDrop events because of WindowFromPoint. If I move that overlay off the project and fudge the X,Y coordinates sent to the IDropTarget interface so it looks like the mouse is over the project, then VB happily triggers the DragDrop messages. VB appears to honor the X,Y coords sent via IDropTarget instead of getting the actual mouse coords separately.

    As I said earlier in this post -- 1 more idea to try. I do like challenges; just don't like failure, hence the saying in my signature below
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  26. #26

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Well, that last idea I had, worked in my head -- but we know how that goes. Anyway, because the source app that instigated the drag can exist in a different process, that idea went down in flames. The idea was to cut a hole in the overlay allowing VB's WindowFromPoint call to work correctly, then quickly close it. But the drag source saw this too and sent a drag leave event to the overlay when it saw the mouse was over another window, which is not what I wanted.

    Any hoo ... I'll write up an example that can be used for the simplest of drop requests. By simple, I mean that it will not work for all people in all scenarios. The usage will be worthwhile for those that only care to get the drop, they don't need to respond to the OLEDragOver event, just the OLEDragDrop event if applicable. They would have to understand that drag-scrolling and caret placement in textboxes would not work. That would also mean you wouldn't have control over where the drop occurs on a textbox if that textbox was the target. Again, not applicable in all scenarios.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  27. #27
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    432

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by LaVolpe View Post
    I'll write up an example that can be used for the simplest of drop requests. By simple, I mean that it will not work for all people in all scenarios.
    LaVolpe, I really appreciate your efforts.

    While it is all interesting, I wouldn't go further.
    The drop is not allowed because the OS doesn't allow it.
    I doubt it make sense to work against the OS.

    But, if it is not too much effort, I'm eager to see what comes out of your test.

  28. #28
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,316

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by Karl77 View Post
    While it is all interesting, I wouldn't go further.
    The drop is not allowed because the OS doesn't allow it.
    I doubt it make sense to work against the OS.
    Yep - which triggers the question of: why exactly your "license dialog" needs elevation to work properly?

    Olaf

  29. #29

    Thread Starter
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,234

    Re: Brainstorming: Drag-Drop to Elevated VB App

    I'm officially ending my efforts. Here's a short list of what I've discovered should anyone want to pursue this

    1. We can get the IDropTarget into an elevated process via marshaling: CoMarshalInterface (from lower level), CoUnmarshalInterface (from elevated level).

    2. An overlay was easy to use, but in the end was too much of an obstacle to try to communicate between the lower & elevated processes and the drag source. VB can't process a drag event without WindowFromPoint API calls which the overlay blocks.

    Technically, when a drop on the overlay happens, the overlay could get all known data from the drag source, pass that to the elevated process and hide itself. Then the elevated process creates an IDropTarget in its own process and fires a drop event that will trigger VB events. This is not a good solution because: a) we'd have to copy all dragged items into the process whether the drop target wants it or not, b) there is no way to communicate back to the drag source our true intent: dropCopy, dropMove, etc.

    I did briefly consider trying to play with token impersonation or modifying token privileges, but quickly opted against it for two reasons: 1) a huge learning curve for me and 2) even if possible, allowing a lower process access to elevated process from within the elevated process is a potential security risk. One of the things that a lower level process can't do is call OpenProcess (may be what COM does during drags?). If we punched a hole to allow it, even briefly, that would open a backdoor to any malware scanning for such opportunities, giving them the opportunity to inject themselves into an elevated process with admin rights.

    Down the road, maybe Microsoft will actually elevate Explorer when "Run As Administrator". Until then, just tell your customers of the workarounds like using an elevated instance of NotePad to get to an explorer-like dialog to drag from.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  30. #30
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    432

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by Schmidt View Post
    Yep - which triggers the question of: why exactly your "license dialog" needs elevation to work properly?
    Olaf
    That's because the license is per machine, not per user.
    I use a 3rd party tool for the license stuff (SoftwarePassport/Armadillo).

    I thought it could be a better solution to ask for admin rights at the moment when the license is written.
    So I tested it with some non-IT-pro users, and they were confused when the UAC dialog came up.
    Because of that, I decided to let the whole app request admin rights for licensing.

    If you have a better idea or know of a better tool, tell me.

  31. #31
    PowerPoster
    Join Date
    Jun 2013
    Posts
    4,316

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by Karl77 View Post
    That's because the license is per machine, not per user.
    Ah, OK...

    Quote Originally Posted by Karl77 View Post
    I thought it could be a better solution to ask for admin rights at the moment when the license is written.
    Yeah - that's exactly what I was going to suggest (to keep the GUI un-elevated - and then
    switch to some "setup-like, non GUI-activity" via a separately shelled process or a service which has the appropriate rights.

    Quote Originally Posted by Karl77 View Post
    So I tested it with some non-IT-pro users, and they were confused when the UAC dialog came up.
    Because of that, I decided to let the whole app request admin rights for licensing.

    If you have a better idea or know of a better tool, tell me.
    The idea would be as written above - run the Drag&Drop-GUI for your License-file normally (unelevated) -
    and gather the data.

    Then proceed either via the already mentioned "pre-installed service of your own" you can communicate with,
    and which then could write the needed registry-infos to HKLM from the usual "System-account" it runs under (without prompting UAC)...
    or .
    Simply show an "Explanation-Dialog" beforehand, to preempt the "surprise-effect" of the potentially up-coming UAC-prompt.

    -----------------------------------------------------------------------------------------------------------------------------
    Your Drag-Operation of the License-Information was successful.

    We will now proceed with writing these informations into a safe area on your machine -
    please confirm the next upcoming Dialogue, to allow this setup-like action to succeed.
    -----------------------------------------------------------------------------------------------------------------------------

    Or something like that will go a long way, to reduce confusion on the side of inexperienced users.

    Olaf

  32. #32
    Hyperactive Member
    Join Date
    Apr 2015
    Posts
    432

    Re: Brainstorming: Drag-Drop to Elevated VB App

    Quote Originally Posted by Schmidt View Post
    Simply show an "Explanation-Dialog" beforehand, to preempt the "surprise-effect" of the potentially up-coming UAC-prompt.
    Such a dialog is useful, no doubt.
    Unfortunately, some users consider a MsgBox or even a better dialog as a nice screen decoration.
    I experienced such fast click-away behavior too often.


    -----------------------------------------------------------------------------------------------------------------------------
    Your Drag-Operation of the License-Information was successful.

    We will now proceed with writing these informations into a safe area on your machine -
    please confirm the next upcoming Dialogue, to allow this setup-like action to succeed.
    -----------------------------------------------------------------------------------------------------------------------------
    A good text for you and me...

    The setup requires admin rights anyway.
    At the end of the setup, the 'Start now' checkbox is checked.
    The software starts elevated.
    Licensing can happen with no obstacles.

    If the user decides to start the app manually, the license dialog explains in short words that the app has to run elevated for licensing.
    And a button can restart the app elevated if wanted.

    I think this is an acceptable solution.

    ---

    D&D was just an idea.
    Not super important.

    Also, for D&D a file, the file must be saved somewhere before.
    Some user forget where they saved a file immediately.
    True.

    ---

    Thanks for the idea!

  33. #33
    Junior Member
    Join Date
    Jan 2014
    Location
    Oregon
    Posts
    17

    Re: [RESOLVED] Brainstorming: Drag-Drop to Elevated VB App

    Just found this thread and thought I would share how I over came the drag and drop problem. Copy and paste. I have a note on the form to a user that they can copy and paste the files into the list, I then have the code and functions to read the clip board for the file and folder names and add them to the list. This works perfectly since drag and drop is out of the question with an elevated app. I could put together a sample app if you like.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width