Registering my application to URI Scheme and fetching the command that launched it - windows

Windows allows me to register my application to a URI Scheme as defined here. If the application is already running clicking on the URI should bring it to the foreground. For some reason, GetCommandLineW() keeps giving me the original command that launched the application.
Is there some way I could get the new URI that brought my window to the foreground.
I'm aware Win messages could be used to get the command line arguments. Is there some way to associate my URI commands with a win message.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\myapp]
#="URL:myapp"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
#="<Path To App>,2"
[HKEY_CLASSES_ROOT\myapp\shell]
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\myapp\shell\open\command]
#="\"<Path To App>" \"%1\""

Firstly, thanks a lot everyone for your comments. Sorry, I'm a bit of a newbie and it took me some time to grasp what was being stated from the beginning. I'll leave this comment here in case someone wants to check back.
As suggested, my app did launch a new window. It found an instance of my app that was already running. And as a result terminated.
What I changed? Before this newly launched instance is terminated, I send a new message to the previously running instance of my application. In order to pass the contents of the command line I used named shared memory.
The receiving app just listened to this message. On receiving it, it retrieves the command line from the shared memory and allows me to handle the command line.
Thanks again.

Related

wscript.exe stopped working with a custom protocol

All the computers in our company are configured with a custom protocol that runs a vbs script, so when you click on a link with that user protocol, the vbs script starts and performs operations that interact with the file system and applications otherwise inaccessible to the browser.
This is the .reg file used to register the protocol:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\<name>]
"URL Protocol"=""
#="Url:<Description>"
"UseOriginalUrlEncoding"=dword:00000001
[HKEY_CLASSES_ROOT\<name>\DefaultIcon]
#="C:\\Windows\\System32\\WScript.exe"
[HKEY_CLASSES_ROOT\<name>\shell]
[HKEY_CLASSES_ROOT\<name>\shell\open]
[HKEY_CLASSES_ROOT\<name>\shell\open\command]
#="C:\\Windows\\System32\\WScript.exe \"C:\\Program Files\\<name>.vbs\" \"%1\""
The script has worked beautifully since 2014 without problems on ~50 computers.
Last week one user complained that it stopped working. I found out that WScript.exe doesn't work anymore, so I copied it creating WScript2.exe, modified the custom protocol to run WScript2.exe and it restarted working.
This morning also my computer didn't listen to the clicks on my custom protocol. I made a copy of WScript.exe to WScript2.exe and it restarted working.
I am expecting my phone to start ringing soon.
Why did WScript.exe stop listening to the custom protocol?
Why its identical copy still works?
EDIT (answers to comments)
Perhaps if I knew how to better describe "it stopped working" then I would know how to fix it :)
I don't know if it stopped working because of a Microsoft update, an anti-virus update or a change on the IT infrastructure/configuration. Here is a quick summary of what led me to the workaround:
I compared my custom protocol to a working one, I picked mailto as a reference
I noticed that changing the last line of the .reg file (see above) it would work with any other executable, but it wouldn't work with wscript.exe
I compared the execution of wscript.exe on the affected computers to its execution on computers (not yet) affected and there is no difference
A double click shows the same Windows Script Host Settings dialog
The execution from a command prompt with the same arguments used by the custom protocol works as expected
The custom protocol passes the correct arguments when executing another executable
At this point I thought that Windows blacklisted wscript.exe and I started searching for an alternative
I tried to rename wscript.exe to wscript2.exe but I couldn't because I don't have TrustedInstaller permission
I made a copy instead of renaming it
I tested the copy from the command prompt and it was working like the original
I tested the copy from the custom protocol and it was working like the original once did
EDIT 2 (more answers to comments)
All the computers have Windows 10 Pro.
Clicking on Settings - Updates & Security - View update history it says Feature update to Windows 10, version 1803 Succesfully installed on 5/22/2018. Clicking on Show what's new in this update shows nothing useful.
EDIT 3
Doesn't work = no symptoms, nothing happens, nothing is executed, nothing is logged (as far as I know).
I tried with a simple vbscript with a single line MsgBox "Hello". It works running it from the command line, but it doesn't work from the custom protocol. The task manager doesn't show anything popping up, but I don't know if it doesn't show it because the lifespan is too short to show or because it doesn't execute. The same script works with wscript2.exe.
My feeling is that something (Windows, anti-virus, ...) is blacklisting the custom protocol + wscript.exe thing, but not the custom protocol + any other executable or any other environment + wscript.exe. That's why I tried to copy wscript.exe to wscript2.exe. And I was pleasantly surprised to find out that it works.

Parse.exe crashing and no creating necessary files

I'm trying to start learning parse cloud code. When I launch the parse.exe via my command line, various terrible things happen. For example, if I try to launch it using any kind of a command, but it's not set to "launch as administrator", I will see no text from the program(it will expect me to input my email and password, yet I will see no text I would see if I launched it as administrator). If I run it as administrator, it ends up consistently crashing during any activity. For example, if I try to go for >parse list, I will get to login, the list of apps appears and then the window instantly closes. Strictly following the tutorial(https://www.parse.com/apps/quickstart#cloud_code/windows) crashes midway as well. Doing >parse new for my existing app creates parse.local and parse.project files in the specified directory, but none of the rest files expected. I cannot seem to find the I'm pretty much lost here. Am I doing something wrong? I have the latest parse.exe thing, redownloaded it from multiple locations provided by parse.

Taking over the Windows Run command on 'File not found'

When you hit the WIN+R (Run command) in windows, you get the Run Box:
How can I get a handle to this command incase an entry for what I am typing is not found?
For example, this works great when you type cmd or calc.
But when you type: thisawesomething and hit the return key, you are greeted with this:
What I want to do is either of these two:
Whenever the file, folder or resource is not found via RUN, a default program (which I specify) is fired.
OR
If I can have a program running in the background which listens to an event raised by Windows when it can't find a file, what event am I looking for?
Is this even possible?
I have tried searching for this quite a bit but have hit a wall. Any help or a push in the right direction would be appreciated.
Note:
This article mentions that if I fire the RUN command programatically, there is a way to handle the notification of which program is about to be run. However, I am looking to modify (or patch) the default Windows Run functionality and not fire this programatically from another app. Thanks.

Passing arguments while launching program from browser

I am trying to launch an application (.exe) from my browser.
The specific app needs 4 arguments/parameters when launching, which are: firstname, lastname, id, info
Is there a way to add these arguments on the Internet Explorer address bar when i launch my program?
I mean something like this:
"myapp:// -firstname -lastname -id -info"
(I only managed to add those arguments straight to the windows registry, it worked that way. But thats no help... i need them to be inputted when launching the app )
I have added this to my windows registry:
[HKEY_CLASSES_ROOT\myapp]
#="URL:myprogram Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
#="\"C:\\myapp.exe\""
[HKEY_CLASSES_ROOT\myapp\shell]
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\vsa\shell\open\command]
#="\"C:\\myapp\" "%1"
Thanks for help already! I hope someone knows how to fix this... :)
ps. Im using windows 7 64 bit and Internet Explorer 10.
You cannot simply pass multiple command line arguments to your application (unless they're listed explicitly in the registry as you've shown).
Instead, you must code your application's executable so that it is able to process the Application Protocol URL string. So your code is invoked by the browser like so:
C:\apps\myapp.exe "myapp:myParam?myParam2&myParam3&myParam4"
The executable must be able to process this string and handle it appropriately. You must take care to avoid security holes in the parsing of this string, as ANY webpage could exploit a hole here to escape the browser sandbox and attack the user's system.
There's more information on Application Protocols in this post: http://blogs.msdn.com/b/ieinternals/archive/2011/07/14/url-protocols-application-protocols-and-asynchronous-pluggable-protocols-oh-my.aspx

Active windows in Windows and QWidget::activateWindow()

The Qt documentation for QWidget::activateWindow() states:
On Windows, if you are calling this
when the application is not currently
the active one then it will not make
it the active window. It will change
the color of the taskbar entry to
indicate that the window has changed
in some way. This is because Microsoft
does not allow an application to
interrupt what the user is currently
doing in another application.
However, Skype appears to defy this rule. If Skype is running but is not the active application, I can launch it from the start menu and it brings the existing instance to the foreground, activates it and grabs input focus.
And how can I do this?
(NOTE: This is specific to how QtSingleApplication works)
The solution is stupidly simple for my issue. Simply call AllowSetForegroundWindow(ASF_ANY); at the beginning of the application, and the original process will thus be allowed to bring itself to the foreground by use of SetForegroundWindow(). No strange hacks, just one line of code to add and no need to modify QtSingleApplication either.
I don't think you can do it reliably with the Qt API alone.
There are multiple solutions for windows. E.g. here, and here, and here.
The method I've used before is to declare a shared memory section, and write the application's window handle there. Later, when a second instance of your program is started, you can find the window handle of the first and activate it.
I don't think you have the issue of windows preventing you from doing this in this case, because your second instance is the active application, so it is allowed to 'pass focus' to other windows.
Use Single Application in Qt Solutions
For some applications it is useful or
even critical that they are started
only once by any user. Future attempts
to start the application should
activate any already running instance,
and possibly perform requested
actions, e.g. loading a file, in that
instance.
you can set the setWindowOpacity from 0 to 1 .the only thing is you may open it all the time

Resources