Talk:Setting Environment Variables to Active Installer Process: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Apply changes to the registry with an external program)
 
No edit summary
 
(One intermediate revision by one other user not shown)
Line 54: Line 54:


I found help from this page (http://castelain.developpez.com/articles/VariablesEnvironnement), and the links that are given to the MSDN related functions.
I found help from this page (http://castelain.developpez.com/articles/VariablesEnvironnement), and the links that are given to the MSDN related functions.
Tips for compilation with Mingw
g++ -Wall main.cpp -L/path/to/user32.lib -luser32 -o main.exe
:That's what [[Setting Environment Variables]] does. The script in this page is meant to set the environment variables only for the current process. --[[User:Kichik|kichik]] 09:02, 6 July 2006 (PDT)

Latest revision as of 16:02, 6 July 2006

There is another way to apply changes in the registry :
1/ write keys and values like before, eg : WriteRegStr HKCU "Environment" "NAME" "VALUE"
2/ call a simple exe program to apply the changes :
Source code :
#include <windows.h>
#include <stdio.h>
 
int main( int argc, char** argv)
{
/*
    LRESULT SendMessageTimeout(
        HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam,
        UINT fuFlags,
        UINT uTimeout,
        PDWORD_PTR lpdwResult
    );
*/
    DWORD lpdwResult;
    char* param;
    param = "Environment";
    int result = SendMessageTimeout(
        // window handle => all top-level windows
        HWND_BROADCAST,
        // message => environment changed
        WM_SETTINGCHANGE,
        // wParam : additional message-specific information
        // When an application sends this message, this parameter must be NULL.
        (WPARAM)NULL,
        // lParam : additional message-specific information
        // lParam is a pointer to a string that indicates the area containing the system parameter that was changed
        (LPARAM)param,
        // how to send the message
        // The calling thread is not prevented from processing other requests while waiting for the function to return.
        SMTO_NORMAL,
        // uTimeout : time-out period in milliseconds
        // duration = uTimeout * number_of_windows (in case broadcast message)
        500,
        // Receives the result of the message processing
        &lpdwResult
    );
    fprintf(stdout, "SendMessageTimeout returned : %d => %s\n", result, (result != 0) ? "SUCCESS" : "FAILED");
    // inverse return code ...
    return (result != 0) ? 0 : -1; 
}

I found help from this page (http://castelain.developpez.com/articles/VariablesEnvironnement), and the links that are given to the MSDN related functions.

Tips for compilation with Mingw g++ -Wall main.cpp -L/path/to/user32.lib -luser32 -o main.exe

That's what Setting Environment Variables does. The script in this page is meant to set the environment variables only for the current process. --kichik 09:02, 6 July 2006 (PDT)