ホーム › NetworkManagement.NetManagement › GetNetScheduleAccountInformation
GetNetScheduleAccountInformation
関数タスクスケジューラの実行アカウント情報を取得する。
シグネチャ
// mstask.dll
#include <windows.h>
HRESULT GetNetScheduleAccountInformation(
LPCWSTR pwszServerName,
DWORD ccAccount,
LPWSTR wszAccount
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pwszServerName | LPCWSTR | in | アカウント情報を取得する対象のコンピューター名を表す、NULL で終端されたワイド文字列です。 |
| ccAccount | DWORD | in | wszAccount 用に割り当てられた、NULL 終端文字を含む文字数です。この値に許可される最大長は、ドメイン名の最大長にユーザー名の最大長と 2 を加えた値であり、DNLEN + UNLEN + 2 と表されます。(末尾の 2 文字は「\」文字と NULL 終端文字です。) |
| wszAccount | LPWSTR | out | アカウント情報を受け取る、NULL 終端文字を含むワイド文字の配列です。 |
戻り値の型: HRESULT
公式ドキュメント
GetNetScheduleAccountInformation 関数は、AT サービスのアカウント名を取得します。
戻り値
戻り値は HRESULT です。S_OK は関数が成功し、アカウント情報が wszAccount に返されたことを示します。S_FALSE は関数が成功し、アカウントが Local System アカウントであることを示します(この場合、wszAccount には何も返されません)。これら以外の戻り値はエラー状態を示します。
解説(Remarks)
GetNetScheduleAccountInformation 関数を正常に呼び出すには、呼び出し元がタスクフォルダーに対する読み取りアクセス権を持っている必要があります。タスクフォルダーは通常 %windir%\tasks であるか、または次のレジストリ設定で定義されています。
HKLM\SOFTWARE\Microsoft\SchedulingAgent\TasksFolder
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// mstask.dll
#include <windows.h>
HRESULT GetNetScheduleAccountInformation(
LPCWSTR pwszServerName,
DWORD ccAccount,
LPWSTR wszAccount
);[DllImport("mstask.dll", ExactSpelling = true)]
static extern int GetNetScheduleAccountInformation(
[MarshalAs(UnmanagedType.LPWStr)] string pwszServerName, // LPCWSTR
uint ccAccount, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder wszAccount // LPWSTR out
);<DllImport("mstask.dll", ExactSpelling:=True)>
Public Shared Function GetNetScheduleAccountInformation(
<MarshalAs(UnmanagedType.LPWStr)> pwszServerName As String, ' LPCWSTR
ccAccount As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> wszAccount As System.Text.StringBuilder ' LPWSTR out
) As Integer
End Function' pwszServerName : LPCWSTR
' ccAccount : DWORD
' wszAccount : LPWSTR out
Declare PtrSafe Function GetNetScheduleAccountInformation Lib "mstask" ( _
ByVal pwszServerName As LongPtr, _
ByVal ccAccount As Long, _
ByVal wszAccount As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetNetScheduleAccountInformation = ctypes.windll.mstask.GetNetScheduleAccountInformation
GetNetScheduleAccountInformation.restype = ctypes.c_int
GetNetScheduleAccountInformation.argtypes = [
wintypes.LPCWSTR, # pwszServerName : LPCWSTR
wintypes.DWORD, # ccAccount : DWORD
wintypes.LPWSTR, # wszAccount : LPWSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mstask.dll')
GetNetScheduleAccountInformation = Fiddle::Function.new(
lib['GetNetScheduleAccountInformation'],
[
Fiddle::TYPE_VOIDP, # pwszServerName : LPCWSTR
-Fiddle::TYPE_INT, # ccAccount : DWORD
Fiddle::TYPE_VOIDP, # wszAccount : LPWSTR out
],
Fiddle::TYPE_INT)#[link(name = "mstask")]
extern "system" {
fn GetNetScheduleAccountInformation(
pwszServerName: *const u16, // LPCWSTR
ccAccount: u32, // DWORD
wszAccount: *mut u16 // LPWSTR out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("mstask.dll")]
public static extern int GetNetScheduleAccountInformation([MarshalAs(UnmanagedType.LPWStr)] string pwszServerName, uint ccAccount, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder wszAccount);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mstask_GetNetScheduleAccountInformation' -Namespace Win32 -PassThru
# $api::GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount)#uselib "mstask.dll"
#func global GetNetScheduleAccountInformation "GetNetScheduleAccountInformation" sptr, sptr, sptr
; GetNetScheduleAccountInformation pwszServerName, ccAccount, varptr(wszAccount) ; 戻り値は stat
; pwszServerName : LPCWSTR -> "sptr"
; ccAccount : DWORD -> "sptr"
; wszAccount : LPWSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mstask.dll" #cfunc global GetNetScheduleAccountInformation "GetNetScheduleAccountInformation" wstr, int, var ; res = GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount) ; pwszServerName : LPCWSTR -> "wstr" ; ccAccount : DWORD -> "int" ; wszAccount : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mstask.dll" #cfunc global GetNetScheduleAccountInformation "GetNetScheduleAccountInformation" wstr, int, sptr ; res = GetNetScheduleAccountInformation(pwszServerName, ccAccount, varptr(wszAccount)) ; pwszServerName : LPCWSTR -> "wstr" ; ccAccount : DWORD -> "int" ; wszAccount : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetNetScheduleAccountInformation(LPCWSTR pwszServerName, DWORD ccAccount, LPWSTR wszAccount) #uselib "mstask.dll" #cfunc global GetNetScheduleAccountInformation "GetNetScheduleAccountInformation" wstr, int, var ; res = GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount) ; pwszServerName : LPCWSTR -> "wstr" ; ccAccount : DWORD -> "int" ; wszAccount : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetNetScheduleAccountInformation(LPCWSTR pwszServerName, DWORD ccAccount, LPWSTR wszAccount) #uselib "mstask.dll" #cfunc global GetNetScheduleAccountInformation "GetNetScheduleAccountInformation" wstr, int, intptr ; res = GetNetScheduleAccountInformation(pwszServerName, ccAccount, varptr(wszAccount)) ; pwszServerName : LPCWSTR -> "wstr" ; ccAccount : DWORD -> "int" ; wszAccount : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mstask = windows.NewLazySystemDLL("mstask.dll")
procGetNetScheduleAccountInformation = mstask.NewProc("GetNetScheduleAccountInformation")
)
// pwszServerName (LPCWSTR), ccAccount (DWORD), wszAccount (LPWSTR out)
r1, _, err := procGetNetScheduleAccountInformation.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszServerName))),
uintptr(ccAccount),
uintptr(wszAccount),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetNetScheduleAccountInformation(
pwszServerName: PWideChar; // LPCWSTR
ccAccount: DWORD; // DWORD
wszAccount: PWideChar // LPWSTR out
): Integer; stdcall;
external 'mstask.dll' name 'GetNetScheduleAccountInformation';result := DllCall("mstask\GetNetScheduleAccountInformation"
, "WStr", pwszServerName ; LPCWSTR
, "UInt", ccAccount ; DWORD
, "Ptr", wszAccount ; LPWSTR out
, "Int") ; return: HRESULT●GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount) = DLL("mstask.dll", "int GetNetScheduleAccountInformation(char*, dword, char*)")
# 呼び出し: GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount)
# pwszServerName : LPCWSTR -> "char*"
# ccAccount : DWORD -> "dword"
# wszAccount : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mstask" fn GetNetScheduleAccountInformation(
pwszServerName: [*c]const u16, // LPCWSTR
ccAccount: u32, // DWORD
wszAccount: [*c]u16 // LPWSTR out
) callconv(std.os.windows.WINAPI) i32;proc GetNetScheduleAccountInformation(
pwszServerName: WideCString, # LPCWSTR
ccAccount: uint32, # DWORD
wszAccount: ptr uint16 # LPWSTR out
): int32 {.importc: "GetNetScheduleAccountInformation", stdcall, dynlib: "mstask.dll".}pragma(lib, "mstask");
extern(Windows)
int GetNetScheduleAccountInformation(
const(wchar)* pwszServerName, // LPCWSTR
uint ccAccount, // DWORD
wchar* wszAccount // LPWSTR out
);ccall((:GetNetScheduleAccountInformation, "mstask.dll"), stdcall, Int32,
(Cwstring, UInt32, Ptr{UInt16}),
pwszServerName, ccAccount, wszAccount)
# pwszServerName : LPCWSTR -> Cwstring
# ccAccount : DWORD -> UInt32
# wszAccount : LPWSTR out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetNetScheduleAccountInformation(
const uint16_t* pwszServerName,
uint32_t ccAccount,
uint16_t* wszAccount);
]]
local mstask = ffi.load("mstask")
-- mstask.GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount)
-- pwszServerName : LPCWSTR
-- ccAccount : DWORD
-- wszAccount : LPWSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mstask.dll');
const GetNetScheduleAccountInformation = lib.func('__stdcall', 'GetNetScheduleAccountInformation', 'int32_t', ['str16', 'uint32_t', 'uint16_t *']);
// GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount)
// pwszServerName : LPCWSTR -> 'str16'
// ccAccount : DWORD -> 'uint32_t'
// wszAccount : LPWSTR out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mstask.dll", {
GetNetScheduleAccountInformation: { parameters: ["buffer", "u32", "buffer"], result: "i32" },
});
// lib.symbols.GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount)
// pwszServerName : LPCWSTR -> "buffer"
// ccAccount : DWORD -> "u32"
// wszAccount : LPWSTR out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetNetScheduleAccountInformation(
const uint16_t* pwszServerName,
uint32_t ccAccount,
uint16_t* wszAccount);
C, "mstask.dll");
// $ffi->GetNetScheduleAccountInformation(pwszServerName, ccAccount, wszAccount);
// pwszServerName : LPCWSTR
// ccAccount : DWORD
// wszAccount : LPWSTR 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 Mstask extends StdCallLibrary {
Mstask INSTANCE = Native.load("mstask", Mstask.class);
int GetNetScheduleAccountInformation(
WString pwszServerName, // LPCWSTR
int ccAccount, // DWORD
char[] wszAccount // LPWSTR out
);
}@[Link("mstask")]
lib Libmstask
fun GetNetScheduleAccountInformation = GetNetScheduleAccountInformation(
pwszServerName : UInt16*, # LPCWSTR
ccAccount : UInt32, # DWORD
wszAccount : UInt16* # LPWSTR out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetNetScheduleAccountInformationNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Utf16>);
typedef GetNetScheduleAccountInformationDart = int Function(Pointer<Utf16>, int, Pointer<Utf16>);
final GetNetScheduleAccountInformation = DynamicLibrary.open('mstask.dll')
.lookupFunction<GetNetScheduleAccountInformationNative, GetNetScheduleAccountInformationDart>('GetNetScheduleAccountInformation');
// pwszServerName : LPCWSTR -> Pointer<Utf16>
// ccAccount : DWORD -> Uint32
// wszAccount : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetNetScheduleAccountInformation(
pwszServerName: PWideChar; // LPCWSTR
ccAccount: DWORD; // DWORD
wszAccount: PWideChar // LPWSTR out
): Integer; stdcall;
external 'mstask.dll' name 'GetNetScheduleAccountInformation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetNetScheduleAccountInformation"
c_GetNetScheduleAccountInformation :: CWString -> Word32 -> CWString -> IO Int32
-- pwszServerName : LPCWSTR -> CWString
-- ccAccount : DWORD -> Word32
-- wszAccount : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getnetscheduleaccountinformation =
foreign "GetNetScheduleAccountInformation"
((ptr uint16_t) @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* pwszServerName : LPCWSTR -> (ptr uint16_t) *)
(* ccAccount : DWORD -> uint32_t *)
(* wszAccount : LPWSTR out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mstask (t "mstask.dll"))
(cffi:use-foreign-library mstask)
(cffi:defcfun ("GetNetScheduleAccountInformation" get-net-schedule-account-information :convention :stdcall) :int32
(pwsz-server-name (:string :encoding :utf-16le)) ; LPCWSTR
(cc-account :uint32) ; DWORD
(wsz-account :pointer)) ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetNetScheduleAccountInformation = Win32::API::More->new('mstask',
'int GetNetScheduleAccountInformation(LPCWSTR pwszServerName, DWORD ccAccount, LPWSTR wszAccount)');
# my $ret = $GetNetScheduleAccountInformation->Call($pwszServerName, $ccAccount, $wszAccount);
# pwszServerName : LPCWSTR -> LPCWSTR
# ccAccount : DWORD -> DWORD
# wszAccount : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f SetNetScheduleAccountInformation — タスクスケジューラの実行アカウントとパスワードを設定する。