In C#, I want to run a program and wait for the user to exit in order to get what was saved. For example, I want to run Photoshop or MSpaint, wait for the user to finish editing and, after saving, to get the file (jpg, png, etc) or at least the path of the file.
I have been unable to determine how to go about this.
It's probably going to depend heavily on the program you wish to use. If you use a program with an API to make calls and get feedback, then maybe you can do this. For Photoshop and MSPaint, I'm a bit skeptical they'd have this feature. In the end, what you might wish to do, is keep some kind of input box open and await the user to paste the path themselves. Either that or find such a program with the API you're looking for or make your very own image editor.
Related
I know how works FileSystemWatcher in C#.
It allows us to give a message when file is already created.
no matter which program/process has created this file!
Or it allows us to give information about what is a name of created file, or when it was created "few second ago"...
Also it allows us to give a message about file which was deleted or changed.
But it does not allows us to create that kind of event:
when file is being creating, but it is not yet/still created!
what if I want to terminate or pause the file creation process programmatically?
For example I want to handle or terminate file creation process programmatically according it's information which tells us that size of this file is 4GB?
no matter which program/process is trying to create this file!
Or there is another question:
What if I want to calculate when was file creation started and when was it created? as well distance between this two dates!?
I think you understood that we need more info about file before process will start to create it!
I think you might know that in windows 10 the explorer.exe allows us to do it anytime!
It even allows us to resume a copy process any time!
So if it is possible to do it in explorer.exe then it also might be possible to do it using .NET
But forget this resume capability of explorer.exe
I just need to cancel any file creation process for example if the size of this file is 4GB!
no matter which program is trying to create file!
So please help me to find out How to pop up a messageBox during file creation process?
Thank you!
Sorry my bad English!
The only way to be notified about the file operation before it is actually performed is to utilize a filesystem filter driver. This is a kernel-mode driver which you need to write in C. There exist samples of such drivers in the internet. An alternative to writing such driver yourself is to use one of the libraries that include pre-created filter drivers and let you handle all or chosen filesystem requests in user-mode (including .NET). Our company offers CallbackFilter product for this purpose.
Im working on automating the behavious of a scientific measurement program in C#.
The program does have a .net API, but the developers of the program havent included all necessary commands eg. they havent included a simple "save as" command that i need for saving the measureing data.
Is there a way to operate the menu strip of the application and e.g. press the save as button.
I start the program from my own application by means of Process.Start();
One simple solution - copy destination path to the clipboard, then use e.g. SendKeys.SendWait() to send the following keys to your target application (with sufficient pauses between them) Ctrl+S "^s", Ctrl+V "^v", Enter "{ENTER}".
It's also a good idea to verify the folder exists, and the file does not, otherwise the saving will obviously fail, or overwrite confirmation will popup.
P.S. But before doing that, use e.g. .NET Reflector to ensure their .NET API doesn't have the save functionality: there're many cases where the SendKeys approach will fail.
how to lock filename , so windows users can not change File filename .
Two ways:
Use the security permissions to restrict the user from doing so.
Open the file in exclusive mode, denying any operation on it by any other app.
Unfortunately, none of them is fail-proof... for the good of humanity :)
Thank God, this is not possible. You may restrict access to this file, so the user won't be able to access it and thus modify its name, but otherwise you cannot prevent them from renaming files.
One more thing, though...
If the file is continuously open in exclusive mode, nobody else will able to modify it, i.e. change its name... But this mean that some process has to lock it, i.e. windows service. Closing such service or killing the process in other way will release the lock.
Think outside the box - use Alternative data streams.
Hide the filename you want in there & have a background task to locate ads with your data stream and restore the 'correct' file name.
Thats not foolproof either, if the user moves the file to a fat32 volume & back again your ads will be lost.
Think outside the box - write your own file system and install it as an ifs
Think outside the box - don't put your data in a file, put it in a database
Think outside the box - Trust your users
This is what most of us do. Helpful error messages at start-up, graceful recovery, perhaps a file dialogue so the user can choose a filename that suits them for reasons you havn't anticipated.
i have c# program to save the path of the files and the password.
How can my program talk with backend program (ie 3rd application program) transparent to the user, to perform the tasks. And based on the data i captured using my c# progeam, given to use with that 3rd app program.
My C# program is just a frontend interface to automated the repeative task for keep manual operation from one source folder to destination folder to save operator time.
The problem is, i don't understand how to do this. I only know we need something like window automate task to get that done. How can i integrate my program + 3rd app.+window automate task, together?
thank you very much.
Create your program as a Windows Service, and make it run constantly
As for the data passing goes, you can output an XML file ( or write to a database), and let the 3 party app to use.
You may want to write a clearer question next time.
I want to write a program that will encrypt an entire folder and it's sub-folders, I have no problem doing this but I would like to make the entire encryption process rather transparent by letting a user double click it and have it open as if it weren't encrypted, say if it were a picture or a word document and it'd open in it's respective application.
How can a running program of mine become notified about the opening of a target file, stop the file from opening, do what it needs to do (decrypt), followed by running the resulting decrypted file.
How can I watch a file and do this in C#? Can I watch for other interactions like the user copying a watched file (since it won't be in a watched folder, it should be decrypted i.e. it's dragged to a USB device), or for deleting a watched file (say if I want to shred a file before deletion)?
P.S. The FileSystemWatcher doesn't quite meet my needs. EDIT: What I mean is that FileSystemWatcher will tell me when a file is being opened, deleted and all those events, but it won't let me step in real quick, decrypt the file, and hand it back to the process that normally opens that file.
You can rename files, add them your own extension, like thepicture.jpg.encrypted. Set your program as a default program for this extension and handle opening them
It's impossible in C#. the bare minimum would need you to use user-mode hooks on NtCreateFile, NtOpenFile, etc. You can't achieve that in C#. That wouldn't even work properly due to kernel-mode code which may try to access your files. The proper way of doing this would be to write a I/O minifilter (in C of course).
EDIT: If you're really desperate, try EasyHook - it allows you to hook functions from C#. I haven't tried it though, and it does seem risky hooking vital functions like NtCreateFile. Plus you need a fair bit of Native API knowledge.
Are you using Windows? If so, why not use the built-in BitLocker?
See this link:
BitLocker drive encryption
If you are thinking about a competitive application to BitLocker, add a comment, as I can point you in that direction as well.
Instead of trying to reinvent the wheel, use NTFS file encryption. You can encrypt single files or entire folders or drives. Plus it's completely transparent to the user and does exactly what you asks (e.g. automatically decrypt when copying to a UBS drive, etc). Just use System.IO.File.Encrypt(string) - there couldn't be anything easier.
You can't do this from usermode.
Unfortunately the only way to do this is to write a minifilter driver. Minifilter drivers allow you to intercept IO requests to files, you can then encrypt/decrypt the files you care about on the fly.
It sounds simple, but encryption minifilter drivers are very, very, difficult to get right. You will have to end up shadowing file objects which is a real challenge. Check with www.osr.com, they have a ton of information on doing exactly what you want to do.
If you choose to go this route I would recommend getting a copy of VMWare Workstation and download VirtualKD. It will let you debug at near fire-wire speeds into a VM. I would start with x64 Win7 and get remote shares working first.