Can I create a child process using WMI VB scripts?

Using WMI scripts WMI I would like to create / attach multiple child processes to a parent process like explorer.

When an application is launched by clicking on it, it becomes a child process of the explorer process. The same is true for all applications that load when Windows starts.

If you kill an explorer process using the Target Process Tree context menu option in Task Manager, it also kills all child processes of the explorer process (quick and crude way to clean up memory without restarting).

I have two scripts - one that kills a bunch of specific processes and the other that restarts those processes.

Most of the processes / apps in my scripts are loaded at startup, so they are children of the explorer process. When I kill the explorer process tree, all those processes die as explained earlier.

When I restart these apps with a script, they are no longer children of the explorer process. When I kill the explorer tree tree, the applications launched by the script don't die.

Now I know that I can kill each process individually using a script. But it would be nice to just kill the explorer process tree in the script without specifying the individual applications I want to kill.

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

I have a script that does exactly that. It moves around and kills all child processes of the explorer process. However, it only works with apps that are loaded on startup or pushed.

Also, by preventing these applications from loading at startup, Windows boots MUCH faster. Later I click on the script icon to load applications when needed.

This is why I want to create a script that can launch applications as children of the explorer process.

Interesting note: I have to postpone killing any commands / consoles, otherwise the script might kill itself before getting the rest of the processes.

Any ideas how this can be done?

Below is my code not working.

Option Explicit
dim wmi, rootProcessName, rootProcess, objStartup, objConfig, objProcess, strComputer, dropbox, itunes, skype
strComputer = "."

dropbox="C:\Program Files\Dropbox\Dropbox.exe"
itunes="C:\Program Files\iTunes\iTunes.exe"
skype="C:\Program Files\Skype\Phone\Skype.exe"

Const NORMAL = 32
Set wmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
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

      

+1


source to share


1 answer


The window process keeps track of the process ID of the process that created it, so relationships are managed. To get what you want, you either need to change the parent PID stored in the child process, or inject code into the process you want to be the parent and create a new child process. None of these are truly feasible.



The real solution is to use Job Objects , this way you can terminate all the processes associated with the job at the same time, But you will have to migrate from vbscript.

+1


source







All Articles