Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-05

Getting common documents folders

7 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Glaucos Ginez
to Richard Mace

Hi, you can use GetEnvironmentVariable('LocalAppData')

2015-05-27 14:53 GMT-04:00 Richard Mace :

Show quoted text 18 lines
Hi All, I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) that all users will have read/write access to by default. I think it is CSIDL_COMMON_DOCUMENTS Any ideas how I can code this in Lazarus? Many thanks Richard -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150527/2b3d13c8/attachment.html>

Reply by email

Bart
to Richard Mace: I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) that all users…
Richard Mace wrote
Hi All, I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) that all users will have read/write access to by default. I think it is CSIDL_COMMON_DOCUMENTS

Copied from winlazfileutils.inc (used by LazFieUtils unit):

Procedure InitDLL;
Var
  pathBuf: array[0..MAX_PATH-1] of char;
  pathLength: Integer;
begin
  { Load shfolder.dll using a full path, in order to prevent spoofing
(Mantis #18185)
    Don't bother loading shell32.dll because shfolder.dll itself
redirects SHGetFolderPath
    to shell32.dll whenever possible. }
  pathLength:=GetSystemDirectory(pathBuf, MAX_PATH);
  if (pathLength>0) and (pathLength<MAX_PATH-14) then {
14=length('\shfolder.dll'#0) }
  begin
    StrLCopy(@pathBuf[pathLength],'\shfolder.dll',MAX_PATH-pathLength-1);
    CFGDLLHandle:=LoadLibrary(pathBuf);
    if (CFGDLLHandle0) then
    begin
      Pointer(ShGetFolderPathW):=GetProcAddress(CFGDLLHandle,'SHGetFolderPathW');
      If @ShGetFolderPathW=nil then
      begin
        FreeLibrary(CFGDLLHandle);
        CFGDllHandle:=0;
      end;
    end;
  end;
  If (@ShGetFolderPathW=Nil) then
    Raise Exception.Create('Could not determine SHGetFolderPathW Function');
end;
function GetWindowsSpecialDirW(ID :  Integer) : String;
Var
  APath : Array[0..MAX_PATH] of WideChar;
  WS: WideString;
  Len: SizeInt;
begin
  Result := '';
  if (CFGDLLHandle = 0) then
    InitDLL;
  If (SHGetFolderPathW  Nil) then
  begin
    FillChar(APath{%H-}, SizeOf(APath), #0);
    if SHGetFolderPathW(0,ID or CSIDL_FLAG_CREATE,0,0, at APATH[0]) = S_OK then
    begin
      Len := StrLen(APath);
      SetLength(WS, Len);
      System.Move(APath[0], WS[1], Len * SizeOf(WideChar));
      Result := AppendPathDelim(Utf16ToUtf8(WS));
    end;
  end
  else
    Result := SysToUtf8(GetWindowsSpecialDir(ID)); //<< only needed for Win9x
end;

Bart

Reply by email

Michael Van Canneyt
to Glaucos Ginez: Hi, you can use GetEnvironmentVariable('LocalAppData') 2015-05-27 14:53 GMT-04:00 Richard…
Glaucos Ginez wrote 9 lines
Hi, you can use?GetEnvironmentVariable('LocalAppData') 2015-05-27 14:53 GMT-04:00 Richard Mace : Hi All, I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) that all users will have read/write access to by default. I think it is?CSIDL_COMMON_DOCUMENTS Any ideas how I can code this in Lazarus?

You can use the shfolder unit. It contains the necessary constants and calls to retrieve the location.

Michael.

Reply by email

silvioprog
to Michael Van Canneyt

On Wed, May 27, 2015 at 6:21 PM, Michael Van Canneyt <

Show quoted text 21 lines
wrote: On Wed, 27 May 2015, Glaucos Ginez wrote: Hi, you can use GetEnvironmentVariable('LocalAppData') > > 2015-05-27 14:53 GMT-04:00 Richard Mace : > Hi All, > I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) > that all users will have > read/write access to by default. > I think it is CSIDL_COMMON_DOCUMENTS > > Any ideas how I can code this in Lazarus? > You can use the shfolder unit. It contains the necessary constants and calls to retrieve the location. Michael.

Here in Brazil, on Lazarus-BR group, an member (Joao Marcelo Vaz) sent an very nice tip:

uses
  windirs;

...

  ShowMessage(GetWindowsSpecialDir(CSIDL_COMMON_DOCUMENTS));

=)

Silvio Cl?cio My public projects - github.com/silvioprog -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150527/d420f94f/attachment.html>

Reply by email

Michael Van Canneyt
to silvioprog
silvioprog wrote 31 lines
On Wed, May 27, 2015 at 6:21 PM, Michael Van Canneyt wrote: On Wed, 27 May 2015, Glaucos Ginez wrote: Hi, you can use?GetEnvironmentVariable('LocalAppData') 2015-05-27 14:53 GMT-04:00 Richard Mace : ? ? ? Hi All, I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) that all users will have read/write access to by default. I think it is?CSIDL_COMMON_DOCUMENTS Any ideas how I can code this in Lazarus? You can use the shfolder unit. It contains the necessary constants and calls to retrieve the location. Michael. Here in Brazil, on Lazarus-BR group, an member (Joao Marcelo Vaz) sent an very nice tip: uses ? windirs; ... ??ShowMessage(GetWindowsSpecialDir(CSIDL_COMMON_DOCUMENTS)); =)

Right, I could not find that unit !
I knew there was another one, but could not find it, looking in packages/winunits-base :(

Michael.

Reply by email

Richard Mace
to silvioprog: On Wed, May 27, 2015 at 6:21 PM, Michael Van Canneyt < Here in Brazil, on Lazarus-BR…

Perfect

Thank you

"silvioprog" wrote 47 lines
On Wed, May 27, 2015 at 6:21 PM, Michael Van Canneyt < > wrote: > > > On Wed, 27 May 2015, Glaucos Ginez wrote: > > Hi, you can use GetEnvironmentVariable('LocalAppData') >> >> 2015-05-27 14:53 GMT-04:00 Richard Mace : >> Hi All, >> I need to use/get a common windows folder (in Win XP,Vista,7,8 and 8.1) >> that all users will have >> read/write access to by default. >> I think it is CSIDL_COMMON_DOCUMENTS >> >> Any ideas how I can code this in Lazarus? >> > > You can use the shfolder unit. It contains the necessary constants and > calls to retrieve the location. > > Michael. Here in Brazil, on Lazarus-BR group, an member (Joao Marcelo Vaz) sent an very nice tip: uses windirs; ... ShowMessage(GetWindowsSpecialDir(CSIDL_COMMON_DOCUMENTS)); =) -- Silvio Cl?cio My public projects - github.com/silvioprog -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150528/d3c73f5f/attachment-0001.html>

Reply by email