Techniques to save files from ActiveX (protected mode IE)

微笑、不失礼 提交于 2019-12-08 11:52:38

问题


i have an ActiveX.

ActiveX means:

  • Internet Explorer
  • native binary code
  • running from a dll (.ocx)
  • in Protected Mode

The user would like to save some content. i would like to show a Save As dialog, then save to the location they said.

Since the process hosting my ActiveX is running at a Low integrity level, the code cannot save to the user's requested location.

Since the process hosting my ActiveX is running in Internet Explorer's Protected mode, the code cannot save to the user's requested location.

Instead the files are silently saved to a location that the user did not request.

Instead the files are silently saved to a location where the end-user is not able to find them.

Is there any suggestions of how to handle this?

Bonus Chatter

What is the user trying to save to their hard drive? It doesn't matter to the question. But pretend:

  • it's a few hundred megabyte 3D cad mesh
  • it's a GIS imagery dump
  • it's a PDF
  • it's a PNG
  • it's a text file

Additional Reading

Internet Explorer's protected mode api does allow addins to show a savedialog:

IEShowSaveFileDialog(this.Handle, "Eden.3ds", 
      GetUserDocumentsFolder(), null, 
      "3D Studio File|*.3ds|GIS Imagery|*.kvm|Adobe Acrobat File|*.pdf|All Files|*.*|"
      null, 0, 
      OFN_ENABLESIZING | OFN_PATHMUSTEXIST,
      ref destinationPath, ref stateCookie);

and then save the file using that cookie that save provided:

IESaveFile(stateCookie, sourcefilename);

Where sourcefilename is going to be a file that i managed to save somewhere (which is another question).

Bonus Reading

Understanding and Working in Protected Mode Internet Explorer

Saving Files to the User Profile

Some extensions need to save files to a particular location so that users or applications can later find the files. The following steps show how to save a file outside of a low integrity location:

Create a temporary version of the file in %userprofile%\AppData\LocalLow. Remember to delete the temporary file after the file is sucessfully saved.

Call IEShowSaveFileDialog with the location of the user's profile folder to prompt the user to save the file in a different location. If the user accepts the Save As dialog, IEShowSaveFileDialog returns the chosen destination folder.

Call IESaveFile with the location of the temporary file saved in Step 1.

When you do this, Protected Mode's user broker copies the file from the temporary location to the location selected by the user.


回答1:


The Internet Explorer Protected Mode API is how an ActiveX can save a file outside the low privelage areas:

  1. Save your file to the FOLDERID_LocalAppDataLow folder; where processes running at Low integrity level in IE are allowed to write:

    String sourceFile = SHGetKnownFolderPath(FOLDERID_LocalAppDataLow)+"\tempcopy.dat";
    SaveToFile(sourceFile);
    
  2. Show the user a save dialog using IEShowSaveFileDialog:

    int stateCookie = 0;
    
    IEShowSaveFileDialog(this.Handle, //hwnd
          "FemaleMesh.3ds", //suggested filename
          SHGetKnownFolder(FOLDERID_Desktop), //suggested save location
          "3D Studio Mesh|*.3ds|All Files|*.*", //save filer
          "3ds", //default extension
          1, //default one-based filter index
          ref destinationFile, 
          ref stateCookie);
    
  3. Instruct IE to move our temporary file to the location the user selected using IESaveFile:

    IESaveFile(stateCookie, sourceFile);
    

So i was right that IE Protected Mode API was the API to use. i just had to translate all the API headers, figure out the imports, write the code, debug it, test it, before i could figure out that it is the correct API to use.

Note: You can save yourself some work by checking if IE is running in protected mode first, by calling IEIsProtectedModeProcess:

Boolean isProtectedMode = IEIsProtectedModeProcess();

Bonus Chatter

The IE protected mode API functions do not work from outside Internet Explorer.

Note: Any code is released into the public domain. No attribution required.



来源:https://stackoverflow.com/questions/9213758/techniques-to-save-files-from-activex-protected-mode-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!