ホーム › System.RemoteManagement › WSManConnectShellCommand
WSManConnectShellCommand
関数既存のリモートコマンドへ接続する。
シグネチャ
// WsmSvc.dll
#include <windows.h>
void WSManConnectShellCommand(
WSMAN_SHELL_HANDLE shell,
DWORD flags,
LPCWSTR commandID,
WSMAN_OPTION_SET* options, // optional
WSMAN_DATA* connectXml, // optional
WSMAN_SHELL_ASYNC* async,
WSMAN_COMMAND_HANDLE* command
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| shell | WSMAN_SHELL_HANDLE | in |
| flags | DWORD | in |
| commandID | LPCWSTR | in |
| options | WSMAN_OPTION_SET* | inoptional |
| connectXml | WSMAN_DATA* | inoptional |
| async | WSMAN_SHELL_ASYNC* | in |
| command | WSMAN_COMMAND_HANDLE* | out |
戻り値の型: void
各言語での呼び出し定義
// WsmSvc.dll
#include <windows.h>
void WSManConnectShellCommand(
WSMAN_SHELL_HANDLE shell,
DWORD flags,
LPCWSTR commandID,
WSMAN_OPTION_SET* options, // optional
WSMAN_DATA* connectXml, // optional
WSMAN_SHELL_ASYNC* async,
WSMAN_COMMAND_HANDLE* command
);[DllImport("WsmSvc.dll", ExactSpelling = true)]
static extern void WSManConnectShellCommand(
IntPtr shell, // WSMAN_SHELL_HANDLE
uint flags, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string commandID, // LPCWSTR
IntPtr options, // WSMAN_OPTION_SET* optional
IntPtr connectXml, // WSMAN_DATA* optional
IntPtr async, // WSMAN_SHELL_ASYNC*
out IntPtr command // WSMAN_COMMAND_HANDLE* out
);<DllImport("WsmSvc.dll", ExactSpelling:=True)>
Public Shared Sub WSManConnectShellCommand(
shell As IntPtr, ' WSMAN_SHELL_HANDLE
flags As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> commandID As String, ' LPCWSTR
options As IntPtr, ' WSMAN_OPTION_SET* optional
connectXml As IntPtr, ' WSMAN_DATA* 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
' options : WSMAN_OPTION_SET* optional
' connectXml : WSMAN_DATA* optional
' async : WSMAN_SHELL_ASYNC*
' command : WSMAN_COMMAND_HANDLE* out
Declare PtrSafe Sub WSManConnectShellCommand Lib "wsmsvc" ( _
ByVal shell As LongPtr, _
ByVal flags As Long, _
ByVal commandID As LongPtr, _
ByVal options As LongPtr, _
ByVal connectXml 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
WSManConnectShellCommand = ctypes.windll.wsmsvc.WSManConnectShellCommand
WSManConnectShellCommand.restype = None
WSManConnectShellCommand.argtypes = [
ctypes.c_ssize_t, # shell : WSMAN_SHELL_HANDLE
wintypes.DWORD, # flags : DWORD
wintypes.LPCWSTR, # commandID : LPCWSTR
ctypes.c_void_p, # options : WSMAN_OPTION_SET* optional
ctypes.c_void_p, # connectXml : WSMAN_DATA* 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')
WSManConnectShellCommand = Fiddle::Function.new(
lib['WSManConnectShellCommand'],
[
Fiddle::TYPE_INTPTR_T, # shell : WSMAN_SHELL_HANDLE
-Fiddle::TYPE_INT, # flags : DWORD
Fiddle::TYPE_VOIDP, # commandID : LPCWSTR
Fiddle::TYPE_VOIDP, # options : WSMAN_OPTION_SET* optional
Fiddle::TYPE_VOIDP, # connectXml : WSMAN_DATA* 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 WSManConnectShellCommand(
shell: isize, // WSMAN_SHELL_HANDLE
flags: u32, // DWORD
commandID: *const u16, // LPCWSTR
options: *mut WSMAN_OPTION_SET, // WSMAN_OPTION_SET* optional
connectXml: *mut WSMAN_DATA, // WSMAN_DATA* 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 WSManConnectShellCommand(IntPtr shell, uint flags, [MarshalAs(UnmanagedType.LPWStr)] string commandID, IntPtr options, IntPtr connectXml, IntPtr async, out IntPtr command);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WsmSvc_WSManConnectShellCommand' -Namespace Win32 -PassThru
# $api::WSManConnectShellCommand(shell, flags, commandID, options, connectXml, async, command)#uselib "WsmSvc.dll"
#func global WSManConnectShellCommand "WSManConnectShellCommand" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WSManConnectShellCommand shell, flags, commandID, varptr(options), varptr(connectXml), varptr(async), command
; shell : WSMAN_SHELL_HANDLE -> "sptr"
; flags : DWORD -> "sptr"
; commandID : LPCWSTR -> "sptr"
; options : WSMAN_OPTION_SET* optional -> "sptr"
; connectXml : WSMAN_DATA* optional -> "sptr"
; async : WSMAN_SHELL_ASYNC* -> "sptr"
; command : WSMAN_COMMAND_HANDLE* out -> "sptr"出力引数:
#uselib "WsmSvc.dll" #func global WSManConnectShellCommand "WSManConnectShellCommand" sptr, int, wstr, var, var, var, int ; WSManConnectShellCommand shell, flags, commandID, options, connectXml, async, command ; shell : WSMAN_SHELL_HANDLE -> "sptr" ; flags : DWORD -> "int" ; commandID : LPCWSTR -> "wstr" ; options : WSMAN_OPTION_SET* optional -> "var" ; connectXml : WSMAN_DATA* optional -> "var" ; async : WSMAN_SHELL_ASYNC* -> "var" ; command : WSMAN_COMMAND_HANDLE* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WsmSvc.dll" #func global WSManConnectShellCommand "WSManConnectShellCommand" sptr, int, wstr, sptr, sptr, sptr, int ; WSManConnectShellCommand shell, flags, commandID, varptr(options), varptr(connectXml), varptr(async), command ; shell : WSMAN_SHELL_HANDLE -> "sptr" ; flags : DWORD -> "int" ; commandID : LPCWSTR -> "wstr" ; options : WSMAN_OPTION_SET* optional -> "sptr" ; connectXml : WSMAN_DATA* optional -> "sptr" ; async : WSMAN_SHELL_ASYNC* -> "sptr" ; command : WSMAN_COMMAND_HANDLE* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void WSManConnectShellCommand(WSMAN_SHELL_HANDLE shell, DWORD flags, LPCWSTR commandID, WSMAN_OPTION_SET* options, WSMAN_DATA* connectXml, WSMAN_SHELL_ASYNC* async, WSMAN_COMMAND_HANDLE* command) #uselib "WsmSvc.dll" #func global WSManConnectShellCommand "WSManConnectShellCommand" intptr, int, wstr, var, var, var, int ; WSManConnectShellCommand shell, flags, commandID, options, connectXml, async, command ; shell : WSMAN_SHELL_HANDLE -> "intptr" ; flags : DWORD -> "int" ; commandID : LPCWSTR -> "wstr" ; options : WSMAN_OPTION_SET* optional -> "var" ; connectXml : WSMAN_DATA* optional -> "var" ; async : WSMAN_SHELL_ASYNC* -> "var" ; command : WSMAN_COMMAND_HANDLE* out -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void WSManConnectShellCommand(WSMAN_SHELL_HANDLE shell, DWORD flags, LPCWSTR commandID, WSMAN_OPTION_SET* options, WSMAN_DATA* connectXml, WSMAN_SHELL_ASYNC* async, WSMAN_COMMAND_HANDLE* command) #uselib "WsmSvc.dll" #func global WSManConnectShellCommand "WSManConnectShellCommand" intptr, int, wstr, intptr, intptr, intptr, int ; WSManConnectShellCommand shell, flags, commandID, varptr(options), varptr(connectXml), varptr(async), command ; shell : WSMAN_SHELL_HANDLE -> "intptr" ; flags : DWORD -> "int" ; commandID : LPCWSTR -> "wstr" ; options : WSMAN_OPTION_SET* optional -> "intptr" ; connectXml : WSMAN_DATA* optional -> "intptr" ; async : WSMAN_SHELL_ASYNC* -> "intptr" ; command : WSMAN_COMMAND_HANDLE* out -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wsmsvc = windows.NewLazySystemDLL("WsmSvc.dll")
procWSManConnectShellCommand = wsmsvc.NewProc("WSManConnectShellCommand")
)
// shell (WSMAN_SHELL_HANDLE), flags (DWORD), commandID (LPCWSTR), options (WSMAN_OPTION_SET* optional), connectXml (WSMAN_DATA* optional), async (WSMAN_SHELL_ASYNC*), command (WSMAN_COMMAND_HANDLE* out)
r1, _, err := procWSManConnectShellCommand.Call(
uintptr(shell),
uintptr(flags),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(commandID))),
uintptr(options),
uintptr(connectXml),
uintptr(async),
uintptr(command),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure WSManConnectShellCommand(
shell: NativeInt; // WSMAN_SHELL_HANDLE
flags: DWORD; // DWORD
commandID: PWideChar; // LPCWSTR
options: Pointer; // WSMAN_OPTION_SET* optional
connectXml: Pointer; // WSMAN_DATA* optional
async: Pointer; // WSMAN_SHELL_ASYNC*
command: Pointer // WSMAN_COMMAND_HANDLE* out
); stdcall;
external 'WsmSvc.dll' name 'WSManConnectShellCommand';result := DllCall("WsmSvc\WSManConnectShellCommand"
, "Ptr", shell ; WSMAN_SHELL_HANDLE
, "UInt", flags ; DWORD
, "WStr", commandID ; LPCWSTR
, "Ptr", options ; WSMAN_OPTION_SET* optional
, "Ptr", connectXml ; WSMAN_DATA* optional
, "Ptr", async ; WSMAN_SHELL_ASYNC*
, "Ptr", command ; WSMAN_COMMAND_HANDLE* out
, "Int") ; return: void●WSManConnectShellCommand(shell, flags, commandID, options, connectXml, async, command) = DLL("WsmSvc.dll", "int WSManConnectShellCommand(int, dword, char*, void*, void*, void*, void*)")
# 呼び出し: WSManConnectShellCommand(shell, flags, commandID, options, connectXml, async, command)
# shell : WSMAN_SHELL_HANDLE -> "int"
# flags : DWORD -> "dword"
# commandID : LPCWSTR -> "char*"
# options : WSMAN_OPTION_SET* optional -> "void*"
# connectXml : WSMAN_DATA* optional -> "void*"
# async : WSMAN_SHELL_ASYNC* -> "void*"
# command : WSMAN_COMMAND_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。