2 questions. Is it possible to get name of the exe currently being run?

I'm writing a file shredder and want to make sure that the shredder doesn't try to accidently delete itself. I know I can always keep a const string in the file code, but what if I decide someday to change the name of the file executable?

Second question:
Is it possible with c++ to check what if any programs are reading, writing to, or deleting my specified files?

Like the only way I was thinking of was if my c++ program was currently running and if I had a fstream object created and opened up to a file I wanted to protect that would prevent another program from reading and or deleting my file.

Is there anyway to get the name of the program that was trying to delete my file?

Thanks a bundle!
Adios,
argv[0] passed to main() is usually the name of the executable.

If in Windows, you can use GetModuleFilename() to get the name of the executable. As for knowing who has a certain file open, that's a good question. I am curious myself.
I tried GetModuleFilename(). Did you mean GetModuleFileName()? What are the parameters for that? Can you provide an example of how it works?
http://msdn.microsoft.com/en-us/library/ms683197(VS.85).aspx . I'm sure you can search the web for examples on this function.
I did, and I was lead to the site you posted, which doesn't show any examples.
Topic archived. No new replies allowed.