Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7011937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:11:26+00:00 2026-05-27T22:11:26+00:00

My OS is Win7 x64. I have two exe named ComHost.exe and ClientApp.exe. The

  • 0

My OS is Win7 x64. I have two exe named ComHost.exe and ClientApp.exe.

The ComHost.exe is a standalone exe and also a the COM host for the out-of-process COM.

ClientApp.exe creates the COM instance by calling the CoCreateInstance(…). When create the COM instance, the process ComHost.exe starts.

In the windows environment variables, there is a variable “AppStatus=status1”.

In the implementation of ClientApp.exe, the code is like that

int ret = putenv("AppStatus=status2"); // Change the environment variable.
// do something
CoCreateInstance(...); // Start ComHost.exe

In the implementation of ComHost.exe, I get the viriable value with the code

char * pStatus = getenv("AppStatus");

Case 1: If start the ComHost.exe by double click it, the value of pStatus is “status1”.

Case 2: If start the ComHost.exe in ClientApp.exe, the value of pStatus is “status2”. It inherits the environment variables of the parent process ClientApp.exe.

My question is:

I want ComHost.exe always reads the variable value defined by OS not the value inherited from the parent process. That means, in case 2, I want to get the value “status1”. Is it possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:11:27+00:00Added an answer on May 27, 2026 at 10:11 pm

    If you double-click the “ComHost.exe” process, you’re probably doing so from Explorer.EXE. That means you don’t get the “variable value defined by OS”. You just inherit it from Explorer.EXE (which, admittably, is started in a special way during login.)

    Behind the scenes, we’re always using CreateProcess or a variant thereof. Its default behavior it to create a new process, copying the environment variables of the calling process. As you’re not in charge of creating that new process (in case 2, COM is), you can’t alter this behavior.

    So, therefore, in both cases, getenv will get you the inherited value, and in case 2 you cannot get the value “that you would have inherited from Explorer.EXE”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small 32bit process I'm debugging on win7 x64 and I see
On my development machine (Win7 x64, IIS 7.5, SSRS 2008R2 x64), I have an
Using Delphi XE on Win7 x64, have Jedi Class Library ver. 3.45, and 7z.dll
I have the standard XAMPP installation on win7 (x64). Having had my share of
I'm setting up an ASP Classic website on Win7 x64, I have done the
I search for a solution. We have Delphi 6 Prof on Win7/X64. When I
I have a win7 x64 system (i3, nvidia card) and I want to use
I have CUDA 4.1 SDK with Parallel Nsight 2.1 installed on Win7 x64. I
On my Win7 PC I have a couple of virtual network adaptors that are
We have a higher-end Win7-64 Dell precision workstation notebook with an i7, 8 gigs

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.