ユーザ・プロファイルのルートパス名には次のようなものがあります。(戻る)
- すべてのユーザのルートパス名(GetProfilesDirectory)
- 全ユーザのルートパス名(GetAllUsersProfileDirectory)
- 既定ユーザのルートパス名(GetDefaultUserProfileDirectory)
プロトタイプ宣言
BOOL GetProfilesDirectory( LPTSTR lpBuff, // バッファ領域 LPDWORD lpSize // バッファ容量のポインタ ); BOOL GetAllUsersProfileDirectory( LPTSTR lpBuff, // バッファ領域 LPDWORD lpSize // バッファ容量のポインタ ); BOOL GetDefaultUserProfileDirectory( LPTSTR lpBuff, // バッファ領域 LPDWORD lpSize // バッファ容量のポインタ );
サンプル
#include <stdio.h> #include <windows.h> #include <userenv.h> // メイン関数 int main( void ) { TCHAR szPath[ 3 ][ MAX_PATH ]; DWORD dwSize; // ユーザ・プロファイルの取得 dwSize = MAX_PATH; GetProfilesDirectory( szPath[0], &dwSize ); dwSize = MAX_PATH; GetAllUsersProfileDirectory( szPath[1], &dwSize ); dwSize = MAX_PATH; GetDefaultUserProfileDirectory( szPath[2], &dwSize ); // ユーザ・プロファイルの情報 printf( TEXT("ユーザ・プロファイルの情報\n") ); printf( TEXT("\n") ); printf( TEXT("すべてのユーザのルートパス名:%s\n"), szPath[0] ); printf( TEXT(" 全ユーザのルートパス名:%s\n"), szPath[1] ); printf( TEXT(" 既定ユーザのルートパス名:%s\n"), szPath[2] ); return 0; }
実行結果
ユーザ・プロファイルの情報 すべてのユーザのルートパス名:C:\Documents and Settings 全ユーザのルートパス名:C:\Documents and Settings\All Users 既定ユーザのルートパス名:C:\Documents and Settings\Default User
- 上記の実行結果はWindows XP Home SP2の環境です。
注意事項
- バッファ容量のサイズは DWORD 型へのポインタを渡します。
- UserEnv.h ヘッダをインクルードして UserEnv.Lib をインポートして下さい。
関連記事
- システム・ディレクトリの取得
- ユーザ・プロファイルの取得
- ディレクトリの作成/削除
※コメント投稿者のブログIDはブログ作成者のみに通知されます