GetProfilesDirectory (userenv)
Last changed: -45.48.65.144

.
Summary
Determines the profiles directory on the current machine. ie c:\Users on Vista and later

C# Signature:

[DllImport("userenv.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern bool GetProfilesDirectory(StringBuilder path, ref int size);

Sample Code:

   StringBuilder path = new StringBuilder(4*1024);
   int size = path.Capacity;
   if (GetProfilesDirectory(path, ref size) )
   {
       ... use path value, size contains length...
   }

Sample code using gcc in Cygwin as a GUI w/ ICON executable

Needs cygwin system set up and installed. To build:

Save this file in usrprof.c

copy a file containing an icon, say bfe.ico, to cwd

echo 'this icon bfe.ico' > this.rc

windres this.rc Ocoffothis.res

gcc –Wall –Wl,– –enable–stdcall–fixup –mnop–fun–dllimport –mwindows this.res usrprof.c /cygdrive/c/windows/system32/userenv.dll

400gcc Wall0000-0000C00000046

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <windows.h>
#include <w32api/windows.h>
#include <w32api/userenv.h>

int main() {
    DWORD size = 4*1024;
    char *path = malloc(size);
    if (GetProfilesDirectory(path, &size) ) {
        printf("%d %s\n", (int)size, path);
        MessageBox(NULL, path, "GetProfilesDirectory()", MB_OK);
    }
    return 0;
}

Contributed by John Refling

Documentation