.NET and COM interop - How do I get environment variables to the COM process when using Windows Task

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a .NET application that needs to be scheduled to run using Windows Task Scheduler. The task is scheduled to run whether the user is logged in or not and we check the box to run with high priviledges. When we finish with the task, we have to give the
login and password to the task scheduler.
The .NET executable uses the Activator.CreateInstance API to create an instance of our COM application using a System.Type variable (via GetTypeFromProgID). However when it starts, the COM application does not have access to the users environment variables
if the user actually logs out before the scheduled task runs.
I have added calls in the .NET application to Enviornment.GetEnvironmentVariable and log the values. The .NET process, whether the user is logged in or not, succeeds in getting the environment variables so I know they are set and available to the .NET process.
I modified my COM app to log the values of the same environment variables. When the user is logged out and the app is started via the Activator call by the scheduled task when it starts, the COM app finds that the environment variables are not set. So the
environment for the user is not propogated to the COM process started by the .net process started by the task scheduler.
I suspect that I need to change the security settings of the .NET process so the COM process it creates via the Activator also has access to the users environment whether the user remains logged in or not.
Does anyone know how I can accomplish this? <hr class="sig R.D. Holland

View the full article
 
Back
Top