Environment.SetEnvironmentVariable takes a long time to set a variable at the user or machine level

I am using the Environment.SetEnvironmentVariable method call in C # (.NET 3.5) as follows:

Environment.SetEnvironmentVariable (environmentVariable, cost, "Machine");

However, this single call takes more than 2 seconds on several test systems (works both XP and Windows 7). I found out that this could be because: "If the target is a User or a machine, other applications are notified of the specified operation with the Windows WM_SETTINGCHANGE message." Is there a way to suppress this notification for other applications so that my environment installs quickly and comes back ??

Please note that I have a component that sets about 20 environment variables, and if I use the function as I described above, it takes about a minute to complete this task.

Please suggest !!

+5
source share
1 answer

SetEnvironmentVariable , , WM_SETTINGCHANGE Win32 SendMessageTimeout. HWND_BROADCAST (0xffff), , - 1000 . msdn:

HWND_BROADCAST ((HWND) 0xffff), , . , . uTimeout .

fuFlags 0.

SMTO_NORMAL (0x0000): .

SMTO_BLOCK (0x0001): , .

, . Win32 . .

+9

All Articles