Win32 API 日本語リファレンス
ホームUI.Shell › CreateProfile

CreateProfile

関数
指定したユーザー用の新しいプロファイルを作成する。
DLLUSERENV.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// USERENV.dll
#include <windows.h>

HRESULT CreateProfile(
    LPCWSTR pszUserSid,
    LPCWSTR pszUserName,
    LPWSTR pszProfilePath,
    DWORD cchProfilePath
);

パラメーター

名前方向
pszUserSidLPCWSTRin
pszUserNameLPCWSTRin
pszProfilePathLPWSTRout
cchProfilePathDWORDin

戻り値の型: HRESULT

各言語での呼び出し定義

// USERENV.dll
#include <windows.h>

HRESULT CreateProfile(
    LPCWSTR pszUserSid,
    LPCWSTR pszUserName,
    LPWSTR pszProfilePath,
    DWORD cchProfilePath
);
[DllImport("USERENV.dll", ExactSpelling = true)]
static extern int CreateProfile(
    [MarshalAs(UnmanagedType.LPWStr)] string pszUserSid,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string pszUserName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszProfilePath,   // LPWSTR out
    uint cchProfilePath   // DWORD
);
<DllImport("USERENV.dll", ExactSpelling:=True)>
Public Shared Function CreateProfile(
    <MarshalAs(UnmanagedType.LPWStr)> pszUserSid As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszUserName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> pszProfilePath As System.Text.StringBuilder,   ' LPWSTR out
    cchProfilePath As UInteger   ' DWORD
) As Integer
End Function
' pszUserSid : LPCWSTR
' pszUserName : LPCWSTR
' pszProfilePath : LPWSTR out
' cchProfilePath : DWORD
Declare PtrSafe Function CreateProfile Lib "userenv" ( _
    ByVal pszUserSid As LongPtr, _
    ByVal pszUserName As LongPtr, _
    ByVal pszProfilePath As LongPtr, _
    ByVal cchProfilePath As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateProfile = ctypes.windll.userenv.CreateProfile
CreateProfile.restype = ctypes.c_int
CreateProfile.argtypes = [
    wintypes.LPCWSTR,  # pszUserSid : LPCWSTR
    wintypes.LPCWSTR,  # pszUserName : LPCWSTR
    wintypes.LPWSTR,  # pszProfilePath : LPWSTR out
    wintypes.DWORD,  # cchProfilePath : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USERENV.dll')
CreateProfile = Fiddle::Function.new(
  lib['CreateProfile'],
  [
    Fiddle::TYPE_VOIDP,  # pszUserSid : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszUserName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # pszProfilePath : LPWSTR out
    -Fiddle::TYPE_INT,  # cchProfilePath : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "userenv")]
extern "system" {
    fn CreateProfile(
        pszUserSid: *const u16,  // LPCWSTR
        pszUserName: *const u16,  // LPCWSTR
        pszProfilePath: *mut u16,  // LPWSTR out
        cchProfilePath: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USERENV.dll")]
public static extern int CreateProfile([MarshalAs(UnmanagedType.LPWStr)] string pszUserSid, [MarshalAs(UnmanagedType.LPWStr)] string pszUserName, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder pszProfilePath, uint cchProfilePath);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USERENV_CreateProfile' -Namespace Win32 -PassThru
# $api::CreateProfile(pszUserSid, pszUserName, pszProfilePath, cchProfilePath)
#uselib "USERENV.dll"
#func global CreateProfile "CreateProfile" sptr, sptr, sptr, sptr
; CreateProfile pszUserSid, pszUserName, varptr(pszProfilePath), cchProfilePath   ; 戻り値は stat
; pszUserSid : LPCWSTR -> "sptr"
; pszUserName : LPCWSTR -> "sptr"
; pszProfilePath : LPWSTR out -> "sptr"
; cchProfilePath : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USERENV.dll"
#cfunc global CreateProfile "CreateProfile" wstr, wstr, var, int
; res = CreateProfile(pszUserSid, pszUserName, pszProfilePath, cchProfilePath)
; pszUserSid : LPCWSTR -> "wstr"
; pszUserName : LPCWSTR -> "wstr"
; pszProfilePath : LPWSTR out -> "var"
; cchProfilePath : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT CreateProfile(LPCWSTR pszUserSid, LPCWSTR pszUserName, LPWSTR pszProfilePath, DWORD cchProfilePath)
#uselib "USERENV.dll"
#cfunc global CreateProfile "CreateProfile" wstr, wstr, var, int
; res = CreateProfile(pszUserSid, pszUserName, pszProfilePath, cchProfilePath)
; pszUserSid : LPCWSTR -> "wstr"
; pszUserName : LPCWSTR -> "wstr"
; pszProfilePath : LPWSTR out -> "var"
; cchProfilePath : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	userenv = windows.NewLazySystemDLL("USERENV.dll")
	procCreateProfile = userenv.NewProc("CreateProfile")
)

// pszUserSid (LPCWSTR), pszUserName (LPCWSTR), pszProfilePath (LPWSTR out), cchProfilePath (DWORD)
r1, _, err := procCreateProfile.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszUserSid))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszUserName))),
	uintptr(pszProfilePath),
	uintptr(cchProfilePath),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CreateProfile(
  pszUserSid: PWideChar;   // LPCWSTR
  pszUserName: PWideChar;   // LPCWSTR
  pszProfilePath: PWideChar;   // LPWSTR out
  cchProfilePath: DWORD   // DWORD
): Integer; stdcall;
  external 'USERENV.dll' name 'CreateProfile';
result := DllCall("USERENV\CreateProfile"
    , "WStr", pszUserSid   ; LPCWSTR
    , "WStr", pszUserName   ; LPCWSTR
    , "Ptr", pszProfilePath   ; LPWSTR out
    , "UInt", cchProfilePath   ; DWORD
    , "Int")   ; return: HRESULT
●CreateProfile(pszUserSid, pszUserName, pszProfilePath, cchProfilePath) = DLL("USERENV.dll", "int CreateProfile(char*, char*, char*, dword)")
# 呼び出し: CreateProfile(pszUserSid, pszUserName, pszProfilePath, cchProfilePath)
# pszUserSid : LPCWSTR -> "char*"
# pszUserName : LPCWSTR -> "char*"
# pszProfilePath : LPWSTR out -> "char*"
# cchProfilePath : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。