using:

char username[255+1];
DWORD username_len = 255+1;
GetUserName(username, &username_len);

i get the actual user name.

but how can i get the program folder name for execute a program?
the '%ProgramFiles(x86)%' on folder name string is ignored :(

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    //Get Program Files Location.
    char buffer[256];
    ExpandEnvironmentStrings("%ProgramFiles(x86)%", buffer, 256);
    std::cout<<buffer<<"\n";

    //Get Current Executable Location.
    GetCurrentDirectory(256, buffer);
    std::cout<<buffer<<"\n";
    return 0;
}

after several searchs i found the SHGetFolderPath(): https://msdn.microsoft.com/en-us/library/windows/desktop/bb762181%28v=vs.85%29.aspx

heres a sample:

char programs[255+1];
    SHGetFolderPath(NULL,CSIDL_PROGRAM_FILESX86 ,NULL,SHGFP_TYPE_DEFAULT,programs);
    MessageBox(NULL,programs,"hi",0);

Only some CSIDL values are supported, including the following:

CSIDL_ADMINTOOLS
CSIDL_APPDATA
CSIDL_COMMON_ADMINTOOLS
CSIDL_COMMON_APPDATA
CSIDL_COMMON_DOCUMENTS
CSIDL_COOKIES
CSIDL_FLAG_CREATE
CSIDL_FLAG_DONT_VERIFY
CSIDL_HISTORY
CSIDL_INTERNET_CACHE
CSIDL_LOCAL_APPDATA
CSIDL_MYPICTURES
CSIDL_PERSONAL
CSIDL_PROGRAM_FILES
CSIDL_PROGRAM_FILES_COMMON
CSIDL_SYSTEM
CSIDL_WINDOWS

anotherthing: the GetUserName() give us the user name:

char username[255+1];
    DWORD username_len = 255+1;
    GetUserName(username, &username_len);
    MessageBox(NULL,username,"hi",0);

thanks to all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.