Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › ChangeAccountPasswordW

ChangeAccountPasswordW

関数
セキュリティパッケージ経由でアカウントのパスワードを変更する(Unicode版)。
DLLSECUR32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

HRESULT ChangeAccountPasswordW(
    WORD* pszPackageName,
    WORD* pszDomainName,
    WORD* pszAccountName,
    WORD* pszOldPassword,
    WORD* pszNewPassword,
    BOOLEAN bImpersonating,
    DWORD dwReserved,
    SecBufferDesc* pOutput
);

パラメーター

名前方向
pszPackageNameWORD*in
pszDomainNameWORD*in
pszAccountNameWORD*in
pszOldPasswordWORD*in
pszNewPasswordWORD*in
bImpersonatingBOOLEANin
dwReservedDWORDin
pOutputSecBufferDesc*inout

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT ChangeAccountPasswordW(
    WORD* pszPackageName,
    WORD* pszDomainName,
    WORD* pszAccountName,
    WORD* pszOldPassword,
    WORD* pszNewPassword,
    BOOLEAN bImpersonating,
    DWORD dwReserved,
    SecBufferDesc* pOutput
);
[DllImport("SECUR32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int ChangeAccountPasswordW(
    ref ushort pszPackageName,   // WORD*
    ref ushort pszDomainName,   // WORD*
    ref ushort pszAccountName,   // WORD*
    ref ushort pszOldPassword,   // WORD*
    ref ushort pszNewPassword,   // WORD*
    [MarshalAs(UnmanagedType.U1)] bool bImpersonating,   // BOOLEAN
    uint dwReserved,   // DWORD
    IntPtr pOutput   // SecBufferDesc* in/out
);
<DllImport("SECUR32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ChangeAccountPasswordW(
    ByRef pszPackageName As UShort,   ' WORD*
    ByRef pszDomainName As UShort,   ' WORD*
    ByRef pszAccountName As UShort,   ' WORD*
    ByRef pszOldPassword As UShort,   ' WORD*
    ByRef pszNewPassword As UShort,   ' WORD*
    <MarshalAs(UnmanagedType.U1)> bImpersonating As Boolean,   ' BOOLEAN
    dwReserved As UInteger,   ' DWORD
    pOutput As IntPtr   ' SecBufferDesc* in/out
) As Integer
End Function
' pszPackageName : WORD*
' pszDomainName : WORD*
' pszAccountName : WORD*
' pszOldPassword : WORD*
' pszNewPassword : WORD*
' bImpersonating : BOOLEAN
' dwReserved : DWORD
' pOutput : SecBufferDesc* in/out
Declare PtrSafe Function ChangeAccountPasswordW Lib "secur32" ( _
    ByRef pszPackageName As Integer, _
    ByRef pszDomainName As Integer, _
    ByRef pszAccountName As Integer, _
    ByRef pszOldPassword As Integer, _
    ByRef pszNewPassword As Integer, _
    ByVal bImpersonating As Byte, _
    ByVal dwReserved As Long, _
    ByVal pOutput 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

ChangeAccountPasswordW = ctypes.windll.secur32.ChangeAccountPasswordW
ChangeAccountPasswordW.restype = ctypes.c_int
ChangeAccountPasswordW.argtypes = [
    ctypes.POINTER(ctypes.c_ushort),  # pszPackageName : WORD*
    ctypes.POINTER(ctypes.c_ushort),  # pszDomainName : WORD*
    ctypes.POINTER(ctypes.c_ushort),  # pszAccountName : WORD*
    ctypes.POINTER(ctypes.c_ushort),  # pszOldPassword : WORD*
    ctypes.POINTER(ctypes.c_ushort),  # pszNewPassword : WORD*
    ctypes.c_byte,  # bImpersonating : BOOLEAN
    wintypes.DWORD,  # dwReserved : DWORD
    ctypes.c_void_p,  # pOutput : SecBufferDesc* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SECUR32.dll')
ChangeAccountPasswordW = Fiddle::Function.new(
  lib['ChangeAccountPasswordW'],
  [
    Fiddle::TYPE_VOIDP,  # pszPackageName : WORD*
    Fiddle::TYPE_VOIDP,  # pszDomainName : WORD*
    Fiddle::TYPE_VOIDP,  # pszAccountName : WORD*
    Fiddle::TYPE_VOIDP,  # pszOldPassword : WORD*
    Fiddle::TYPE_VOIDP,  # pszNewPassword : WORD*
    Fiddle::TYPE_CHAR,  # bImpersonating : BOOLEAN
    -Fiddle::TYPE_INT,  # dwReserved : DWORD
    Fiddle::TYPE_VOIDP,  # pOutput : SecBufferDesc* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "secur32")]
extern "system" {
    fn ChangeAccountPasswordW(
        pszPackageName: *mut u16,  // WORD*
        pszDomainName: *mut u16,  // WORD*
        pszAccountName: *mut u16,  // WORD*
        pszOldPassword: *mut u16,  // WORD*
        pszNewPassword: *mut u16,  // WORD*
        bImpersonating: u8,  // BOOLEAN
        dwReserved: u32,  // DWORD
        pOutput: *mut SecBufferDesc  // SecBufferDesc* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SECUR32.dll", CharSet = CharSet.Unicode)]
public static extern int ChangeAccountPasswordW(ref ushort pszPackageName, ref ushort pszDomainName, ref ushort pszAccountName, ref ushort pszOldPassword, ref ushort pszNewPassword, [MarshalAs(UnmanagedType.U1)] bool bImpersonating, uint dwReserved, IntPtr pOutput);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_ChangeAccountPasswordW' -Namespace Win32 -PassThru
# $api::ChangeAccountPasswordW(pszPackageName, pszDomainName, pszAccountName, pszOldPassword, pszNewPassword, bImpersonating, dwReserved, pOutput)
#uselib "SECUR32.dll"
#func global ChangeAccountPasswordW "ChangeAccountPasswordW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; ChangeAccountPasswordW varptr(pszPackageName), varptr(pszDomainName), varptr(pszAccountName), varptr(pszOldPassword), varptr(pszNewPassword), bImpersonating, dwReserved, varptr(pOutput)   ; 戻り値は stat
; pszPackageName : WORD* -> "wptr"
; pszDomainName : WORD* -> "wptr"
; pszAccountName : WORD* -> "wptr"
; pszOldPassword : WORD* -> "wptr"
; pszNewPassword : WORD* -> "wptr"
; bImpersonating : BOOLEAN -> "wptr"
; dwReserved : DWORD -> "wptr"
; pOutput : SecBufferDesc* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SECUR32.dll"
#cfunc global ChangeAccountPasswordW "ChangeAccountPasswordW" var, var, var, var, var, int, int, var
; res = ChangeAccountPasswordW(pszPackageName, pszDomainName, pszAccountName, pszOldPassword, pszNewPassword, bImpersonating, dwReserved, pOutput)
; pszPackageName : WORD* -> "var"
; pszDomainName : WORD* -> "var"
; pszAccountName : WORD* -> "var"
; pszOldPassword : WORD* -> "var"
; pszNewPassword : WORD* -> "var"
; bImpersonating : BOOLEAN -> "int"
; dwReserved : DWORD -> "int"
; pOutput : SecBufferDesc* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT ChangeAccountPasswordW(WORD* pszPackageName, WORD* pszDomainName, WORD* pszAccountName, WORD* pszOldPassword, WORD* pszNewPassword, BOOLEAN bImpersonating, DWORD dwReserved, SecBufferDesc* pOutput)
#uselib "SECUR32.dll"
#cfunc global ChangeAccountPasswordW "ChangeAccountPasswordW" var, var, var, var, var, int, int, var
; res = ChangeAccountPasswordW(pszPackageName, pszDomainName, pszAccountName, pszOldPassword, pszNewPassword, bImpersonating, dwReserved, pOutput)
; pszPackageName : WORD* -> "var"
; pszDomainName : WORD* -> "var"
; pszAccountName : WORD* -> "var"
; pszOldPassword : WORD* -> "var"
; pszNewPassword : WORD* -> "var"
; bImpersonating : BOOLEAN -> "int"
; dwReserved : DWORD -> "int"
; pOutput : SecBufferDesc* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procChangeAccountPasswordW = secur32.NewProc("ChangeAccountPasswordW")
)

// pszPackageName (WORD*), pszDomainName (WORD*), pszAccountName (WORD*), pszOldPassword (WORD*), pszNewPassword (WORD*), bImpersonating (BOOLEAN), dwReserved (DWORD), pOutput (SecBufferDesc* in/out)
r1, _, err := procChangeAccountPasswordW.Call(
	uintptr(pszPackageName),
	uintptr(pszDomainName),
	uintptr(pszAccountName),
	uintptr(pszOldPassword),
	uintptr(pszNewPassword),
	uintptr(bImpersonating),
	uintptr(dwReserved),
	uintptr(pOutput),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ChangeAccountPasswordW(
  pszPackageName: Pointer;   // WORD*
  pszDomainName: Pointer;   // WORD*
  pszAccountName: Pointer;   // WORD*
  pszOldPassword: Pointer;   // WORD*
  pszNewPassword: Pointer;   // WORD*
  bImpersonating: ByteBool;   // BOOLEAN
  dwReserved: DWORD;   // DWORD
  pOutput: Pointer   // SecBufferDesc* in/out
): Integer; stdcall;
  external 'SECUR32.dll' name 'ChangeAccountPasswordW';
result := DllCall("SECUR32\ChangeAccountPasswordW"
    , "Ptr", pszPackageName   ; WORD*
    , "Ptr", pszDomainName   ; WORD*
    , "Ptr", pszAccountName   ; WORD*
    , "Ptr", pszOldPassword   ; WORD*
    , "Ptr", pszNewPassword   ; WORD*
    , "Char", bImpersonating   ; BOOLEAN
    , "UInt", dwReserved   ; DWORD
    , "Ptr", pOutput   ; SecBufferDesc* in/out
    , "Int")   ; return: HRESULT
●ChangeAccountPasswordW(pszPackageName, pszDomainName, pszAccountName, pszOldPassword, pszNewPassword, bImpersonating, dwReserved, pOutput) = DLL("SECUR32.dll", "int ChangeAccountPasswordW(void*, void*, void*, void*, void*, byte, dword, void*)")
# 呼び出し: ChangeAccountPasswordW(pszPackageName, pszDomainName, pszAccountName, pszOldPassword, pszNewPassword, bImpersonating, dwReserved, pOutput)
# pszPackageName : WORD* -> "void*"
# pszDomainName : WORD* -> "void*"
# pszAccountName : WORD* -> "void*"
# pszOldPassword : WORD* -> "void*"
# pszNewPassword : WORD* -> "void*"
# bImpersonating : BOOLEAN -> "byte"
# dwReserved : DWORD -> "dword"
# pOutput : SecBufferDesc* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。