How to open a URL in chrome incognito mode
You'll need to create a process with a path to Chrome's exe file, and use the argument --incognito
.
The path to chrome in windows is typically:
C:\Users\<UserName>\AppData\Local\Google\Chrome\chrome.exe
Use the following code:
var url = "http://www.google.com";
using (var process = new Process())
{
process.StartInfo.FileName = @"C:\Users\<UserName>\AppData\Local\Google\Chrome\chrome.exe";
process.StartInfo.Arguments = url + " --incognito";
process.Start();
}
An article explaining this: http://www.tech-recipes.com/rx/3479/google-chrome-use-a-command-line-switch-to-open-in-incognito-mode/
The full chrome command-line switch directory: http://peter.sh/experiments/chromium-command-line-switches/
Opening chrome in incognito with a url
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 http://www.google.com
Therefore, try passing chrome a string consisting of param
, a space, and then the URL, concatenated together with &
:
Process.Start(chrome, param & " " & sURL)
Open a link in an Incognito Window in Google Chrome
To run any executable including Chrome in JAVA:
If the path to the application is a system variable:
String location = System.getenv("APPVARIAVLE");
Process process = new ProcessBuilder(location).start();
Or if you want to use the fully qualified path:
Process process = new ProcessBuilder("C:\\location\\MyApp.exe").start();
The JavaDoc for the process builder say that you can add parameters like this:
new ProcessBuilder("myCommand", "myArg1", "myArg2");
The argument for incognito looks like it is: "-incognito" and to open a url just add the url: "example.com".
Which means that you can most likely can add the url and incognito arguments the following way to chrome in the arguments:
Process process = new ProcessBuilder("C:\\YourChrome\\Location\\chrome.exe","-incognito","http://stackoverflow.com").start();
Related Topics
Convert Byte Array to Wav File
How to Dynamically Adjust Table Column Width in Rdlc Report
Regex Match Keywords That Are Not in Quotes
Error: the Entity Type Requires a Primary Key
How to Trim All Elements in a List
How to Convert a Dictionary to a Json String in C#
How to Delete a Read-Only File
How to Autosize the Height and the Width of C# Windows Form
How to Use Task.Delay as a Timer
How to Calculate the Average of Each Row in Multidimensional Array
How to Submit Disabled Input in ASP.NET MVC
How to Authenticate a Webclient Request
Convert Date Format of String to Datetime Mm/Dd/Yyyy When System Date Formate Is Dd/Mm/Yyyy
Use Linq to Collaps Multiply Collections into One Collection