How to hide file programmatically?

18 08 2008


Hidden files are very basic and primitive mode of protection. If your file is set as hidden, it won’t get listed to normal user, unless he explicitly enabled – “Show hidden files”. Well, how to make a file really hidden?


You can use the api – SetFileAttributes(). Pass FILE_ATTRIBUTE_HIDDEN as attribute and you’re file will be hidden. Have a look at the code snippet.

// The file, which is to be hidden.
CString csFile = _T("C:\\Autumn Leaves.jpg");

// Hide the file.
SetFileAttributes( csFile, FILE_ATTRIBUTE_HIDDEN );


Another alternative is to use CFile::SetStatus(). Have a look at it too…


Targeted Audience – Beginners.

Advertisements

Actions

Information

3 responses

9 09 2008
Vishal

Nice post, Write some more interesting articles.

Thanks

9 09 2008
Jijo.Raj

Thanks a lot, buddy!!! Sure, expect more interesting tips. Keep watching!!! 😀

Regards,
Jijo.

17 06 2009
Undreamt

Hey man! Thanks for the tip!
I have a question though, if I place such a hidden file in the startup folder, it wont start, or will it?

is there a way to make it start, programatically?

I would appreciate and answer, and thanks for the great blog!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s




%d bloggers like this: