Windows User Name lazarus / 34-Windows ---------------------------------------------------------------------- Newmann · 2011-02-16 00:34 Hey guys, I'm quite new to Lazarus, but I like it quite a bit. Just a quick question- what is the easiest way to get the current user(name) of the person and/or his folders (eg My Documents, Application Settings, etc). Most of my Delphi code I could simply copy & paste over from my older projects, but to retrieve this info seems to be a bit harder than I though...or am I missing something somewhere? Please help, thanks ---------------------------------------------------------------------- captian jaster · 2011-02-16 01:06 Sysutils can give you the GetUserDir function. Windows unit gives you GetUserName function.. Something like Code: [Select]Uses  Windows;  ... Function GetUsrName:String; Var  Buf : PChar; Const  MaxDBuf:Dword = 256; begin   if GetUserDir(Buf,MaxDBuf)then    Result := StrPas(Buf) Else Result := ''; end; Should work ---------------------------------------------------------------------- Newmann · 2011-02-16 10:13 It gives me the following error: Quotemain.pas(59,28) Error: Wrong number of parameters specified for call to "GetUserDir" I tried this one as well last night and it didn't work- only I was trying to call from "ShellAPI", not "Windows". I tried Ctrl+Click the function to see in the source what it want's to pass to it- no luck there either. The other one I tried was: Code: [Select]function GetCurrentUserName : string; const   cnMaxUserNameLen = 254; var   sUserName     : string;   dwUserNameLen : DWord; begin   dwUserNameLen := cnMaxUserNameLen-1;   SetLength( sUserName, cnMaxUserNameLen );   GetUserName(     PChar( sUserName ),     dwUserNameLen );   SetLength( sUserName, dwUserNameLen );   Result := sUserName; end; However, this one worked 100% this time- so I think it's safe to say that the main problem was the fact that I used ShellAPI instead of Windows. Unfortunately this has now caused another annoying problem...everywhere I used the "Beep" procedure it gives me the following error: Quotemain.pas(213,3) Error: Wrong number of parameters specified for call to "Beep" I really don't know what the compiler's problem is... ---------------------------------------------------------------------- theo · 2011-02-16 10:18 http://www.freepascal.org/docs-html/rtl/sysutils/getuserdir.html ---------------------------------------------------------------------- Newmann · 2011-02-17 00:39 Beautiful!!!! Was actually exactly what I needed... thanks Theo! When I posted the message I forgot that the path to this folder not the same in WinXP and Win7...