windows 11 url scheme not opening application compiled by golang - go

I want to create an OAuth registration/login process for my non-web application written in golang. For that, when my application is opened, I open the browser with an OAuth URL and after the successful authenitcation, the redirect_uri is set to my own url scheme myapp:// to reopen my application and pass the authentication token to it.
I managed to let my golang application register it's url scheme itself with Handling url schemes with golang?
and wenn I type in my scheme like myapp:// the browser prompts me as expected if I want to open my application.
But when I click "yes open it" it just opens a cmd very shortly (or nothing when I compile it with go build -ldflags -Hwindowsgui) and nothing else happens and I also don't get any logfiles written by my application, so I am pretty sure that nothing is executed.
If I change the executeable path in the registry of the scheme to open something like C:\Windows\System32\notepad.exe it opens the Windows editor as expected.
I also tried to put my application in a Windows-folder but still nothing is executed.
I can't find any ressource on the internet regarding this problem.
Do I need to do something security wise so my application is executed, because it seems that Windows blocks the execution of my application?
One guess would be that my freshly compiled golang executable is not digital signed and therefor not executed because of security risks? Or is there something else I'm missing?
Or is there another way to create url schemes for applications in local development?
Thanks for any help!

Related

How to open chrome app with specific URL through chrome_proxy.exe?

I have a Chrome app that I created with "Create Application Shortcut".
What I need is to open that app with specific url on the same domain.
Example:
chrome_proxy.exe --profile-directory=Default --app-id=xxxxxxxx "https://www.google.com"
Is that possible or any command that achive the same result?
I'm guessing you installed the Chrome app so that the website launches in a standalone window. If this is the case, you can achieve something similar by using the --app command line switch instead.
Eg: chrome_proxy.exe --profile-directory=Default --app="https://www.google.com"
This doesn't strictly open the URL in the existing app, but it does open that specific URL in a standalone window.
Here's the answer what you are looking for.
chrome_proxy.exe --profile-directory=Default --app-id=xxxxxxxx --app-launch-url-for-shortcuts-menu-item="https://youtu.be/dQw4w9WgXcQ"
Using this will work:
chrome_proxy.exe --profile-directory=Default --app-id=xxxxxxxx --app-launch-url-for-shortcuts-menu-item="https://youtu.be/dQw4w9WgXcQ"
It will launch in the special standalone window AND navigate to the specified URL.
Replace xxxxxxxx with the app id (this can be found if you look at the properties of the shortcut it created), but after you create the app this part should already be filled in.
At that point all you need to add is this part:
--app-launch-url-for-shortcuts-menu-item="https://youtu.be/dQw4w9WgXcQ"
Replacing the https:​//youtu.be/dQw4w9WgXcQ part with the full URL of where you would like to navigate to.
Documentation of the argument can be found here.
Credit due in part to 김보근.

URI scheme launching

I've been given a task to create a protocol similar to callto:, that - upon clicking on a link with it - would automatically launch an installed aplication.
I followed the microsoft guide on how a scheme should look like.
My scheme looks like this:
HKEY_CLASSES_ROOT
slican
URL Protocol = ""
DefaultIcon (Default) = "C:\Users\Okabe\Desktop\slican\SlicanP.exe,1"
shell
open
command (Default) = "C:\Users\Okabe\Desktop\slican\SlicanP.exe" "%1""
I thought that was all and tested it with
test link
test telephone link
There was no reaction whatsoever. Internet Explorer asked me if I want to search for a program that can open the content and Chrome responded with nothing, as if I clicked javascript:void(0).
How to get that worked?
Thank you for your help!
The registration you show works perfectly fine for me when I try it on Windows 7. The local app I registered in place of SlicanP.exe ran fine when I invoked a slican: URL from the Start | Run menu, and from within the address bar of Windows Explorer. So the registration works.
Do be aware that Internet Explorer runs in a lower integrity security context, so it may not have rights to run local programs. When I tried to click on an HTML link to a slican: URL, or type a slican: URL in the address bar, IE had trouble executing the local app (even after prompting for permission). I had to run IE as an administrator, then the local app ran just fine.
Also, you really should not be creating a HKEY_CLASSES_ROOT\slican key directly. Create a HKEY_CURRENT_USER\Software\Classes\slican (current user only) or HKEY_LOCAL_MACHINE\Software\Classes\slican (all users) instead. Refer to MSDN for more details:
HKEY_CLASSES_ROOT Key
Merged View of HKEY_CLASSES_ROOT
Update: Since it works in Windows 7, Microsoft probably changed how URL schemes are registered in Windows 8. For instance, phone/store apps use URI activation:
URI activation (XAML).
URI activation (HTML)
The documentation says there are two ways to register a custom URI scheme:
Internet Explorer uses two mechanisms for registering new pluggable protocol handlers. The first method is to register a URI scheme name and its associated application so that all attempts to navigate to a URI using that scheme launch the application (for example, registering applications to handle mailto: or news: URIs). The second method uses the Asynchronous Pluggable Protocols API, which allows you to define new protocols by mapping the URI scheme to a class.
You are doing the first. Try using the second instead.
However, I just noticed that "Asynchronous Pluggable Protocols" is listed on MSDN in the "Legacy APIs" section, and it has the following note:
Third-party protocol implementations won't load in Windows Store apps using JavaScript, or in the Internet Explorer in the new Windows UI.
So it may or may not work in Windows 8.
Update: I just found this:
Guidelines for file types and URIs
In Windows 8, the relationship between apps and the file types they support differs from previous versions of Windows.
Walkthrough: using Windows 8 Custom Protocol Activation
The file type and protocol association model has changed in Windows 8. Apps are no longer able to programmatically set themselves as the default handler for a file type or protocol. Instead, now the user always controls what the default handler is for a file type or protocol.
Your app can use existing protocols for communication, such as mailto, or create a custom protocol. The protocol activation extension enables you to define a custom protocol or register to handle an existing protocol.
Also have a look at this:
Setting mailto: protocol handler programmatically in Windows 8
And this:
Default Programs
if you go to C:\Users\\AppData\Local\Google\Chrome\User Data
You can edit the Local State file
Search for protocol_handler
The syntax here is a key value pair. I usually copy two mailto: and make sure that you set your protocols to false. This will mean that chrome will treat your new protocols as URI_Handler events
If you have troubles with configuring custom URI scheme, you can compare your own configuration with existing one. For example, "HKEY_CLASSES_ROOT/mailto" - most likely you have it already in your system.

Batch script/PowerShell advanced conditionals implementation

My question is in regards to how I should go about implementing a batch script/PowerShell cmdlet on Windows that does the following:
When a browser window is open that has the window/page title "Blank" then send the "tab" key, send login credentials to text boxes on webpage and then send the "enter" key.
I found this article (Automatic login to a website on windows 7/Chrome via batch file) about sending login credentials in a web browser, which is very similar to what I want to do, however I want the script to ONLY run if the browser is already open and has a specific value in the window title. This is for an authentication system for the network running on my server that asks me to re-login every 30 days, and will open up a browser window automatically when it needs me to login. So, when it opens the window, I want the script to be able to automatically login for me. Since the server is unattended (GUI wise), I want the re-authentication to occur automatically. My plan would be to have this set as a scheduled task and have it run nightly, to verify that the system is still authenticated. If the system is not authenticated, I want the batch file/cmdlet to login for me.
I did some research and found information about using conditions for batch files, but I couldn't find any information about how I would use the window title or any other program attribute to base my conditional off of.
People have suggested using PowerShell, so I am totally open to that as well if you have a recommendation for implementation via that route.
Please let me know if you need any further information, or have any questions.
You can do it with Powershell.
Here is an example for getting the window name, it should be possible to use it to detect Internet explorer to.
$selectedWindows = get-process | Where-Object { $_.MainWindowTitle -match "Editor"}
in $selectedWindows there are all windows which title matches "Editor"
Now you can get the $selectedWindows in front and use sendKeys to work with the Window.
For getting the Window activated and in front i have a short example here:
http://pastecode.org/index.php/view/22992037

Implementing my own protocol and using it through my browser

I want to create a new protocol so that I can view the data retrieved through the protocol in the browser.
For example, I want to be able to go to myprotocol://www.filepath.com/img.jpg and view the image.
Where myprotocol is defined by myself.
I have read about registering application handling here:
http://msdn.microsoft.com/en-us/library/aa767914%28v=vs.85%29.aspx
with this it is possible to run a desktop exe that receives the url I am trying to access. How would I return the retrieved jpg to the browser for viewing, so that it behaves like a normal protocol, such as http?
Thanks
That registration will allow you to bind an application to the uri, so if launched through windows explorer (including "Run") and from command line, then the app is launched and the uri passed to it as an argument (much like if you double-click a file, the default app for it is launched and the path to the file passed).
For example, your "default" browser will have http:// associated with it in this way.
It is still up to the application itself to have its own handling of the URI when it is passed as an argument. If you want to make a browser handle your new protocol, you will have to write an extension/plugin/add-on/whatever-that-browser's-makers-call-it to add further functionality to the browser. This is a separate job for Firefox, IE, Chrome, Konqueror, Chromium (well, at least it might be sharable with Chrome), etc. with separate APIs to deal with.

Opening URLs with custom protocol - syntax error?

I'm having some real issues in getting local files to open up via a browser using a custom protocol. Now before you shoot me for the custom protocol, this web app will be working in a closed intranet environment, so I have full control to add these protocols for all users. The app works fine at the moment, but I've been requested to bypass the Open / Save dialog for files as it's 'annoying' and 'time consuming' (yeah, I know...I tried to tell them), so here I am in uncharted territory!
Here's an example then of what's not working (I'm using Notepad in this example to test it in Server 2008 R2 with IIS7):
Using the info on Registering an Application to a URL Protocol I've added the following to the registry:
HKEY_CLASSES_ROOT
opentxt
(Default) = "URL:opentxt Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "C:\Windows\System32\notepad.exe,1"
shell
open
command
(Default) = "C:\Windows\System32\notepad.exe" "%1"
So now, in theory, it should be as easy as having the following link in my html
Open File
And it does almost work - click on the link and it opens up Notepad instantly, however I'm presented with this error in notepad.
The filename, directory name, or volume label syntax is incorrect
The file definitely exists in that location (I can read it using http: //localhost/openme.txt), and I've tried to represent the link in as many different formats, such as described here but just can't get it to work.
Any ideas where I'm going wrong?
Quite simply, you're confusing your two different protocols.
Your protocol - and the Url that you pass to notepad - is opentxt://localhost/openme.txt. The working location of the file is http: //localhost/openme.txt. These two are not the same!
HTTP is a protocol that is natively understood by the operating system and, as such, Notepad can pass the HTTP Url to the operating system, which will in turn connect to localhost using port 80 and send a request for that resource. The file is returned, and Notepad has its data. This is all handled within operating system libraries that define the behaviour of HTTP.
Your opentxt protocol doesn't have this support unless you code it. Notepad doesn't know what to do with it - so you see your error message.
A way to handle this easily is to create your own application that handles the protocol. If you had an opentxtHandler.exe wired up through the registry, it would be passed the opentxt:// url, and can then process it appropriately. This might simply mean changing the protocol from opentxt to http and then passing it to Notepad - or it could be something more complex.

Resources