view raw
maky55 maky55 - 6 months ago 71 Question

Opening chrome in incognito with a url

I'm expanding on a little programming work I'm doing, and I'm using process.start() to open chrome in incognito mode, but I also want it to open a url in the incognito mode. This is my code:

Dim chrome As String = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
Dim param As String = "/incognito"
Dim sURL As String = txtCustomURL.Text
Process.Start(chrome, param)

End Sub

This didn't work, it opens a incognito tab but opens the url in a normal window. Is there a way I can open a url in incognito mode like this (baring in mind I'm a beginner at VB)?


You are calling Process.Start twice:

  • The first one runs Chrome.exe with the parameter /incognito;
  • the second runs your URL, which Windows will launch with the default browser.

You need to launch Chrome.exe with two parameters: /incognito, and the url to open.

Chrome (and most other programs) accept parameters separated by spaces. So the format of your parameters should end up like /incognito

Therefore, try passing chrome a string consisting of param, a space, and then the URL, concatenated together with +:

Process.Start(chrome, param + " " + sURL)