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

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

It worked well now.
The problem was with me where I said

My code was the first time it opened Chrome with a profile and the second time with user-data-dir
Now, as you said, a new window has opened without the ui.vision plugin.
And your code worked. Only master 1 and master 2 windows are closed.
but While it works. It also gives an error. see this

Thanks to the dear user “Paper”

This is the solution

Run Chrome with --user-data-dir = “Your Chrome profile name” (below code)

Set shell=CreateObject("Shell.Application")
' shell.ShellExecute "application", "arguments", "path", "verb", window
shell.ShellExecute  "chrome.exe"," --user-data-dir=""c:\test\Profile 1""","""C:\Program Files (x86)\Google\Chrome\Application\""", "", 1

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

use follow code and replace “myMacro” with your chrome profile name

and enjoy :watermelon:

1 Like

You can remove the $profileArgs variable, that was there just in case you wanted to use it to start Chrome :slight_smile:

1 Like

ok deleted and thank you

hi again paper
can you give me your code in vbscript?

i convert it to:

Set sh = WScript.CreateObject ("WScript.Shell")

sh.run "cmd /k powershell.exe -command (Get-WmiObject win32_process -filter (""Name='chrome.exe' AND CommandLine LIKE '%{0}%'"" -f ""master1"")).Terminate()"

But it gives me the error below:

Name=chrome.exe : The term 'Name=chrome.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:39 + (Get-WmiObject win32_process -filter (Name='chrome.exe' AND CommandLi ... + ~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Name=chrome.exe:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Hi again,

Sorry, I don’t use VBScript. Probably you need to escape the contents after sh.run, like this:

sh.run "cmd \/k powershell.exe -command (Get-WmiObject win32_process -filter (\"\"Name=\'chrome.exe\' AND CommandLine LIKE \'%{0}%\'\"\" -f \"\"master1\"\")).Terminate()"
// Or this:
sh.run "cmd /k powershell.exe -command (Get-WmiObject win32_process -filter (\"\"Name=\'chrome.exe\' AND CommandLine LIKE \'%{0}%\'\"\" -f \"\"master1\"\")).Terminate()"

It’s possible none of the lines above work as I don’t know how to performing string escaping in VBScript. On a side note, I’m using a slightly modified version of this script, you might want to check it out:

1 Like

Mr @Plankton i want ask, i use powershell to automatically restart google chrome after x hours, but, the problem is powershell just open 1 browser, and i need to open 6 profile browser at the same time, it is possible? thank you

@Paper Im sorry i want to ask, how to open more than 1 browser with that powershell script? beacuse when i running the script, its work very good but just open 1 browser, how to open more than 1 browser / profile chrome?

Hi @Plankton i want to ask you how to automatically restart browser with powershell.
I’m already read other thread or problem in this forum about auto restart browser, and i found this

what i want to ask is, when i run the script its work fine, very good, but its just open 1 browser, and how to open more 1 browser, because i want run 6 browser at the same time, its can?

If you use firefox portable you can run unlimited browser in same time, need only to have multiple folder with firefox.

For Chrome i do not use it, require excessive ram i do not like Chrome.