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

RefreshPolicyEx

関数
オプション指定でグループポリシーを再適用する。
DLLUSERENV.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL RefreshPolicyEx(
    BOOL bMachine,
    DWORD dwOptions
);

パラメーター

名前方向説明
bMachineBOOLinTRUEでコンピューターポリシーを、FALSEでユーザーポリシーを更新する。
dwOptionsDWORDin更新オプション。RP_FORCEで変更有無に関わらず全設定を再適用する。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL RefreshPolicyEx(
    BOOL bMachine,
    DWORD dwOptions
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USERENV.dll", SetLastError = true, ExactSpelling = true)]
static extern bool RefreshPolicyEx(
    bool bMachine,   // BOOL
    uint dwOptions   // DWORD
);
<DllImport("USERENV.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function RefreshPolicyEx(
    bMachine As Boolean,   ' BOOL
    dwOptions As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' bMachine : BOOL
' dwOptions : DWORD
Declare PtrSafe Function RefreshPolicyEx Lib "userenv" ( _
    ByVal bMachine As Long, _
    ByVal dwOptions As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RefreshPolicyEx = ctypes.windll.userenv.RefreshPolicyEx
RefreshPolicyEx.restype = wintypes.BOOL
RefreshPolicyEx.argtypes = [
    wintypes.BOOL,  # bMachine : BOOL
    wintypes.DWORD,  # dwOptions : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USERENV.dll')
RefreshPolicyEx = Fiddle::Function.new(
  lib['RefreshPolicyEx'],
  [
    Fiddle::TYPE_INT,  # bMachine : BOOL
    -Fiddle::TYPE_INT,  # dwOptions : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "userenv")]
extern "system" {
    fn RefreshPolicyEx(
        bMachine: i32,  // BOOL
        dwOptions: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("USERENV.dll", SetLastError = true)]
public static extern bool RefreshPolicyEx(bool bMachine, uint dwOptions);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USERENV_RefreshPolicyEx' -Namespace Win32 -PassThru
# $api::RefreshPolicyEx(bMachine, dwOptions)
#uselib "USERENV.dll"
#func global RefreshPolicyEx "RefreshPolicyEx" sptr, sptr
; RefreshPolicyEx bMachine, dwOptions   ; 戻り値は stat
; bMachine : BOOL -> "sptr"
; dwOptions : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "USERENV.dll"
#cfunc global RefreshPolicyEx "RefreshPolicyEx" int, int
; res = RefreshPolicyEx(bMachine, dwOptions)
; bMachine : BOOL -> "int"
; dwOptions : DWORD -> "int"
; BOOL RefreshPolicyEx(BOOL bMachine, DWORD dwOptions)
#uselib "USERENV.dll"
#cfunc global RefreshPolicyEx "RefreshPolicyEx" int, int
; res = RefreshPolicyEx(bMachine, dwOptions)
; bMachine : BOOL -> "int"
; dwOptions : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	userenv = windows.NewLazySystemDLL("USERENV.dll")
	procRefreshPolicyEx = userenv.NewProc("RefreshPolicyEx")
)

// bMachine (BOOL), dwOptions (DWORD)
r1, _, err := procRefreshPolicyEx.Call(
	uintptr(bMachine),
	uintptr(dwOptions),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function RefreshPolicyEx(
  bMachine: BOOL;   // BOOL
  dwOptions: DWORD   // DWORD
): BOOL; stdcall;
  external 'USERENV.dll' name 'RefreshPolicyEx';
result := DllCall("USERENV\RefreshPolicyEx"
    , "Int", bMachine   ; BOOL
    , "UInt", dwOptions   ; DWORD
    , "Int")   ; return: BOOL
●RefreshPolicyEx(bMachine, dwOptions) = DLL("USERENV.dll", "bool RefreshPolicyEx(bool, dword)")
# 呼び出し: RefreshPolicyEx(bMachine, dwOptions)
# bMachine : BOOL -> "bool"
# dwOptions : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "userenv" fn RefreshPolicyEx(
    bMachine: i32, // BOOL
    dwOptions: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc RefreshPolicyEx(
    bMachine: int32,  # BOOL
    dwOptions: uint32  # DWORD
): int32 {.importc: "RefreshPolicyEx", stdcall, dynlib: "USERENV.dll".}
pragma(lib, "userenv");
extern(Windows)
int RefreshPolicyEx(
    int bMachine,   // BOOL
    uint dwOptions   // DWORD
);
ccall((:RefreshPolicyEx, "USERENV.dll"), stdcall, Int32,
      (Int32, UInt32),
      bMachine, dwOptions)
# bMachine : BOOL -> Int32
# dwOptions : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t RefreshPolicyEx(
    int32_t bMachine,
    uint32_t dwOptions);
]]
local userenv = ffi.load("userenv")
-- userenv.RefreshPolicyEx(bMachine, dwOptions)
-- bMachine : BOOL
-- dwOptions : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USERENV.dll');
const RefreshPolicyEx = lib.func('__stdcall', 'RefreshPolicyEx', 'int32_t', ['int32_t', 'uint32_t']);
// RefreshPolicyEx(bMachine, dwOptions)
// bMachine : BOOL -> 'int32_t'
// dwOptions : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USERENV.dll", {
  RefreshPolicyEx: { parameters: ["i32", "u32"], result: "i32" },
});
// lib.symbols.RefreshPolicyEx(bMachine, dwOptions)
// bMachine : BOOL -> "i32"
// dwOptions : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RefreshPolicyEx(
    int32_t bMachine,
    uint32_t dwOptions);
C, "USERENV.dll");
// $ffi->RefreshPolicyEx(bMachine, dwOptions);
// bMachine : BOOL
// dwOptions : DWORD
// 構造体/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 Userenv extends StdCallLibrary {
    Userenv INSTANCE = Native.load("userenv", Userenv.class);
    boolean RefreshPolicyEx(
        boolean bMachine,   // BOOL
        int dwOptions   // DWORD
    );
}
@[Link("userenv")]
lib LibUSERENV
  fun RefreshPolicyEx = RefreshPolicyEx(
    bMachine : Int32,   # BOOL
    dwOptions : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RefreshPolicyExNative = Int32 Function(Int32, Uint32);
typedef RefreshPolicyExDart = int Function(int, int);
final RefreshPolicyEx = DynamicLibrary.open('USERENV.dll')
    .lookupFunction<RefreshPolicyExNative, RefreshPolicyExDart>('RefreshPolicyEx');
// bMachine : BOOL -> Int32
// dwOptions : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RefreshPolicyEx(
  bMachine: BOOL;   // BOOL
  dwOptions: DWORD   // DWORD
): BOOL; stdcall;
  external 'USERENV.dll' name 'RefreshPolicyEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RefreshPolicyEx"
  c_RefreshPolicyEx :: CInt -> Word32 -> IO CInt
-- bMachine : BOOL -> CInt
-- dwOptions : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let refreshpolicyex =
  foreign "RefreshPolicyEx"
    (int32_t @-> uint32_t @-> returning int32_t)
(* bMachine : BOOL -> int32_t *)
(* dwOptions : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library userenv (t "USERENV.dll"))
(cffi:use-foreign-library userenv)

(cffi:defcfun ("RefreshPolicyEx" refresh-policy-ex :convention :stdcall) :int32
  (b-machine :int32)   ; BOOL
  (dw-options :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RefreshPolicyEx = Win32::API::More->new('USERENV',
    'BOOL RefreshPolicyEx(BOOL bMachine, DWORD dwOptions)');
# my $ret = $RefreshPolicyEx->Call($bMachine, $dwOptions);
# bMachine : BOOL -> BOOL
# dwOptions : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API