C# - Get Url from browser - c#

So just like uTorrent gets magnet links and opens them,
How can I setup my WinForm app to get a URL from Default Browser (in this case my default is Chrome) and open that URL in EO.WebBrowser within my app?
I don't have any code for this yet, as I don't know where to start.
Is this something that would be assigned as a Registry Key?
I know there are Registry keys for uTorrent to handle Magnet links in HKEY_CLASSES_ROOT\Magnet\shell\open\command.
What I have is WhatsApp Web open in EO.WebBrowser, and when I click on a URL starting with https://web.whatsapp.com or https://api.whatsapp.com it would open that link. The thing is the link should be changed to web.whatsapp.com, instead of api.whatsapp.com

Related

C# autologin to website using desktop application

I have a website in PHP Laravel 5.2.
I want to create a desktop application (something like drop-box application for windows) using C#, in which there will be a button "Open web", clicking which the logged-in user (in desktop app) should get logged in to the web-site without asking any credentials.
In web-site, I am using api_token based authentication.
There is a possible way I can make an end-point in web-site to check the token an make user logged in if correct, but I think it is less secure.
I've checked request-response log in fiddler for drop-box "Open dropbox.com" button, it does not sets any token in request.
The question is how can I achieve it?
One way would do the following:
Request a use-once (a nonce) unique code from the server in your desktop application, that refers to the user you want to log in as
Open a webbrowser process with an address that contains this use-once code, something like this:
http://www.your.server.com/the/page/you/want?auth=29874298798724982734
The way Dropbox does this, is to create a temporary html file on disk which contains some javascript code that posts a "form" to a secure page on their server
https://www.dropbox.com/desktop_login
form fields:
buildno=Dropbox-win-7.4.30
u=home
c=en_US
i=<some number>
n data-nonce-c=<some large hex string>
Then it spawns a webbrowser process to open this file.
To see this file, use the globe link in your Dropbox app and then hit Esc as soon as the initial web page loads and grab the url which should look like this:
file://C:/users/USERNAME/appdata/local/temp/RANDOM.html
Then open this file to inspect it.

C# - open browser to intranet on button click

I am aware
System.Diagnostics.Process.Start("https://www.facebook.com");
Goes to facebook but i want a button for a handy shortcut to the networks Intranet.
I obviously cant just put
System.Diagnostics.Process.Start("intranet");
Which is what i normally put in the browser, so how do i direct the button click here?
When you type "intranet" into the browser's address bar, the browser silently adds http://. When you copy the address from that address bar (after your intranet has loaded), you will get the full URL.
Try and use that in your Process.Start.

Find out the launch points of active IE instances of windows

We have an application that runs as service on windows. The service periodically checks for active Internet Explorer instances using SHDocVw.ShellWindows(). With this, we are able to capture the URL in each of the IE instances.
My Question:
Is it possible to find out how the webpage in each of these IE instances were launched. For example -
Did user type in url in IE to load the webpage?
Did the user select the link from another IE tab to launch ?
Did the user launch IE instance from another desktop application like outlook etc
Thank you.
The closest thing I could find to your specific requirement was this also check out the part 2 of the same blog where some edge cases have been discussed.
The part 1 of the blog talks about a registry key named TypedURLs (path: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs) which can be found in the registry editor, the rules of updation of this key are like this:
If a link is copied and pasted from a web page to the URL address bar and the user hits enter, this will also populate the key, as this is akin to physically typing in the entire address. If an invalid address of a webpage or resource that cannot be located is entered, the key will not be populated until either the connection or the request is completed (whether it succeeded or failed). If IE’s Stop function is selected before the connection is finished or the resource is located, the key will not be populated.
It is important to note that websites visited with the browser via hyperlinks, redirects, the IE Favorites menu or the user’s home page will not populate this key. Also, when a user selects to delete their browsing history using IE’s built-in function, this key is cleared.
Hope it helps!

Facebook Desktop Auth pop up Browser

I'm writing a desktop app in C# that has Facebook integration and I'm trying to figure out how to do authentication/login. I have thought of two different approaches:
1. Popup default browser
The user probably is logged into Facebook on their default browser.
Code: System.Diagnostics.Process.Start("http://www.facebook.com/...");
Issues/Questions: How do I control the window location and size (e.g. not show address bar when it starts)? Can I destroy the process after login is complete or even close the window (won't most browsers prompt for window closing if done from javascript?)?
2. Popup specific browser
If I lookup the default browser, I can pass command-line flags to the browser. "..\chrome.exe" --app=http://www.facebook.com/...
Questions: How do I set the window size/location? How do I close the process after login-complete (assuming I know when the login is complete)?
Is there a better way to do this?
very usefull resource in this situation is http://facebooksdk.net/.
Earlier, there was a sample project for desktop application on facebooksdk.net, but it was removed. You can see it here https://github.com/MarkAureliy/facebook-winforms-sample-master
This project is straight for your needs

How to launch a browser and later direct it to a page?

I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't

Categories

Resources