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

WSManRunShellCommandEx

関数
コマンドIDを指定してリモートコマンドを実行する。
DLLWsmSvc.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

void WSManRunShellCommandEx(
    WSMAN_SHELL_HANDLE shell,
    DWORD flags,
    LPCWSTR commandId,
    LPCWSTR commandLine,
    WSMAN_COMMAND_ARG_SET* args,   // optional
    WSMAN_OPTION_SET* options,   // optional
    WSMAN_SHELL_ASYNC* async,
    WSMAN_COMMAND_HANDLE* command
);

パラメーター

名前方向説明
shellWSMAN_SHELL_HANDLEinコマンドを実行する対象のシェルハンドル。
flagsDWORDinコマンド実行動作を制御するフラグ。
commandIdLPCWSTRin作成するコマンドに割り当てる呼び出し側指定のコマンドID文字列。
commandLineLPCWSTRin実行するコマンドラインを示す文字列。
argsWSMAN_COMMAND_ARG_SET*inoptionalコマンドへ渡す引数セットへのポインター。NULL 可。
optionsWSMAN_OPTION_SET*inoptionalコマンドに渡すオプションセットへのポインター。NULL 可。
asyncWSMAN_SHELL_ASYNC*in完了通知を受け取る非同期コールバック構造体へのポインター。
commandWSMAN_COMMAND_HANDLE*out作成されたコマンドハンドルを受け取るポインター。

戻り値の型: void

各言語での呼び出し定義

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

void WSManRunShellCommandEx(
    WSMAN_SHELL_HANDLE shell,
    DWORD flags,
    LPCWSTR commandId,
    LPCWSTR commandLine,
    WSMAN_COMMAND_ARG_SET* args,   // optional
    WSMAN_OPTION_SET* options,   // optional
    WSMAN_SHELL_ASYNC* async,
    WSMAN_COMMAND_HANDLE* command
);
[DllImport("WsmSvc.dll", ExactSpelling = true)]
static extern void WSManRunShellCommandEx(
    IntPtr shell,   // WSMAN_SHELL_HANDLE
    uint flags,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string commandId,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string commandLine,   // LPCWSTR
    IntPtr args,   // WSMAN_COMMAND_ARG_SET* optional
    IntPtr options,   // WSMAN_OPTION_SET* optional
    IntPtr async,   // WSMAN_SHELL_ASYNC*
    out IntPtr command   // WSMAN_COMMAND_HANDLE* out
);
<DllImport("WsmSvc.dll", ExactSpelling:=True)>
Public Shared Sub WSManRunShellCommandEx(
    shell As IntPtr,   ' WSMAN_SHELL_HANDLE
    flags As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> commandId As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> commandLine As String,   ' LPCWSTR
    args As IntPtr,   ' WSMAN_COMMAND_ARG_SET* optional
    options As IntPtr,   ' WSMAN_OPTION_SET* optional
    async As IntPtr,   ' WSMAN_SHELL_ASYNC*
    <Out> ByRef command As IntPtr   ' WSMAN_COMMAND_HANDLE* out
)
End Sub
' shell : WSMAN_SHELL_HANDLE
' flags : DWORD
' commandId : LPCWSTR
' commandLine : LPCWSTR
' args : WSMAN_COMMAND_ARG_SET* optional
' options : WSMAN_OPTION_SET* optional
' async : WSMAN_SHELL_ASYNC*
' command : WSMAN_COMMAND_HANDLE* out
Declare PtrSafe Sub WSManRunShellCommandEx Lib "wsmsvc" ( _
    ByVal shell As LongPtr, _
    ByVal flags As Long, _
    ByVal commandId As LongPtr, _
    ByVal commandLine As LongPtr, _
    ByVal args As LongPtr, _
    ByVal options As LongPtr, _
    ByVal async As LongPtr, _
    ByRef command As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSManRunShellCommandEx = ctypes.windll.wsmsvc.WSManRunShellCommandEx
WSManRunShellCommandEx.restype = None
WSManRunShellCommandEx.argtypes = [
    ctypes.c_ssize_t,  # shell : WSMAN_SHELL_HANDLE
    wintypes.DWORD,  # flags : DWORD
    wintypes.LPCWSTR,  # commandId : LPCWSTR
    wintypes.LPCWSTR,  # commandLine : LPCWSTR
    ctypes.c_void_p,  # args : WSMAN_COMMAND_ARG_SET* optional
    ctypes.c_void_p,  # options : WSMAN_OPTION_SET* optional
    ctypes.c_void_p,  # async : WSMAN_SHELL_ASYNC*
    ctypes.c_void_p,  # command : WSMAN_COMMAND_HANDLE* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WsmSvc.dll')
WSManRunShellCommandEx = Fiddle::Function.new(
  lib['WSManRunShellCommandEx'],
  [
    Fiddle::TYPE_INTPTR_T,  # shell : WSMAN_SHELL_HANDLE
    -Fiddle::TYPE_INT,  # flags : DWORD
    Fiddle::TYPE_VOIDP,  # commandId : LPCWSTR
    Fiddle::TYPE_VOIDP,  # commandLine : LPCWSTR
    Fiddle::TYPE_VOIDP,  # args : WSMAN_COMMAND_ARG_SET* optional
    Fiddle::TYPE_VOIDP,  # options : WSMAN_OPTION_SET* optional
    Fiddle::TYPE_VOIDP,  # async : WSMAN_SHELL_ASYNC*
    Fiddle::TYPE_VOIDP,  # command : WSMAN_COMMAND_HANDLE* out
  ],
  Fiddle::TYPE_VOID)
#[link(name = "wsmsvc")]
extern "system" {
    fn WSManRunShellCommandEx(
        shell: isize,  // WSMAN_SHELL_HANDLE
        flags: u32,  // DWORD
        commandId: *const u16,  // LPCWSTR
        commandLine: *const u16,  // LPCWSTR
        args: *mut WSMAN_COMMAND_ARG_SET,  // WSMAN_COMMAND_ARG_SET* optional
        options: *mut WSMAN_OPTION_SET,  // WSMAN_OPTION_SET* optional
        async: *mut WSMAN_SHELL_ASYNC,  // WSMAN_SHELL_ASYNC*
        command: *mut isize  // WSMAN_COMMAND_HANDLE* out
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WsmSvc.dll")]
public static extern void WSManRunShellCommandEx(IntPtr shell, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandId, [MarshalAs(UnmanagedType.LPWStr)] string commandLine, IntPtr args, IntPtr options, IntPtr async, out IntPtr command);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WsmSvc_WSManRunShellCommandEx' -Namespace Win32 -PassThru
# $api::WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command)
#uselib "WsmSvc.dll"
#func global WSManRunShellCommandEx "WSManRunShellCommandEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WSManRunShellCommandEx shell, flags, commandId, commandLine, varptr(args), varptr(options), varptr(async), varptr(command)
; shell : WSMAN_SHELL_HANDLE -> "sptr"
; flags : DWORD -> "sptr"
; commandId : LPCWSTR -> "sptr"
; commandLine : LPCWSTR -> "sptr"
; args : WSMAN_COMMAND_ARG_SET* optional -> "sptr"
; options : WSMAN_OPTION_SET* optional -> "sptr"
; async : WSMAN_SHELL_ASYNC* -> "sptr"
; command : WSMAN_COMMAND_HANDLE* out -> "sptr"
出力引数:
#uselib "WsmSvc.dll"
#func global WSManRunShellCommandEx "WSManRunShellCommandEx" sptr, int, wstr, wstr, var, var, var, var
; WSManRunShellCommandEx shell, flags, commandId, commandLine, args, options, async, command
; shell : WSMAN_SHELL_HANDLE -> "sptr"
; flags : DWORD -> "int"
; commandId : LPCWSTR -> "wstr"
; commandLine : LPCWSTR -> "wstr"
; args : WSMAN_COMMAND_ARG_SET* optional -> "var"
; options : WSMAN_OPTION_SET* optional -> "var"
; async : WSMAN_SHELL_ASYNC* -> "var"
; command : WSMAN_COMMAND_HANDLE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void WSManRunShellCommandEx(WSMAN_SHELL_HANDLE shell, DWORD flags, LPCWSTR commandId, LPCWSTR commandLine, WSMAN_COMMAND_ARG_SET* args, WSMAN_OPTION_SET* options, WSMAN_SHELL_ASYNC* async, WSMAN_COMMAND_HANDLE* command)
#uselib "WsmSvc.dll"
#func global WSManRunShellCommandEx "WSManRunShellCommandEx" intptr, int, wstr, wstr, var, var, var, var
; WSManRunShellCommandEx shell, flags, commandId, commandLine, args, options, async, command
; shell : WSMAN_SHELL_HANDLE -> "intptr"
; flags : DWORD -> "int"
; commandId : LPCWSTR -> "wstr"
; commandLine : LPCWSTR -> "wstr"
; args : WSMAN_COMMAND_ARG_SET* optional -> "var"
; options : WSMAN_OPTION_SET* optional -> "var"
; async : WSMAN_SHELL_ASYNC* -> "var"
; command : WSMAN_COMMAND_HANDLE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wsmsvc = windows.NewLazySystemDLL("WsmSvc.dll")
	procWSManRunShellCommandEx = wsmsvc.NewProc("WSManRunShellCommandEx")
)

// shell (WSMAN_SHELL_HANDLE), flags (DWORD), commandId (LPCWSTR), commandLine (LPCWSTR), args (WSMAN_COMMAND_ARG_SET* optional), options (WSMAN_OPTION_SET* optional), async (WSMAN_SHELL_ASYNC*), command (WSMAN_COMMAND_HANDLE* out)
r1, _, err := procWSManRunShellCommandEx.Call(
	uintptr(shell),
	uintptr(flags),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(commandId))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(commandLine))),
	uintptr(args),
	uintptr(options),
	uintptr(async),
	uintptr(command),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure WSManRunShellCommandEx(
  shell: NativeInt;   // WSMAN_SHELL_HANDLE
  flags: DWORD;   // DWORD
  commandId: PWideChar;   // LPCWSTR
  commandLine: PWideChar;   // LPCWSTR
  args: Pointer;   // WSMAN_COMMAND_ARG_SET* optional
  options: Pointer;   // WSMAN_OPTION_SET* optional
  async: Pointer;   // WSMAN_SHELL_ASYNC*
  command: Pointer   // WSMAN_COMMAND_HANDLE* out
); stdcall;
  external 'WsmSvc.dll' name 'WSManRunShellCommandEx';
result := DllCall("WsmSvc\WSManRunShellCommandEx"
    , "Ptr", shell   ; WSMAN_SHELL_HANDLE
    , "UInt", flags   ; DWORD
    , "WStr", commandId   ; LPCWSTR
    , "WStr", commandLine   ; LPCWSTR
    , "Ptr", args   ; WSMAN_COMMAND_ARG_SET* optional
    , "Ptr", options   ; WSMAN_OPTION_SET* optional
    , "Ptr", async   ; WSMAN_SHELL_ASYNC*
    , "Ptr", command   ; WSMAN_COMMAND_HANDLE* out
    , "Int")   ; return: void
●WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command) = DLL("WsmSvc.dll", "int WSManRunShellCommandEx(int, dword, char*, char*, void*, void*, void*, void*)")
# 呼び出し: WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command)
# shell : WSMAN_SHELL_HANDLE -> "int"
# flags : DWORD -> "dword"
# commandId : LPCWSTR -> "char*"
# commandLine : LPCWSTR -> "char*"
# args : WSMAN_COMMAND_ARG_SET* optional -> "void*"
# options : WSMAN_OPTION_SET* optional -> "void*"
# async : WSMAN_SHELL_ASYNC* -> "void*"
# command : WSMAN_COMMAND_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "wsmsvc" fn WSManRunShellCommandEx(
    shell: isize, // WSMAN_SHELL_HANDLE
    flags: u32, // DWORD
    commandId: [*c]const u16, // LPCWSTR
    commandLine: [*c]const u16, // LPCWSTR
    args: [*c]WSMAN_COMMAND_ARG_SET, // WSMAN_COMMAND_ARG_SET* optional
    options: [*c]WSMAN_OPTION_SET, // WSMAN_OPTION_SET* optional
    async: [*c]WSMAN_SHELL_ASYNC, // WSMAN_SHELL_ASYNC*
    command: [*c]isize // WSMAN_COMMAND_HANDLE* out
) callconv(std.os.windows.WINAPI) void;
proc WSManRunShellCommandEx(
    shell: int,  # WSMAN_SHELL_HANDLE
    flags: uint32,  # DWORD
    commandId: WideCString,  # LPCWSTR
    commandLine: WideCString,  # LPCWSTR
    args: ptr WSMAN_COMMAND_ARG_SET,  # WSMAN_COMMAND_ARG_SET* optional
    options: ptr WSMAN_OPTION_SET,  # WSMAN_OPTION_SET* optional
    async: ptr WSMAN_SHELL_ASYNC,  # WSMAN_SHELL_ASYNC*
    command: ptr int  # WSMAN_COMMAND_HANDLE* out
) {.importc: "WSManRunShellCommandEx", stdcall, dynlib: "WsmSvc.dll".}
pragma(lib, "wsmsvc");
extern(Windows)
void WSManRunShellCommandEx(
    ptrdiff_t shell,   // WSMAN_SHELL_HANDLE
    uint flags,   // DWORD
    const(wchar)* commandId,   // LPCWSTR
    const(wchar)* commandLine,   // LPCWSTR
    WSMAN_COMMAND_ARG_SET* args,   // WSMAN_COMMAND_ARG_SET* optional
    WSMAN_OPTION_SET* options,   // WSMAN_OPTION_SET* optional
    WSMAN_SHELL_ASYNC* async,   // WSMAN_SHELL_ASYNC*
    ptrdiff_t* command   // WSMAN_COMMAND_HANDLE* out
);
ccall((:WSManRunShellCommandEx, "WsmSvc.dll"), stdcall, Cvoid,
      (Int, UInt32, Cwstring, Cwstring, Ptr{WSMAN_COMMAND_ARG_SET}, Ptr{WSMAN_OPTION_SET}, Ptr{WSMAN_SHELL_ASYNC}, Ptr{Int}),
      shell, flags, commandId, commandLine, args, options, async, command)
# shell : WSMAN_SHELL_HANDLE -> Int
# flags : DWORD -> UInt32
# commandId : LPCWSTR -> Cwstring
# commandLine : LPCWSTR -> Cwstring
# args : WSMAN_COMMAND_ARG_SET* optional -> Ptr{WSMAN_COMMAND_ARG_SET}
# options : WSMAN_OPTION_SET* optional -> Ptr{WSMAN_OPTION_SET}
# async : WSMAN_SHELL_ASYNC* -> Ptr{WSMAN_SHELL_ASYNC}
# command : WSMAN_COMMAND_HANDLE* out -> Ptr{Int}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
void WSManRunShellCommandEx(
    intptr_t shell,
    uint32_t flags,
    const uint16_t* commandId,
    const uint16_t* commandLine,
    void* args,
    void* options,
    void* async,
    intptr_t* command);
]]
local wsmsvc = ffi.load("wsmsvc")
-- wsmsvc.WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command)
-- shell : WSMAN_SHELL_HANDLE
-- flags : DWORD
-- commandId : LPCWSTR
-- commandLine : LPCWSTR
-- args : WSMAN_COMMAND_ARG_SET* optional
-- options : WSMAN_OPTION_SET* optional
-- async : WSMAN_SHELL_ASYNC*
-- command : WSMAN_COMMAND_HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WsmSvc.dll');
const WSManRunShellCommandEx = lib.func('__stdcall', 'WSManRunShellCommandEx', 'void', ['intptr_t', 'uint32_t', 'str16', 'str16', 'void *', 'void *', 'void *', 'intptr_t *']);
// WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command)
// shell : WSMAN_SHELL_HANDLE -> 'intptr_t'
// flags : DWORD -> 'uint32_t'
// commandId : LPCWSTR -> 'str16'
// commandLine : LPCWSTR -> 'str16'
// args : WSMAN_COMMAND_ARG_SET* optional -> 'void *'
// options : WSMAN_OPTION_SET* optional -> 'void *'
// async : WSMAN_SHELL_ASYNC* -> 'void *'
// command : WSMAN_COMMAND_HANDLE* out -> 'intptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WsmSvc.dll", {
  WSManRunShellCommandEx: { parameters: ["isize", "u32", "buffer", "buffer", "pointer", "pointer", "pointer", "pointer"], result: "void" },
});
// lib.symbols.WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command)
// shell : WSMAN_SHELL_HANDLE -> "isize"
// flags : DWORD -> "u32"
// commandId : LPCWSTR -> "buffer"
// commandLine : LPCWSTR -> "buffer"
// args : WSMAN_COMMAND_ARG_SET* optional -> "pointer"
// options : WSMAN_OPTION_SET* optional -> "pointer"
// async : WSMAN_SHELL_ASYNC* -> "pointer"
// command : WSMAN_COMMAND_HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
void WSManRunShellCommandEx(
    intptr_t shell,
    uint32_t flags,
    const uint16_t* commandId,
    const uint16_t* commandLine,
    void* args,
    void* options,
    void* async,
    intptr_t* command);
C, "WsmSvc.dll");
// $ffi->WSManRunShellCommandEx(shell, flags, commandId, commandLine, args, options, async, command);
// shell : WSMAN_SHELL_HANDLE
// flags : DWORD
// commandId : LPCWSTR
// commandLine : LPCWSTR
// args : WSMAN_COMMAND_ARG_SET* optional
// options : WSMAN_OPTION_SET* optional
// async : WSMAN_SHELL_ASYNC*
// command : WSMAN_COMMAND_HANDLE* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Wsmsvc extends StdCallLibrary {
    Wsmsvc INSTANCE = Native.load("wsmsvc", Wsmsvc.class);
    void WSManRunShellCommandEx(
        long shell,   // WSMAN_SHELL_HANDLE
        int flags,   // DWORD
        WString commandId,   // LPCWSTR
        WString commandLine,   // LPCWSTR
        Pointer args,   // WSMAN_COMMAND_ARG_SET* optional
        Pointer options,   // WSMAN_OPTION_SET* optional
        Pointer async,   // WSMAN_SHELL_ASYNC*
        LongByReference command   // WSMAN_COMMAND_HANDLE* out
    );
}
@[Link("wsmsvc")]
lib LibWsmSvc
  fun WSManRunShellCommandEx = WSManRunShellCommandEx(
    shell : LibC::SSizeT,   # WSMAN_SHELL_HANDLE
    flags : UInt32,   # DWORD
    commandId : UInt16*,   # LPCWSTR
    commandLine : UInt16*,   # LPCWSTR
    args : WSMAN_COMMAND_ARG_SET*,   # WSMAN_COMMAND_ARG_SET* optional
    options : WSMAN_OPTION_SET*,   # WSMAN_OPTION_SET* optional
    async : WSMAN_SHELL_ASYNC*,   # WSMAN_SHELL_ASYNC*
    command : LibC::SSizeT*   # WSMAN_COMMAND_HANDLE* out
  ) : Void
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WSManRunShellCommandExNative = Void Function(IntPtr, Uint32, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef WSManRunShellCommandExDart = void Function(int, int, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final WSManRunShellCommandEx = DynamicLibrary.open('WsmSvc.dll')
    .lookupFunction<WSManRunShellCommandExNative, WSManRunShellCommandExDart>('WSManRunShellCommandEx');
// shell : WSMAN_SHELL_HANDLE -> IntPtr
// flags : DWORD -> Uint32
// commandId : LPCWSTR -> Pointer<Utf16>
// commandLine : LPCWSTR -> Pointer<Utf16>
// args : WSMAN_COMMAND_ARG_SET* optional -> Pointer<Void>
// options : WSMAN_OPTION_SET* optional -> Pointer<Void>
// async : WSMAN_SHELL_ASYNC* -> Pointer<Void>
// command : WSMAN_COMMAND_HANDLE* out -> Pointer<IntPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure WSManRunShellCommandEx(
  shell: NativeInt;   // WSMAN_SHELL_HANDLE
  flags: DWORD;   // DWORD
  commandId: PWideChar;   // LPCWSTR
  commandLine: PWideChar;   // LPCWSTR
  args: Pointer;   // WSMAN_COMMAND_ARG_SET* optional
  options: Pointer;   // WSMAN_OPTION_SET* optional
  async: Pointer;   // WSMAN_SHELL_ASYNC*
  command: Pointer   // WSMAN_COMMAND_HANDLE* out
); stdcall;
  external 'WsmSvc.dll' name 'WSManRunShellCommandEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WSManRunShellCommandEx"
  c_WSManRunShellCommandEx :: CIntPtr -> Word32 -> CWString -> CWString -> Ptr () -> Ptr () -> Ptr () -> Ptr CIntPtr -> IO ()
-- shell : WSMAN_SHELL_HANDLE -> CIntPtr
-- flags : DWORD -> Word32
-- commandId : LPCWSTR -> CWString
-- commandLine : LPCWSTR -> CWString
-- args : WSMAN_COMMAND_ARG_SET* optional -> Ptr ()
-- options : WSMAN_OPTION_SET* optional -> Ptr ()
-- async : WSMAN_SHELL_ASYNC* -> Ptr ()
-- command : WSMAN_COMMAND_HANDLE* out -> Ptr CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wsmanrunshellcommandex =
  foreign "WSManRunShellCommandEx"
    (intptr_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr intptr_t) @-> returning void)
(* shell : WSMAN_SHELL_HANDLE -> intptr_t *)
(* flags : DWORD -> uint32_t *)
(* commandId : LPCWSTR -> (ptr uint16_t) *)
(* commandLine : LPCWSTR -> (ptr uint16_t) *)
(* args : WSMAN_COMMAND_ARG_SET* optional -> (ptr void) *)
(* options : WSMAN_OPTION_SET* optional -> (ptr void) *)
(* async : WSMAN_SHELL_ASYNC* -> (ptr void) *)
(* command : WSMAN_COMMAND_HANDLE* out -> (ptr intptr_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wsmsvc (t "WsmSvc.dll"))
(cffi:use-foreign-library wsmsvc)

(cffi:defcfun ("WSManRunShellCommandEx" wsman-run-shell-command-ex :convention :stdcall) :void
  (shell :int64)   ; WSMAN_SHELL_HANDLE
  (flags :uint32)   ; DWORD
  (command-id (:string :encoding :utf-16le))   ; LPCWSTR
  (command-line (:string :encoding :utf-16le))   ; LPCWSTR
  (args :pointer)   ; WSMAN_COMMAND_ARG_SET* optional
  (options :pointer)   ; WSMAN_OPTION_SET* optional
  (async :pointer)   ; WSMAN_SHELL_ASYNC*
  (command :pointer))   ; WSMAN_COMMAND_HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WSManRunShellCommandEx = Win32::API::More->new('WsmSvc',
    'void WSManRunShellCommandEx(LPARAM shell, DWORD flags, LPCWSTR commandId, LPCWSTR commandLine, LPVOID args, LPVOID options, LPVOID async, LPVOID command)');
# my $ret = $WSManRunShellCommandEx->Call($shell, $flags, $commandId, $commandLine, $args, $options, $async, $command);
# shell : WSMAN_SHELL_HANDLE -> LPARAM
# flags : DWORD -> DWORD
# commandId : LPCWSTR -> LPCWSTR
# commandLine : LPCWSTR -> LPCWSTR
# args : WSMAN_COMMAND_ARG_SET* optional -> LPVOID
# options : WSMAN_OPTION_SET* optional -> LPVOID
# async : WSMAN_SHELL_ASYNC* -> LPVOID
# command : WSMAN_COMMAND_HANDLE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型