Win32 API 日本語リファレンス
ホームSystem.Shutdown › AbortSystemShutdownW

AbortSystemShutdownW

関数
進行中のシステムシャットダウンを中止する。
DLLADVAPI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL AbortSystemShutdownW(
    LPWSTR lpMachineName   // optional
);

パラメーター

名前方向
lpMachineNameLPWSTRinoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL AbortSystemShutdownW(
    LPWSTR lpMachineName   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool AbortSystemShutdownW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpMachineName   // LPWSTR optional
);
<DllImport("ADVAPI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AbortSystemShutdownW(
    <MarshalAs(UnmanagedType.LPWStr)> lpMachineName As String   ' LPWSTR optional
) As Boolean
End Function
' lpMachineName : LPWSTR optional
Declare PtrSafe Function AbortSystemShutdownW Lib "advapi32" ( _
    ByVal lpMachineName 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

AbortSystemShutdownW = ctypes.windll.advapi32.AbortSystemShutdownW
AbortSystemShutdownW.restype = wintypes.BOOL
AbortSystemShutdownW.argtypes = [
    wintypes.LPCWSTR,  # lpMachineName : LPWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procAbortSystemShutdownW = advapi32.NewProc("AbortSystemShutdownW")
)

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