ホーム › NetworkManagement.NetManagement › SetNetScheduleAccountInformation
SetNetScheduleAccountInformation
関数タスクスケジューラの実行アカウントとパスワードを設定する。
シグネチャ
// mstask.dll
#include <windows.h>
HRESULT SetNetScheduleAccountInformation(
LPCWSTR pwszServerName,
LPCWSTR pwszAccount,
LPCWSTR pwszPassword
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pwszServerName | LPCWSTR | in | アカウント情報を設定する対象のコンピューター名を表す、NULL で終わるワイド文字列です。 |
| pwszAccount | LPCWSTR | in | アカウントを表す NULL で終わるワイド文字列へのポインターです。ローカルシステムアカウントを指定するには、このパラメーターを NULL に設定します。 |
| pwszPassword | LPCWSTR | in | パスワードを表す NULL で終わるワイド文字列へのポインターです。パスワード情報を保護する方法については、Handling Passwords を参照してください。 |
戻り値の型: HRESULT
公式ドキュメント
SetNetScheduleAccountInformation 関数は、AT サービスのアカウント名とパスワードを設定します。AT サービスのアカウント名とパスワードは、NetScheduleJobAdd で作成されるスケジュール済みジョブの資格情報として使用されます。
戻り値
戻り値は HRESULT です。S_OK の値は、アカウント名とパスワードが正常に設定されたことを示します。それ以外の値はエラー状態を示します。
関数が失敗した場合、考えられる戻り値の一部を以下に示します。
| 戻り値/値 | 説明 |
|---|---|
|
アクセスが拒否されました。このエラーは、呼び出し元が Administrators グループのメンバーでない場合に返されます。また、pwszAccount パラメーターが NULL ではなく(ローカルシステムアカウントではなく名前付きアカウントを指定)、かつ pwszAccount パラメーターで指定されたアカウントに対して pwszPassword パラメーターが正しくない場合にも返されます。 |
|
データが無効です。このエラーは、pwszPassword パラメーターが NULL であった場合、または pwszPassword パラメーターの文字列の長さが長すぎた場合に返されます。 |
|
指定されたアカウントの存在を確認できませんでした。このエラーは、pwszAccount パラメーターが NULL ではなく(ローカルシステムアカウントではなく名前付きアカウントを指定)、かつ pwszAccount パラメーターが見つからなかった場合に返されます。 |
解説(Remarks)
SetNetScheduleAccountInformation は呼び出し元を偽装(impersonate)します。スケジュールアカウント情報を設定するコンピューター上のローカル Administrators グループのメンバーのみが、この関数を正常に実行できます。NULL パスワードは許可されないことに注意してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 SetNetScheduleAccountInformation(
LPCWSTR pwszServerName,
LPCWSTR pwszAccount,
LPCWSTR pwszPassword
);[DllImport("mstask.dll", ExactSpelling = true)]
static extern int SetNetScheduleAccountInformation(
[MarshalAs(UnmanagedType.LPWStr)] string pwszServerName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pwszAccount, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string pwszPassword // LPCWSTR
);<DllImport("mstask.dll", ExactSpelling:=True)>
Public Shared Function SetNetScheduleAccountInformation(
<MarshalAs(UnmanagedType.LPWStr)> pwszServerName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pwszAccount As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> pwszPassword As String ' LPCWSTR
) As Integer
End Function' pwszServerName : LPCWSTR
' pwszAccount : LPCWSTR
' pwszPassword : LPCWSTR
Declare PtrSafe Function SetNetScheduleAccountInformation Lib "mstask" ( _
ByVal pwszServerName As LongPtr, _
ByVal pwszAccount As LongPtr, _
ByVal pwszPassword As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetNetScheduleAccountInformation = ctypes.windll.mstask.SetNetScheduleAccountInformation
SetNetScheduleAccountInformation.restype = ctypes.c_int
SetNetScheduleAccountInformation.argtypes = [
wintypes.LPCWSTR, # pwszServerName : LPCWSTR
wintypes.LPCWSTR, # pwszAccount : LPCWSTR
wintypes.LPCWSTR, # pwszPassword : LPCWSTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mstask.dll')
SetNetScheduleAccountInformation = Fiddle::Function.new(
lib['SetNetScheduleAccountInformation'],
[
Fiddle::TYPE_VOIDP, # pwszServerName : LPCWSTR
Fiddle::TYPE_VOIDP, # pwszAccount : LPCWSTR
Fiddle::TYPE_VOIDP, # pwszPassword : LPCWSTR
],
Fiddle::TYPE_INT)#[link(name = "mstask")]
extern "system" {
fn SetNetScheduleAccountInformation(
pwszServerName: *const u16, // LPCWSTR
pwszAccount: *const u16, // LPCWSTR
pwszPassword: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("mstask.dll")]
public static extern int SetNetScheduleAccountInformation([MarshalAs(UnmanagedType.LPWStr)] string pwszServerName, [MarshalAs(UnmanagedType.LPWStr)] string pwszAccount, [MarshalAs(UnmanagedType.LPWStr)] string pwszPassword);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mstask_SetNetScheduleAccountInformation' -Namespace Win32 -PassThru
# $api::SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)#uselib "mstask.dll"
#func global SetNetScheduleAccountInformation "SetNetScheduleAccountInformation" sptr, sptr, sptr
; SetNetScheduleAccountInformation pwszServerName, pwszAccount, pwszPassword ; 戻り値は stat
; pwszServerName : LPCWSTR -> "sptr"
; pwszAccount : LPCWSTR -> "sptr"
; pwszPassword : LPCWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "mstask.dll"
#cfunc global SetNetScheduleAccountInformation "SetNetScheduleAccountInformation" wstr, wstr, wstr
; res = SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)
; pwszServerName : LPCWSTR -> "wstr"
; pwszAccount : LPCWSTR -> "wstr"
; pwszPassword : LPCWSTR -> "wstr"; HRESULT SetNetScheduleAccountInformation(LPCWSTR pwszServerName, LPCWSTR pwszAccount, LPCWSTR pwszPassword)
#uselib "mstask.dll"
#cfunc global SetNetScheduleAccountInformation "SetNetScheduleAccountInformation" wstr, wstr, wstr
; res = SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)
; pwszServerName : LPCWSTR -> "wstr"
; pwszAccount : LPCWSTR -> "wstr"
; pwszPassword : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mstask = windows.NewLazySystemDLL("mstask.dll")
procSetNetScheduleAccountInformation = mstask.NewProc("SetNetScheduleAccountInformation")
)
// pwszServerName (LPCWSTR), pwszAccount (LPCWSTR), pwszPassword (LPCWSTR)
r1, _, err := procSetNetScheduleAccountInformation.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszServerName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszAccount))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwszPassword))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction SetNetScheduleAccountInformation(
pwszServerName: PWideChar; // LPCWSTR
pwszAccount: PWideChar; // LPCWSTR
pwszPassword: PWideChar // LPCWSTR
): Integer; stdcall;
external 'mstask.dll' name 'SetNetScheduleAccountInformation';result := DllCall("mstask\SetNetScheduleAccountInformation"
, "WStr", pwszServerName ; LPCWSTR
, "WStr", pwszAccount ; LPCWSTR
, "WStr", pwszPassword ; LPCWSTR
, "Int") ; return: HRESULT●SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword) = DLL("mstask.dll", "int SetNetScheduleAccountInformation(char*, char*, char*)")
# 呼び出し: SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)
# pwszServerName : LPCWSTR -> "char*"
# pwszAccount : LPCWSTR -> "char*"
# pwszPassword : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mstask" fn SetNetScheduleAccountInformation(
pwszServerName: [*c]const u16, // LPCWSTR
pwszAccount: [*c]const u16, // LPCWSTR
pwszPassword: [*c]const u16 // LPCWSTR
) callconv(std.os.windows.WINAPI) i32;proc SetNetScheduleAccountInformation(
pwszServerName: WideCString, # LPCWSTR
pwszAccount: WideCString, # LPCWSTR
pwszPassword: WideCString # LPCWSTR
): int32 {.importc: "SetNetScheduleAccountInformation", stdcall, dynlib: "mstask.dll".}pragma(lib, "mstask");
extern(Windows)
int SetNetScheduleAccountInformation(
const(wchar)* pwszServerName, // LPCWSTR
const(wchar)* pwszAccount, // LPCWSTR
const(wchar)* pwszPassword // LPCWSTR
);ccall((:SetNetScheduleAccountInformation, "mstask.dll"), stdcall, Int32,
(Cwstring, Cwstring, Cwstring),
pwszServerName, pwszAccount, pwszPassword)
# pwszServerName : LPCWSTR -> Cwstring
# pwszAccount : LPCWSTR -> Cwstring
# pwszPassword : LPCWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetNetScheduleAccountInformation(
const uint16_t* pwszServerName,
const uint16_t* pwszAccount,
const uint16_t* pwszPassword);
]]
local mstask = ffi.load("mstask")
-- mstask.SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)
-- pwszServerName : LPCWSTR
-- pwszAccount : LPCWSTR
-- pwszPassword : LPCWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mstask.dll');
const SetNetScheduleAccountInformation = lib.func('__stdcall', 'SetNetScheduleAccountInformation', 'int32_t', ['str16', 'str16', 'str16']);
// SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)
// pwszServerName : LPCWSTR -> 'str16'
// pwszAccount : LPCWSTR -> 'str16'
// pwszPassword : LPCWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mstask.dll", {
SetNetScheduleAccountInformation: { parameters: ["buffer", "buffer", "buffer"], result: "i32" },
});
// lib.symbols.SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword)
// pwszServerName : LPCWSTR -> "buffer"
// pwszAccount : LPCWSTR -> "buffer"
// pwszPassword : LPCWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetNetScheduleAccountInformation(
const uint16_t* pwszServerName,
const uint16_t* pwszAccount,
const uint16_t* pwszPassword);
C, "mstask.dll");
// $ffi->SetNetScheduleAccountInformation(pwszServerName, pwszAccount, pwszPassword);
// pwszServerName : LPCWSTR
// pwszAccount : LPCWSTR
// pwszPassword : LPCWSTR
// 構造体/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 SetNetScheduleAccountInformation(
WString pwszServerName, // LPCWSTR
WString pwszAccount, // LPCWSTR
WString pwszPassword // LPCWSTR
);
}@[Link("mstask")]
lib Libmstask
fun SetNetScheduleAccountInformation = SetNetScheduleAccountInformation(
pwszServerName : UInt16*, # LPCWSTR
pwszAccount : UInt16*, # LPCWSTR
pwszPassword : UInt16* # LPCWSTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetNetScheduleAccountInformationNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
typedef SetNetScheduleAccountInformationDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>);
final SetNetScheduleAccountInformation = DynamicLibrary.open('mstask.dll')
.lookupFunction<SetNetScheduleAccountInformationNative, SetNetScheduleAccountInformationDart>('SetNetScheduleAccountInformation');
// pwszServerName : LPCWSTR -> Pointer<Utf16>
// pwszAccount : LPCWSTR -> Pointer<Utf16>
// pwszPassword : LPCWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetNetScheduleAccountInformation(
pwszServerName: PWideChar; // LPCWSTR
pwszAccount: PWideChar; // LPCWSTR
pwszPassword: PWideChar // LPCWSTR
): Integer; stdcall;
external 'mstask.dll' name 'SetNetScheduleAccountInformation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetNetScheduleAccountInformation"
c_SetNetScheduleAccountInformation :: CWString -> CWString -> CWString -> IO Int32
-- pwszServerName : LPCWSTR -> CWString
-- pwszAccount : LPCWSTR -> CWString
-- pwszPassword : LPCWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setnetscheduleaccountinformation =
foreign "SetNetScheduleAccountInformation"
((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> returning int32_t)
(* pwszServerName : LPCWSTR -> (ptr uint16_t) *)
(* pwszAccount : LPCWSTR -> (ptr uint16_t) *)
(* pwszPassword : LPCWSTR -> (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 ("SetNetScheduleAccountInformation" set-net-schedule-account-information :convention :stdcall) :int32
(pwsz-server-name (:string :encoding :utf-16le)) ; LPCWSTR
(pwsz-account (:string :encoding :utf-16le)) ; LPCWSTR
(pwsz-password (:string :encoding :utf-16le))) ; LPCWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetNetScheduleAccountInformation = Win32::API::More->new('mstask',
'int SetNetScheduleAccountInformation(LPCWSTR pwszServerName, LPCWSTR pwszAccount, LPCWSTR pwszPassword)');
# my $ret = $SetNetScheduleAccountInformation->Call($pwszServerName, $pwszAccount, $pwszPassword);
# pwszServerName : LPCWSTR -> LPCWSTR
# pwszAccount : LPCWSTR -> LPCWSTR
# pwszPassword : LPCWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetNetScheduleAccountInformation — タスクスケジューラの実行アカウント情報を取得する。