in reply to Re: Win32 GetEnvironmentVariables?
in thread Win32 GetEnvironmentVariables?

Sorry I should have been more specific. I actually need to access a dll on windows and retrieve specific environment variables it sets.

Replies are listed 'Best First'.
Re^3: Win32 GetEnvironmentVariables?
by BrowserUk (Patriarch) on Nov 10, 2006 at 22:54 UTC

    Unless the dll was bound to perl, the changes won't be made until you load the dll. It then depends when the dll sets/changes the environment variables.

    If they are set/changed by the dlls initialisation, then you can

    use Win32; my $hModule = Win32::Loadibrary( 'thedll' );

    to load the library and then use GetEnvironmentStrings or GetEnvironmentVariable (via Win32::API) to get the modified environment for the perl process.

    If they don't get set until a particular api within the dll is called, then use Win32::API to load the dll and call the api before retrieving the new/modified values.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      BrowserUK...That's exactley what I was looking for. I'm assuming the Syntax for GetEnvironmentVariable is the same via the Win32 API correct?
      Thanks

        Seems to be.

        use Win32::API::Prototype;; ApiLink( 'kernel32', 'DWORD GetEnvironmentVariable( LPTSTR n, LPTSTR b, DWORD s )' ) or warn $^E;; $buffer = chr( 0 ) x 32767; $chars = GetEnvironmentVariable( 'PROCESSOR_IDENTIFIER', $buffer, 3276 +7 ); print substr $buffer, 0, $chars;; x86 Family 15 Model 2 Stepping 9, GenuineIntel

        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Win32 GetEnvironmentVariables?
by ikegami (Patriarch) on Nov 10, 2006 at 22:35 UTC
    There's no way of knowing which env vars a DLL sets unless you are the child process for which it has set them. That child process can access them via %ENV.
Re^3: Win32 GetEnvironmentVariables?
by runrig (Abbot) on Nov 10, 2006 at 22:00 UTC
    If they are environment variables, why can't you access them through %ENV?