Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get random folder name in windows folder

Status
Not open for further replies.

PlutoDev

Programmer
Sep 21, 2002
25
0
0
ID
How to get a folder name by random in folder c:\windows or c:\program files

because when i run my program, i have to save a file in a folder. but users may not know where this files exists.

so, my solution is save my file in a random folder in drive C that users do not know where my files exists..

after my process done. this file will be deleted automaticly.

for example,
the function may return :
C:\WINDOWS\Fonts or
C:\WINDOWS\system32\CatRoot or
C:\WINDOWS\system or
C:\WINDOWS\Help\mail or
a folder in c:\windows



Thanks in advance.
 
When you start your application you can create a TStringList of the possible folders. When you are creating your temporary file you could use a random number of 0 to StringList.Count - 1 to select one of those folders. If you need to add other folders to the list such as c:\windows\system32\catroot then you can add that manually to the TStringList.
 
The standard way to do that is use the windows TEMP directory, which can be acquired with function GetEnvironmentVariable().

Roo
Delphi Rules!
 
How to get folder name that exists in folder c:\windows\*.*
into TStringList automaticly.

I don't want fill folder name into TStringList manually. because in windows 98, me, xp, 2000, vista, 7 may difference..

I can not use folder temp. i am affraid the user see my file in temp folder.

Thank's for support

 

forget about putting files in windows system directories.
These include windows folder and subfolders, program files folder and subfolders. It is considered bad practice and it wont work in Vista/W7 due to UAC.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
What sort of files are you hiding? Music files, databases, pictures? Perhaps there is an alternative way of protecting them.
 
I hide a txt file, this is a result of decryption file by program. after finish my process. this file will be deleted automaticly.

if in folder windows or program files not work.
may be, i will store this file at other folder(random)

or

how to protect this file, so the user cannot see/open/copy this file during my programm process. for example : access denied because is being used or etc...

Thanks
 
Is the decryption process part of your program as well?
 
Already done: Windows OS (all versions) will not allow open/copy/delete while your program holds the file open. You can change file attributes to hidden/read-only when closed.

Roo
Delphi Rules!
 
Yes.

My program step.
1. Load encryption file a
2. file a will be decrypted into file b in random folder
3. My program process something according file b
4. after finis processing. file b will be deleted automatic by program

my problem..
i'am affraid that file b will be copied / read by user,
so i want to copy into random folder.

or how to prevent the user copy or read file b, like denied accesss or etc...

The existing file b is a must and cannot be encrypt !!

Thanks



 
>>> Already done: Windows OS (all versions) will not allow >>> open/copy/delete while your program holds the file open. >>> You can change file attributes to hidden/read-only when >>> closed.

My program step.
1. Load encryption file a
2. file a will be decrypted into file b in random folder
3. My program process something according file b
for example : memo1.lines.loadfromfile(file b)
4. after finis processing. file b will be deleted automatic by program

my problem..
i'am affraid that file b will be copied / read by user,
so i want to copy into random folder.

or how to prevent the user copy or read file b, like denied accesss or etc...

The existing file b is a must and cannot be encrypt !!


Can you give me a sample of the code for this solution.

My Code :
memo1.lines.loadfromfile(file b) -> may be more than 1 minutes when loading file b into memo1, user still can copy file b when the program is running

how to prevent it ?

thanks

 
Could you decrypt the file into a TMemoryStream and keep everything in memory.
 
Provide password to that file. Use password and do decrypt and what ever u want. make sure that open in logically. Unfortunately if user copy this file he cannot to do any thing.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top