The best way to open and close automatically at a specified time to prevent memory leaks(VBscript)

Your answer is correct, and by “faster” I mean that my site loads faster in the Chrome browser.
And I split the macro into two parts and used the Chrome profile to speed up the macro to finish faster (in general).

This is a good idea (except when the browser is hanged )
Of course, Mr. Plankton’s code snippet does the same. The only problem for me was that it kills the whole browser.
If I use these two commands, there are two way for the vbscript code snippet to notice that the browser and rpa are closed,(one is mr planktons: use log file to determine if a chrome is closed or not) and other is to use a variable at the end of the macro. Vbscript can check the value of this variable every few moments and if there is a specific value (for example, false, which indicates that the browser and rpa is closed), run the browser again with the desired profile (the second code I sent).
Is it possible to call a variable from within vbscript? if yes HOW?

There amore more tricks to get speed up.

  • Disable image, video codec, plugins
  • Do not install other addons except ui vision
  • Use a new browser (new browser updated is more fast of used browser)
  • Disable log in ui vision
  • Disable history in firefox

In this mode you have more speed up, if you study you can run more firefox in same time and you have the maximum speed.

Here’s what I’m doing to close a specific Chrome “profile”:

$scriptName = "myMacro"
$profileArgs = "--flag-switches-begin --user-data-dir=..\profiles\{0} --no-default-browser-check --allow-outdated-plugins --disable-logging --disable-breakpad --flag-switches-end" -f $scriptName
$filterString = "Name='chrome.exe' AND CommandLine LIKE '%{0}%'" -f $scriptName # $profileArgs would be better, but for some reason gives an error
(Get-WmiObject win32_process -filter $filterString).Terminate()

The last two commands will search Chrome’s process with a given “profile” (command line argument) and kill such instance.
You cannot use Chrome’s profile functionality (–profile-directory), you actually have to provide a different –user-data-dir parameter when launching Chrome (see $profileArgs). --profile-directory parameter is lost because Chrome processes merge together (different profiles, but same underlying Chrome instance), --user-data-dir is preserved because processes are not merged (independent Chrome instances)

The following program was used to aid in this analysis:

Someone should just make a CLI app where it reads an INI file and starts Chrome/Firefox instances accordingly:

[instance1]
run=myMacro
timeout=30
repeat=100

[instance2]
run=myMacro2
timeout=30
repeat=0

Anyone feeling adventurous? :slight_smile:
(master profile would be cloned for each instance)

Edit: Firefox is easier, just find command line argument “-P Profile1” and kill the process

1 Like

I think this error is related to the macro name.
Do you mean macro name, macro name in ui.vision or vbscript file name?
If I give this name m, your code will work but it still exit the whole browsers.

For profiles, you code looks good, or does it not work? See also here: Running multiple tests at the same Time - #4 by Timo

Good question: The log file is automatically created after each macro run if you add savelog=Log.txt to the command line.

So this command line log file needs savelog=. It should not be confused with the hard-drive log file, which is created automatically and is simply a copy of whatever you see in the log tab in the GUI.

1 Like

$scriptName here is used as the “profile name” (–user-data-dir=…\profiles{0}), so in this case you would need to launch Chrome with something like chrome.exe --user-data-dir=master instead of --profile-directory=master

References:
https://www.chromium.org/user-experience/multi-profiles
https://www.chromium.org/developers/creating-and-using-profiles

1 Like



image 1: Close the entire browser, regardless of profile
image 2: use profileargs and get error
During testing, profiles 1 and 2 were open.

“profiles 1 and 2 were open” - how did you open these?

1 Like

with this

Set shell=CreateObject("Shell.Application")
' shell.ShellExecute "application", "arguments", "path", "verb", window
shell.ShellExecute  "chrome.exe","--profile-directory=""Profile 2 "","""C:\Program Files (x86)\Google\Chrome\Application\""", "", 1

Set shell=CreateObject("Shell.Application")
' shell.ShellExecute "application", "arguments", "path", "verb", window
shell.ShellExecute  "chrome.exe","--profile-directory=""Profile 3"" """C:\Program Files (x86)\Google\Chrome\Application\""", "", 1

Replace --profile-directory with --user-data-dir. Please note doing so Chrome will start and act as if the profile was empty, because we have actually changed the directory Chrome will be reading (so you may need to install UI.Vision again)

Also, I haven’t tested with spaces in the profile name (“Profile1” vs “Profile 1”)

1 Like

i replace it but no problem was found, Did not act as empty

i use “” “” (double ") to insert space in it

So, is it working then?

1 Like

You mean the space in the profile name, when running the profile or when killing؟
I add double quotes when running profile. When killing the process I do not know is needed?

When the error is “You cannot call a method on a null-valued expression” it means it couldn’t find the process chrome.exe with the command-line argument “profile 2” ($scriptName). Can you verify Chrome’s command line arguments with a tool like Process Hacker to see if it’s really present?

1 Like

If you have a question why --profile-directory is used. I have to say that after your code snippet did not work, I restored it to its previous state.

I can no longer answer. The number of replies exceeded the allowable limit (I am a new user). I have to wait 11 hours.:frowning: :upside_down_face:

but i can edit :wink:

its work but just for profile 2 and dont work with profile 3
Apparently, when the first Chrome profile is opened, all Chrome processes and other profiles(any other profile) are subset of it. Please see this link where the last answer was written. Last comment.

Try $scriptName = “Profile 2” instead of “profile 2” (case sensitive)

Indeed that’s the case, you can’t use Chrome profiles. You have to use --user-data-dir :slight_smile:

1 Like