0

I have wrote an initialization script that sets user environment variables which are keys that have been hashed and encrypted...Once the keys have been created the key encryption exe is no longer required. I want to launch the main application and remove the init file containing the hashing and key encryption functions.

I am not having any trouble with any of the above...Everything works as should when independent of each other. The problem is that in order for the main application to have access to the newly created environment variables I need the init script to completely exit...

Everything I have tried, Popen with flags, os.system() and others have still left me in a situation where the parent process ends and the main application launches, however, the environment variables have not updated...I close and relaunch main.py and...boom the program sees the updated variables and all is fine.

All I want is the init script to run, spawn a new process that is not linked at all with init.py and then exit so it can be removed. I thought this would be simple but after many hours of head scratching and trying numerous things, I am still no closer.

If I have to I will simply bundle it as two separate .exe files but I wanted it to be a one click install type thing.

I am running windows 10 and this can be platform specific.

Links looked at:

How to stop/terminate a python script from running?

Using a Python subprocess call to invoke a Python script

Starting a separate process

https://docs.python.org/2/library/subprocess.html

Python: Howto launch a full process not a child process and retrieve the PID

And more...

Current closest result

p = Popen(["python","UserInterface.py"], stdin=PIPE, stdout=PIPE, stderr=PIPE,
 creationflags=DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP)
asked Oct 10, 2019 at 3:05

1 Answer 1

1

Create an environment block, set the environment variable using SetEnvironmentVariable, and use CreateProcess to specify this environment block for the created process.

MSDN DOC:

To specify a different environment for a process, create a new environment block and pass the pointer to it as a parameter to the CreateProcess function.

...

To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string "Environment". This allows applications, such as the shell, to pick up your updates.

answered Oct 11, 2019 at 5:43
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Drake, I will look into this I have been trying with CreateProcess...I will have a read of the docs and come back to you
Did this help to you?
Yes sorry Drake, swamped!!! I have marked as correct with plus...Thanks for the help

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.