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

DeleteProfileW

関数
指定ユーザーのプロファイルを削除する(Unicode版)。
DLLUSERENV.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// USERENV.dll  (Unicode / -W)
#include <windows.h>

BOOL DeleteProfileW(
    LPCWSTR lpSidString,
    LPCWSTR lpProfilePath,   // optional
    LPCWSTR lpComputerName   // optional
);

パラメーター

名前方向
lpSidStringLPCWSTRin
lpProfilePathLPCWSTRinoptional
lpComputerNameLPCWSTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

// USERENV.dll  (Unicode / -W)
#include <windows.h>

BOOL DeleteProfileW(
    LPCWSTR lpSidString,
    LPCWSTR lpProfilePath,   // optional
    LPCWSTR lpComputerName   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USERENV.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool DeleteProfileW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpSidString,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpProfilePath,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string lpComputerName   // LPCWSTR optional
);
<DllImport("USERENV.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DeleteProfileW(
    <MarshalAs(UnmanagedType.LPWStr)> lpSidString As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpProfilePath As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> lpComputerName As String   ' LPCWSTR optional
) As Boolean
End Function
' lpSidString : LPCWSTR
' lpProfilePath : LPCWSTR optional
' lpComputerName : LPCWSTR optional
Declare PtrSafe Function DeleteProfileW Lib "userenv" ( _
    ByVal lpSidString As LongPtr, _
    ByVal lpProfilePath As LongPtr, _
    ByVal lpComputerName As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DeleteProfileW = ctypes.windll.userenv.DeleteProfileW
DeleteProfileW.restype = wintypes.BOOL
DeleteProfileW.argtypes = [
    wintypes.LPCWSTR,  # lpSidString : LPCWSTR
    wintypes.LPCWSTR,  # lpProfilePath : LPCWSTR optional
    wintypes.LPCWSTR,  # lpComputerName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USERENV.dll')
DeleteProfileW = Fiddle::Function.new(
  lib['DeleteProfileW'],
  [
    Fiddle::TYPE_VOIDP,  # lpSidString : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpProfilePath : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpComputerName : LPCWSTR optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "userenv")]
extern "system" {
    fn DeleteProfileW(
        lpSidString: *const u16,  // LPCWSTR
        lpProfilePath: *const u16,  // LPCWSTR optional
        lpComputerName: *const u16  // LPCWSTR optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USERENV.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool DeleteProfileW([MarshalAs(UnmanagedType.LPWStr)] string lpSidString, [MarshalAs(UnmanagedType.LPWStr)] string lpProfilePath, [MarshalAs(UnmanagedType.LPWStr)] string lpComputerName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USERENV_DeleteProfileW' -Namespace Win32 -PassThru
# $api::DeleteProfileW(lpSidString, lpProfilePath, lpComputerName)
#uselib "USERENV.dll"
#func global DeleteProfileW "DeleteProfileW" wptr, wptr, wptr
; DeleteProfileW lpSidString, lpProfilePath, lpComputerName   ; 戻り値は stat
; lpSidString : LPCWSTR -> "wptr"
; lpProfilePath : LPCWSTR optional -> "wptr"
; lpComputerName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USERENV.dll"
#cfunc global DeleteProfileW "DeleteProfileW" wstr, wstr, wstr
; res = DeleteProfileW(lpSidString, lpProfilePath, lpComputerName)
; lpSidString : LPCWSTR -> "wstr"
; lpProfilePath : LPCWSTR optional -> "wstr"
; lpComputerName : LPCWSTR optional -> "wstr"
; BOOL DeleteProfileW(LPCWSTR lpSidString, LPCWSTR lpProfilePath, LPCWSTR lpComputerName)
#uselib "USERENV.dll"
#cfunc global DeleteProfileW "DeleteProfileW" wstr, wstr, wstr
; res = DeleteProfileW(lpSidString, lpProfilePath, lpComputerName)
; lpSidString : LPCWSTR -> "wstr"
; lpProfilePath : LPCWSTR optional -> "wstr"
; lpComputerName : LPCWSTR optional -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	userenv = windows.NewLazySystemDLL("USERENV.dll")
	procDeleteProfileW = userenv.NewProc("DeleteProfileW")
)

// lpSidString (LPCWSTR), lpProfilePath (LPCWSTR optional), lpComputerName (LPCWSTR optional)
r1, _, err := procDeleteProfileW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpSidString))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpProfilePath))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpComputerName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function DeleteProfileW(
  lpSidString: PWideChar;   // LPCWSTR
  lpProfilePath: PWideChar;   // LPCWSTR optional
  lpComputerName: PWideChar   // LPCWSTR optional
): BOOL; stdcall;
  external 'USERENV.dll' name 'DeleteProfileW';
result := DllCall("USERENV\DeleteProfileW"
    , "WStr", lpSidString   ; LPCWSTR
    , "WStr", lpProfilePath   ; LPCWSTR optional
    , "WStr", lpComputerName   ; LPCWSTR optional
    , "Int")   ; return: BOOL
●DeleteProfileW(lpSidString, lpProfilePath, lpComputerName) = DLL("USERENV.dll", "bool DeleteProfileW(char*, char*, char*)")
# 呼び出し: DeleteProfileW(lpSidString, lpProfilePath, lpComputerName)
# lpSidString : LPCWSTR -> "char*"
# lpProfilePath : LPCWSTR optional -> "char*"
# lpComputerName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。