This sounds difficult, and cannot be done with the rundll32 - I know because I have tried. There are many questions here, where the documentation of rundll is linked from. This basically only calls functions of the form:
void CALLBACK
EntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
http://support.microsoft.com/kb/164787
Which means - you can call special functions, which were designed to be called with this tool, AND simple functions, which take no arguments, or maybe just a HWND.
To refresh the environment, you need to broadcast (i.e. SendMessageTimeout
to HWND_BROADCAST
) the WM_SETTINGCHANGE
message, 4th argument (wparam
) should be 0
, and the LPARAM
should be L"Environment"
(notice the L
- it has to be a wide string, or the variables won't refresh!).
Here's some working PS code, which I don't remember who wrote (it's actually
the MSDN example for WM_SETTINGCHANGE
translated from C++):
#requires -version 2
if (-not ("win32.nativemethods" -as [type])) {
# import sendmessagetimeout from win32
add-type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageTimeout(
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
"@
}
$HWND_BROADCAST = [intptr]0xffff;
$WM_SETTINGCHANGE = 0x1a;
$result = [uintptr]::zero
# notify all windows of environment block change
[win32.nativemethods]::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE,
[uintptr]::Zero, "Environment", 2, 5000, [ref]$result);
It's more than 1 command, but fits into a small script.
I haven't tried your trick with a variable within a variable (PATH), but it may be,
that such a configuration requires two subsequent refreshes (the first one allows BPATH to be updated, and on the second one PATH uses the updated BPATH value.