Is there a way to fake file on file sistem or Write a file that visible only to my EXE file

activex, adobe, filesystems, winapi, windows

Solution

You can almost do it (means: no you can't, but you can do something that comes close).

Creating a file with `FILE_ATTRIBUTE_TEMPORARY` does in principle create a file, temporarily. However, as long as there is sufficient buffer cache (which is normally always the case unless your file is tens to hundreds of megabytes), the system will not write to disk. This is not just something that happens accidentially, but the actual specified behaviour of this flag.

Further, specifying `0` as share mode and `FILE_FLAG_DELETE_ON_CLOSE` will prevent any other process from opening your file for as long as you keep it open, even if someone knows it's there, and the file will "disappear" when you close it. Even if your application crashes, the OS will clean up behind you (if DRM is the reason). If you're in super paranoia mode and worried about the system bluescreening while your file exists, you can additionally schedule a pending move too. This will, in case of a system crash, remove the file during boot.

Lastly, given NTFS, you can create an alternate stream with a random, preferrably unique name (e.g. SHA1 of the document or a UUID) on any file or even directory. Alternate streams on directories are ... a kind of nasty hack, but entirely legal and they work just fine, and don't appear in Explorer. This will not really make your file invisible, but nearly so (in almost every practical aspect, anyway). If you're a good citizen, you will want to use the system temp folder for such a thing, not the program folder or some other place that you shouldn't write to. Creating an alternate stream is dead easy too, just use the normal file or directory name and append a colon (`:`) and the name of the stream you want. No extra API needed.

Other than that, it gets kind of hard. You can of course always create something like a ramdisk (would be tough to hide it, though), or try to use one of the stream-from-memory functions to fool an application into reading from a memory buffer on the allegation of a file... but that's not trivial stuff.

Problem

Ok i wrote and application that use Adobe ActiveX control for displaying PDF files. Adobe ActiveX control load files only from file system. So i nead to feed a file path to this control. Problem is that i don't want to store PDF files on file system. Event temporary! I wan't to store my PDF files only in memory, and i want to use Adobe ActiveX control. So i nead: 1) A way to fake file on a file system. So this control would "think" that there is a file, but would load it from memory 2) A way to create file on file system that would be "visible" to only one application, so my PDF control could load it, and other users won't even see it.. 3) Something else PS: I'm not asking to "finish my home work", i'm just asking - is there a way to do this?

Original source