Can I create a child process using WMI VB scripting?

20 pts.
Tags:
VBScript
Visual Basic
WMI
Using WMI VB scripting, I would like to create/attach multiple child processes to a parent process, such as the explorer process. Any ideas how this can be done? Below is my code that fails. Thanks! Chris Option Explicit dim wmi, rootProcessName, rootProcess, objStartup, objConfig, objProcess, strComputer, dropbox, itunes, skype strComputer = "." dropbox="C:Program FilesDropboxDropbox.exe" itunes="C:Program FilesiTunesiTunes.exe" skype="C:Program FilesSkypePhoneSkype.exe" Const NORMAL = 32 Set wmi = GetObject("winmgmts:" & strComputer & "rootcimv2") Set objStartup = wmi.Get("Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance_ objConfig.PriorityClass = NORMAL rootProcessName = "'explorer.exe'" set rootProcess = wmi.ExecQuery("Select * from Win32_Process Where Name = " & rootProcessName ) For Each objProcess in rootProcess objProcess.Create dropbox, null, objConfig objProcess.Create itunes, null, objConfig objProcess.Create skype, null, objConfig Next WScript.Quit
ASKED: December 5, 2008  3:33 PM
UPDATED: December 11, 2008  9:26 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

The reason I want to do this is…

When an app is started by clicking on it, it becomes a child process of the explorer process. The same is true for all apps that are loaded when Windows starts up.

If you kill the explorer process using the “End Process Tree” context menu option in the task manager, it kills all child processes of the explorer process as well (a quick, brute force way to clean up memory without restarting).

I have two scripts – one that kills a bunch of specific processes, and another that restarts those processes.

Most of the processes/apps in my scripts are loaded at start-up thus they are children of the explorer process. When I kill the explorer process tree, all these process die, as explained earlier.

When I restart these apps using a script, they are no longer children of the explorer process. When I kill the kill the explorer process tree, the apps started by the script do not die.

Now, I know I can kill each process individually using a script. But it would be nice to just kill the explorer processes tree in a script without having to specify the individual apps I want to kill.

So, if I have one script that can start my apps as children of the explorer process, my other script just has to kill the explorer processes tree.

I have a script that does just that. It loops through and kills all the child processes of the explorer process. However it only works on apps that load at start up or are are clicked on.

Also, by preventing these apps from loading at start-up, Windows loads MUCH faster. Later, I click on my script icon to load my apps when needed.

That’s why I want to create a script that can start apps as children of the explorer process.

An interesting side note: I have to postpone killing any command/console processes, otherwise the script may kill itself before getting the rest of the processes.

Thanks!

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following