ホーム › System.RemoteManagement › WSManRunShellCommand
WSManRunShellCommand
関数リモートシェルでコマンドを非同期に実行する。
シグネチャ
// WsmSvc.dll
#include <windows.h>
void WSManRunShellCommand(
WSMAN_SHELL_HANDLE shell,
DWORD flags,
LPCWSTR commandLine,
WSMAN_COMMAND_ARG_SET* args, // optional
WSMAN_OPTION_SET* options, // optional
WSMAN_SHELL_ASYNC* async,
WSMAN_COMMAND_HANDLE* command
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| shell | WSMAN_SHELL_HANDLE | in | コマンドを実行する対象のシェルハンドル。 |
| flags | DWORD | in | コマンド実行動作を制御するフラグ。 |
| commandLine | LPCWSTR | in | 実行するコマンドラインを示す文字列。 |
| args | WSMAN_COMMAND_ARG_SET* | inoptional | コマンドへ渡す引数セットへのポインター。NULL 可。 |
| options | WSMAN_OPTION_SET* | inoptional | コマンドに渡すオプションセットへのポインター。NULL 可。 |
| async | WSMAN_SHELL_ASYNC* | in | 完了通知を受け取る非同期コールバック構造体へのポインター。 |
| command | WSMAN_COMMAND_HANDLE* | out | 作成されたコマンドハンドルを受け取るポインター。 |
戻り値の型: void
各言語での呼び出し定義
// WsmSvc.dll
#include <windows.h>
void WSManRunShellCommand(
WSMAN_SHELL_HANDLE shell,
DWORD flags,
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 WSManRunShellCommand(
IntPtr shell, // WSMAN_SHELL_HANDLE
uint flags, // DWORD
[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 WSManRunShellCommand(
shell As IntPtr, ' WSMAN_SHELL_HANDLE
flags As UInteger, ' DWORD
<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
' 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 WSManRunShellCommand Lib "wsmsvc" ( _
ByVal shell As LongPtr, _
ByVal flags As Long, _
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
WSManRunShellCommand = ctypes.windll.wsmsvc.WSManRunShellCommand
WSManRunShellCommand.restype = None
WSManRunShellCommand.argtypes = [
ctypes.c_ssize_t, # shell : WSMAN_SHELL_HANDLE
wintypes.DWORD, # flags : DWORD
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')
WSManRunShellCommand = Fiddle::Function.new(
lib['WSManRunShellCommand'],
[
Fiddle::TYPE_INTPTR_T, # shell : WSMAN_SHELL_HANDLE
-Fiddle::TYPE_INT, # flags : DWORD
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 WSManRunShellCommand(
shell: isize, // WSMAN_SHELL_HANDLE
flags: u32, // DWORD
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 WSManRunShellCommand(IntPtr shell, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandLine, IntPtr args, IntPtr options, IntPtr async, out IntPtr command);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WsmSvc_WSManRunShellCommand' -Namespace Win32 -PassThru
# $api::WSManRunShellCommand(shell, flags, commandLine, args, options, async, command)#uselib "WsmSvc.dll"
#func global WSManRunShellCommand "WSManRunShellCommand" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WSManRunShellCommand shell, flags, commandLine, varptr(args), varptr(options), varptr(async), varptr(command)
; shell : WSMAN_SHELL_HANDLE -> "sptr"
; flags : DWORD -> "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 WSManRunShellCommand "WSManRunShellCommand" sptr, int, wstr, var, var, var, var ; WSManRunShellCommand shell, flags, commandLine, args, options, async, command ; shell : WSMAN_SHELL_HANDLE -> "sptr" ; flags : DWORD -> "int" ; 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 方式にも切替可。#uselib "WsmSvc.dll" #func global WSManRunShellCommand "WSManRunShellCommand" sptr, int, wstr, sptr, sptr, sptr, sptr ; WSManRunShellCommand shell, flags, commandLine, varptr(args), varptr(options), varptr(async), varptr(command) ; shell : WSMAN_SHELL_HANDLE -> "sptr" ; flags : DWORD -> "int" ; commandLine : LPCWSTR -> "wstr" ; args : WSMAN_COMMAND_ARG_SET* optional -> "sptr" ; options : WSMAN_OPTION_SET* optional -> "sptr" ; async : WSMAN_SHELL_ASYNC* -> "sptr" ; command : WSMAN_COMMAND_HANDLE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void WSManRunShellCommand(WSMAN_SHELL_HANDLE shell, DWORD flags, LPCWSTR commandLine, WSMAN_COMMAND_ARG_SET* args, WSMAN_OPTION_SET* options, WSMAN_SHELL_ASYNC* async, WSMAN_COMMAND_HANDLE* command) #uselib "WsmSvc.dll" #func global WSManRunShellCommand "WSManRunShellCommand" intptr, int, wstr, var, var, var, var ; WSManRunShellCommand shell, flags, commandLine, args, options, async, command ; shell : WSMAN_SHELL_HANDLE -> "intptr" ; flags : DWORD -> "int" ; 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 WSManRunShellCommand(WSMAN_SHELL_HANDLE shell, DWORD flags, LPCWSTR commandLine, WSMAN_COMMAND_ARG_SET* args, WSMAN_OPTION_SET* options, WSMAN_SHELL_ASYNC* async, WSMAN_COMMAND_HANDLE* command) #uselib "WsmSvc.dll" #func global WSManRunShellCommand "WSManRunShellCommand" intptr, int, wstr, intptr, intptr, intptr, intptr ; WSManRunShellCommand shell, flags, commandLine, varptr(args), varptr(options), varptr(async), varptr(command) ; shell : WSMAN_SHELL_HANDLE -> "intptr" ; flags : DWORD -> "int" ; commandLine : LPCWSTR -> "wstr" ; args : WSMAN_COMMAND_ARG_SET* optional -> "intptr" ; options : WSMAN_OPTION_SET* optional -> "intptr" ; async : WSMAN_SHELL_ASYNC* -> "intptr" ; command : WSMAN_COMMAND_HANDLE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsmsvc = windows.NewLazySystemDLL("WsmSvc.dll")
procWSManRunShellCommand = wsmsvc.NewProc("WSManRunShellCommand")
)
// shell (WSMAN_SHELL_HANDLE), flags (DWORD), commandLine (LPCWSTR), args (WSMAN_COMMAND_ARG_SET* optional), options (WSMAN_OPTION_SET* optional), async (WSMAN_SHELL_ASYNC*), command (WSMAN_COMMAND_HANDLE* out)
r1, _, err := procWSManRunShellCommand.Call(
uintptr(shell),
uintptr(flags),
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 // voidprocedure WSManRunShellCommand(
shell: NativeInt; // WSMAN_SHELL_HANDLE
flags: DWORD; // DWORD
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 'WSManRunShellCommand';result := DllCall("WsmSvc\WSManRunShellCommand"
, "Ptr", shell ; WSMAN_SHELL_HANDLE
, "UInt", flags ; DWORD
, "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●WSManRunShellCommand(shell, flags, commandLine, args, options, async, command) = DLL("WsmSvc.dll", "int WSManRunShellCommand(int, dword, char*, void*, void*, void*, void*)")
# 呼び出し: WSManRunShellCommand(shell, flags, commandLine, args, options, async, command)
# shell : WSMAN_SHELL_HANDLE -> "int"
# flags : DWORD -> "dword"
# 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 WSManRunShellCommand(
shell: isize, // WSMAN_SHELL_HANDLE
flags: u32, // DWORD
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 WSManRunShellCommand(
shell: int, # WSMAN_SHELL_HANDLE
flags: uint32, # DWORD
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: "WSManRunShellCommand", stdcall, dynlib: "WsmSvc.dll".}pragma(lib, "wsmsvc");
extern(Windows)
void WSManRunShellCommand(
ptrdiff_t shell, // WSMAN_SHELL_HANDLE
uint flags, // DWORD
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((:WSManRunShellCommand, "WsmSvc.dll"), stdcall, Cvoid,
(Int, UInt32, Cwstring, Ptr{WSMAN_COMMAND_ARG_SET}, Ptr{WSMAN_OPTION_SET}, Ptr{WSMAN_SHELL_ASYNC}, Ptr{Int}),
shell, flags, commandLine, args, options, async, command)
# shell : WSMAN_SHELL_HANDLE -> Int
# flags : DWORD -> UInt32
# 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 WSManRunShellCommand(
intptr_t shell,
uint32_t flags,
const uint16_t* commandLine,
void* args,
void* options,
void* async,
intptr_t* command);
]]
local wsmsvc = ffi.load("wsmsvc")
-- wsmsvc.WSManRunShellCommand(shell, flags, commandLine, args, options, async, command)
-- shell : WSMAN_SHELL_HANDLE
-- flags : DWORD
-- 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 WSManRunShellCommand = lib.func('__stdcall', 'WSManRunShellCommand', 'void', ['intptr_t', 'uint32_t', 'str16', 'void *', 'void *', 'void *', 'intptr_t *']);
// WSManRunShellCommand(shell, flags, commandLine, args, options, async, command)
// shell : WSMAN_SHELL_HANDLE -> 'intptr_t'
// flags : DWORD -> 'uint32_t'
// 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", {
WSManRunShellCommand: { parameters: ["isize", "u32", "buffer", "pointer", "pointer", "pointer", "pointer"], result: "void" },
});
// lib.symbols.WSManRunShellCommand(shell, flags, commandLine, args, options, async, command)
// shell : WSMAN_SHELL_HANDLE -> "isize"
// flags : DWORD -> "u32"
// 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 WSManRunShellCommand(
intptr_t shell,
uint32_t flags,
const uint16_t* commandLine,
void* args,
void* options,
void* async,
intptr_t* command);
C, "WsmSvc.dll");
// $ffi->WSManRunShellCommand(shell, flags, commandLine, args, options, async, command);
// shell : WSMAN_SHELL_HANDLE
// flags : DWORD
// 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 WSManRunShellCommand(
long shell, // WSMAN_SHELL_HANDLE
int flags, // DWORD
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 WSManRunShellCommand = WSManRunShellCommand(
shell : LibC::SSizeT, # WSMAN_SHELL_HANDLE
flags : UInt32, # DWORD
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 WSManRunShellCommandNative = Void Function(IntPtr, Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
typedef WSManRunShellCommandDart = void Function(int, int, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<IntPtr>);
final WSManRunShellCommand = DynamicLibrary.open('WsmSvc.dll')
.lookupFunction<WSManRunShellCommandNative, WSManRunShellCommandDart>('WSManRunShellCommand');
// shell : WSMAN_SHELL_HANDLE -> IntPtr
// flags : DWORD -> Uint32
// 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 WSManRunShellCommand(
shell: NativeInt; // WSMAN_SHELL_HANDLE
flags: DWORD; // DWORD
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 'WSManRunShellCommand';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WSManRunShellCommand"
c_WSManRunShellCommand :: CIntPtr -> Word32 -> CWString -> Ptr () -> Ptr () -> Ptr () -> Ptr CIntPtr -> IO ()
-- shell : WSMAN_SHELL_HANDLE -> CIntPtr
-- flags : DWORD -> Word32
-- 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 wsmanrunshellcommand =
foreign "WSManRunShellCommand"
(intptr_t @-> uint32_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 *)
(* 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 ("WSManRunShellCommand" wsman-run-shell-command :convention :stdcall) :void
(shell :int64) ; WSMAN_SHELL_HANDLE
(flags :uint32) ; DWORD
(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 $WSManRunShellCommand = Win32::API::More->new('WsmSvc',
'void WSManRunShellCommand(LPARAM shell, DWORD flags, LPCWSTR commandLine, LPVOID args, LPVOID options, LPVOID async, LPVOID command)');
# my $ret = $WSManRunShellCommand->Call($shell, $flags, $commandLine, $args, $options, $async, $command);
# shell : WSMAN_SHELL_HANDLE -> LPARAM
# flags : DWORD -> DWORD
# 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
- f WSManRunShellCommandEx — コマンドIDを指定してリモートコマンドを実行する。