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

RefreshPolicyEx

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

シグネチャ

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

BOOL RefreshPolicyEx(
    BOOL bMachine,
    DWORD dwOptions
);

パラメーター

名前方向
bMachineBOOLin
dwOptionsDWORDin

戻り値の型: 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 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)。