No Admin best HDD place to copy a folder in all windows!

Please discuss general Delphi programming topics here.

No Admin best HDD place to copy a folder in all windows!

Postby sarian » March 23rd, 2013, 8:45 pm

Hi all,
I am developing a program which needs to copy a folder and some files somewhere in HDD.
I have to notice the below issues:
1- The user may have Windows Xp, Vista, 7 and 8, so the solution should work with all versions of windows.
2- I prefer somewhere in drive C, because I worry that the user may have only one drive.
3- I don't like someone easily find my folder and extract the data, so the folder should be hidden and at the most possible inattention place, lets say in windows or program files directory if possible.
4- My user might not be administrator, so the program should have permission to copy there, so I think I should forget about windows and program files directory which may need administrator permission, so may be I have to place it at C:\My folder, but I am still not sure if it works with all windows.

What is the best place in your opinion?

Thanks!
Reza
sarian
Active Member
Active Member
 
Posts: 5
Joined: October 26th, 2012, 10:01 am

Re: No Admin best HDD place to copy a folder in all windows!

Postby sarian » March 24th, 2013, 7:11 pm

I found the solution.
The best place is application data folder. which can be recall with "CSIDL_LOCAL_APPDATA"


IN: Windows XP, Windows Server 2003, Windows Server 2003 R2: C:\Documents and Settings\UserName\Local Settings\Application Data

IN: Windows 8, Windows Server 2012, Windows 7, Windows Vista, Windows Server 2008, Windows Server 2008 R2: C:\Users\UserName\AppData\Local

This code works, only need to add ShlObj unit in your uses list

// function to ask windows for a special folder and convert the "windows string" into

// Delphi string

function GetSpecialFolder(const ASpecialFolderID: Integer): string;

var

vSFolder : pItemIDList;

vSpecialPath : array[0..MAX_PATH] of Char;

begin

SHGetSpecialFolderLocation(0, ASpecialFolderID, vSFolder);

SHGetPathFromIDList(vSFolder, vSpecialPath);

Result := StrPas(vSpecialPath);

end;


// now the constants that we must pass to windows to specify which special folder we want

const

// constant to get LOCAL_APPDATA folder

CSIDL_APPDATA = $001A;

// constant to get LOCAL_APPDATA folder

CSIDL_LOCAL_APPDATA = $001C;

// constant to get COMMON_APPDATA folder

CSIDL_COMMON_APPDATA = $0023;

// constant to get COMMON_DOCUMENTS folder

CSIDL_COMMON_DOCUMENTS = $002E;

// constant to get MY DOCUMENTS folder

CSIDL_PERSONAL = $0005;


// example how to use the GetSpecialFolder function and the constants

function GetLocalAppDataFolder: string;

begin

Result := GetSpecialFolder(CSIDL_LOCAL_APPDATA);

end;
sarian
Active Member
Active Member
 
Posts: 5
Joined: October 26th, 2012, 10:01 am


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron