none
How can I hide text files RRS feed

  • Question

  • I am using MS V S 2008.  I am working with files.  Something likes this 

    FileStream^ fs =

    new FileStream( "_1Name.txt", FileMode::OpenOrCreate);

     new StreamWriter(fs); // Create a StreamWriter

    sw->Write(strng);

    sw->Flush();

    sw->Close();


    Now I noticed that the files I am working with such as 
    "_1Name.txt", can be accessed and modified by anyone who can go to "My computer".  How can I hide those files or make them visible but inaccessible (May be giving them extensions not "*.txt" )? 

    Tuesday, September 15, 2009 9:12 PM

Answers

  • Your application needs to read/write a txt file, and you want to prevent others from accessing/modifying the file, am i right?
    If so, some ideas for you:
    1. Put the file in your application folder if possible to tell others that "don't modify or move the file, it is a part of the application.".
    2. Encrypt the file when write operation is done, decrypt it before read operation, following are some helpful links about Encrypt/Decrypt file:
            http://www.codeproject.com/KB/security/fileencryptdecrypt.aspx;
            http://www.codeproject.com/KB/security/DotNetCrypto.aspx;
            http://support.microsoft.com/kb/307010;
    3. There are some smart softwares have the abliity to hide file/folder, but those kits may also make the file inaccessible to your application.

    Thanks,
    Eric 

    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Marked as answer by eryang Tuesday, September 22, 2009 5:46 AM
    Thursday, September 17, 2009 3:57 AM

All replies

  • To prevent anyone from reading the file, make sure you press Windows + L whenever you leave your desk.
    Hans Passant.
    Wednesday, September 16, 2009 12:19 AM
    Moderator
  • Your application needs to read/write a txt file, and you want to prevent others from accessing/modifying the file, am i right?
    If so, some ideas for you:
    1. Put the file in your application folder if possible to tell others that "don't modify or move the file, it is a part of the application.".
    2. Encrypt the file when write operation is done, decrypt it before read operation, following are some helpful links about Encrypt/Decrypt file:
            http://www.codeproject.com/KB/security/fileencryptdecrypt.aspx;
            http://www.codeproject.com/KB/security/DotNetCrypto.aspx;
            http://support.microsoft.com/kb/307010;
    3. There are some smart softwares have the abliity to hide file/folder, but those kits may also make the file inaccessible to your application.

    Thanks,
    Eric 

    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    • Marked as answer by eryang Tuesday, September 22, 2009 5:46 AM
    Thursday, September 17, 2009 3:57 AM
  • Try writing a small app that open your files exclusively. This program would always be running. You can also make this program password protected.

    when ever you want to access your files, close your program so that it would release the file handles.
    Thursday, September 17, 2009 2:33 PM
  • These are not effective security measures.  Anybody that can get to your work station can kill a program or run a debugger to bypass the protection.  Press Windows + L for real protection.
    Hans Passant.
    Thursday, September 17, 2009 6:57 PM
    Moderator
  • Try writing a small app that open your files exclusively. This program would always be running. You can also make this program password protected.

    when ever you want to access your files, close your program so that it would release the file handles.

    I would like to explain that the files are going to be inside the folder.  If you open the folders of any program say windows xp.  You may find a lot of files of different extensions.  If you try to open any of them you cannot, but if there is a file end with .txt; I think anybody can open such as Ream me files.  Imagine if I do not want anybody to open that Read me file.

    Friday, September 18, 2009 1:50 AM
  • Eric,
     I think you understood me very well.  Thanks I will review those sites.  To make it clearer.  Imagine that I do not want anybody to read the Read me files. 
    Friday, September 18, 2009 1:55 AM
  • Hans,
    It is off the wall, but still can use it!
    Friday, September 18, 2009 1:58 AM

  • The instruction 

                File.SetAttributes(@"c:\yourfile.xyz", FileAttributes.Hidden)

    hidden the file.
    Monday, September 21, 2009 3:03 PM
  • I apprciate it.  Do you think it will work with MS VS C++ 2008?
    Wednesday, September 23, 2009 12:25 AM