2
votes

I've written a script which updates an environment variable, but I need to tell Program Manager to update the computer's programs with this new information. I was given this as the API call that is made within another program to cause this:

::SendMessage(::FindWindow("Progman", NULL), WM_WININICHANGE, 0L, (LPARAM)"Environment");

I am attempting to translate this into an AutoHotKey PostMessage call, but I'm doing something wrong, as it isn't working. Here's where I've gotten so far:

PostMessage, 0x1A,, (LPARAM)"Environment", "Program Manager"

Here are the AHK resources I've been looking at to do this:

List of Windows Messages

Send Messages to a Window or Its Controls

PostMessage / SendMessage

And here are the resources that I used to figure out the original API call:

SendMessage function

WM_WININICHANGE message

Can anyone help me figure out what I'm doing wrong?

1

1 Answers

2
votes

A somewhat direct translation would be:

SendMessage 0x1A,, "Environment",, ahk_class Progman

The wParam and lParam parameters are expressions, so literal strings must be quoted. Conversely, the Control and WinTitle parameters are not expressions, so any quote marks would be interpreted literally.

In AutoHotkey, (LPARAM) is just a variable enclosed in parentheses, not a type cast. It should be omitted.

Note that MSDN indicates WM_SETTINGCHANGE should be used instead of WM_WININICHANGE, but these are actually one and the same.

Finally, note that EnvUpdate broadcasts the WM_SETTINGCHANGE message to all windows.

EnvUpdate