How to intercept Windows' "open URL insystem default browser" functionality - windows

Hello, I need to know where/how Windows stores the command that passes the URL clicked in a non-browser program (i.e. Thunderbird) and launches it in the systems default browser.
I need that information to write a script that allows me to have a browser running in a secure sand boxed virtual machine, but still retain the functionality of automatically opening hyperlinks from non-browser programs(i.e. email client on my HOST OS) in the browser of my choosing inside my virtual machine guest OS(xp).
Does anyone know? I'm running Windows Server 2008 R2 if it matters. But I assume most versions of Windows starting with XP, do it the same way.
Thanks
Edit: I found this MS kb article
HKEY_CLASSES_ROOT\http\shell\open\command HKEY_CLASSES_ROOT\http\shell\open\ddeexec
I changed those keys to point to my script, but Firefox on my Host OS still launches, but then complains it is no longer the default browser.
So there must be other registry keys it falls back to besides these.

To open URL in default browser, programs just calls
ShellExecute(0, NULL, "http://...", NULL, NULL, 0)

Related

Open Safari on Mac Client from RDP or Citrix

I have a scenario where I have users accessing our company application either via Citrix or RDP.
The app needs to make a call from within the session to the client pc so it can open a browser for credit card entry.
This is all working okay as I'm using COM to make the call on Windows clients, however I'm not exactly sure how to approach this for Mac.
I believe a start might be able to use AppleScript to open the browser, but not sure on the best way to call the AppleScript. Should I create a C++ app written in xCode.
I'm new to any apple development, so any help or direction would be helpful.
If you have access to the shell on the remote Mac all you need to do to open Safari (or other default browser) is to execute open <URL>, for example:
open http://example.com

Setting mailto: protocol handler programmatically in Windows 8

Before Windows 8, the method of adding a mailto: protocol handler was straightforward (as outlined here Register Windows program with the mailto protocol programmatically)
As of Windows 8, the old method no longer works. It would seem that Win8 enforces the following key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\URLAssociations\‌​MAILTO\UserChoice.
It also appears the ProgID of the selected app is hashed and can't be forged, at least not that I can tell.
Does anyone have a working method for this, or can point me at a utility class/code that'll outline how to accomplish this programmatically?
For code, any language will do.
Edit
I've been asked from other discussions to specify a use-case, so I think it'd be helpful in the context of this question. Please consider this screenshot https://github.com/shellscape/Gmail-Notifier-Plus/raw/master/Promotional/prefs-account.png and the checkbox allowing the user to specify mailto handling. In this use-case, no one is forcing the user, the user is in control and makes the decision. While windows 8 store apps (metro/modern) have an available app manifest entry that automates the missing process described above, nothing seems to readily exist for desktop apps.
You can set your application to be activated by a custom protocol (like mailto:). When the user installs your app, if there is no other app supporting that protocol, they are not prompted and you are automatically assigned to that protocol.
If, however, the user already has an app that handles that protocol, then they will be prompted with a list of apps who support that protocol with the option to select the default. You cannot force the user to make a specific selection.
Also, if the user clicks on a protocol (like myprotocol:) and they have no app installed that handles that protocol then they will be sent to the store (app) which automatically searches for all apps that support that protocol. The user then installs whatever they want. You cannot force the user to make a specific selection (if any at all).
I wrote an article on protocol activation. It might be interesting to you: http://blog.jerrynixon.com/2012/10/walkthrough-using-windows-8-custom.html
So, I made Desktop Firefox my default mailto handler today in Windows 8 by adding the string value "mailto" to the HKCU\Software\Clients\StartMenuInternet\FIREFOX.EXE\Capabilities\URLAssociations and setting the value of "mailto" equal to the ProgID or "FirefoxURL". I then deleted the keys at HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\URLAssociations\‌​MAILTO\UserChoice to allow me to choose the default client again and this time Firefox was available for me to choose.
The essence of this question seems to be that one cannot take over the default client for any protocol anymore (post Windows 8). The user must choose. However, if you wanted to break the OS convention you could hook the call to create the choose default dialog, which would take research, effort, and be only a temporary kludge and would require "breaking" the OS, or you could send a double click to the dialog to choose for the user, assuming your program has elevated rights so that it can send clicks to Admin windows. That would probably be the easiest way, the user would never know what happened, just a quick flash. Really though, after registering itself as a protocol handler, I don't think any program should go beyond deleting the default protocol handler registry entry, thereby forcing the user to re-choose.
This is how to set mailto protocol manually and simply in Windows 8, 8.1, 2012, 2012R2
Add a new registry branch HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\mailto\UserChoice
Then click any mailto: link in your web browser, say IE
and finally there in a program list for you to choose which was not available before.
Also MAILTO appears in Control Panel\All Control Panel Items\Default Programs now. There is no other option to add/remove a protocol from there.
You can't have your app directly take over file associations anymore in Windows 8. There are guidelines for how to handle this for both Windows Store and desktop applications here: http://msdn.microsoft.com/en-us/library/windows/apps/hh700321.aspx

Terminal session when minimized\disconnected returns a blank screen upon capturing desktop snapshot

I am using the below JAVA code to capture the desktop of a remote machine
Robot robot = new Robot();
BufferedImage screenShot = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ByteArrayOutputStream imageBytes = new ByteArrayOutputStream();
ImageIO.write(screenShot, "PNG", imageBytes);
return imageBytes.toByteArray();
However the captured image is blank, when the terminal session to the remote machine is either minimized or disconnected. I appreciate your help in resolving the issue, at the very least the minimized scenario.
Configuration:
I have the same issues with a physical machine running windows 7 and a virtual machine running windows server 2008 R2.
More insights from MSDN:
Why you get black screen when you disconnect from RDP ?
 
http://msdn.microsoft.com/en-us/library/aa383015%28VS.85%29.aspx
Here is my attempt to make things work, but none of the following did the trick:
 
How to get data when RDP window minimized ?
 
You can force the RDP display driver to send data when minized, try these steps and let me know how it goes:
 
1) Add the following key
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client\ Created a new DWORD value and named it RemoteDesktop_SuppressWhenMinimized. Specified 2 as the value data.
Note: Also tried adding the registry key to HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Terminal Server Client\
 
2) Disable bitmap caching (http://technet.microsoft.com/en-us/library/cc737325(WS.10).aspx)
In the Remote Desktop Connection window, click Options.
On the Experience tab, verify that the Bitmap caching check box is selected. Or, to disable bitmap caching, clear theBitmap caching check box
If you minimize the Remote Desktop window, Windows switches the remote session to the GUI-less mode and does not display windows and controls. As a result, TestComplete (or TestExecute) will be unable to interact with the tested application’s GUI, as it does not exist and your automated GUI test will fail.
To work around the issue, you can change the Remote Desktop’s registry settings on your local computer (where you launch the Remote Desktop):
On your local computer, close all open Remote Desktop sessions.
Launch the Registry editor (regedit.exe).
Navigate to one of the following Registry keys, depending on whether you wish to modify the Remote Desktop settings only for the current user or for all users on the computer:
HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client
Create a DWORD value named RemoteDesktop_SuppressWhenMinimized and set it to 2.
Or you can do it programmatically by following steps:
Transparent the window
Restore the Window
Capture
Minimize it again
Remove transparency
We had similar problem in our project last year...we could find any stable and permanent solution....however here is how a work around worked for us...
We had to run on 5 remote desktops (which will take screens capture as well during failure) ..however as you have figured already if we disconnect session or minimise the RDC Window blank screenshot is captured. Therefore we had added one more VM to connect those other five test boxes. The task for that VM is to keep session active and resized to other 5 boxes...this worked for us.
If you connect a remote desktop to the test machine, make sure to reboot the machine when you are done, otherwise the desktop will remain locked and screen captures will not work.
I don't believe there is any other way around the issue.
I just configured the clients to auto logon, disabled the screen saver and installed a VNC server on each client.
Basically, make sure the screen is always on, and don't RDP into them.
This worked on both physical PCs and on virtual machines hosted on a Hyper-V server.
I even wrote a small .NET desktop client that ran multiple VNC clients inside a single window, so we could see what was happening on all the clients. We had an old PC running this with it's monitor on top of a cupboard to (a) let the developers see if any client had hung, had hundreds of browser windows open, etc. and (b) to look impressive for any non-developers walking past.
A simpler alternative to the above answers to to transmute the terminal session (RDP) into the console session. The session will then display to the physical screen (Switching the user of anyone currently logged into the physical machine). The following command does this:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console)

Getting Default browser

How can I determine which is the default browser in my system programatically. The code must be developed using vc++
Is there any API for this ?
Where in the registry is the default browser value stored?
TL;DR: If HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\ exists read that; otherwise read HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\.
After reading the answers here I found little concensus on how to detect the default browser so I did some experiments and research to figure it out. I downloaded the Firefox source, wrote a script that reads a bunch of registry entries and also ran Process Explorer all while changing the default browser over and over.
I found there are a lot of registry keys that Firefox and Chrome change when each sets itself as the default browser. I believe Safari and Opera are both similar in behavior. IE appears to change only one of the registry keys I was watching.
What I found was that while most browsers change other registry paths, all browsers change HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\ (default)
Here are the registry value from the registry key HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\ (default) while each browser is the default browser.
IE 9.0.8112.16421: IEXPLORE.EXE
Chrome 21.0.1180.60 m: Google Chrome
Firefox 10.0.2: FIREFOX.EXE
Safari 3.2.2: Safari.exe
Opera 12.01: Opera
Tested on Microsoft Windows 7 Home Premium SP1 64-bit
Edit:
I found on a fresh install of Windows XP SP3 HKEY_CURRENT_USER\SOFTWARE\Clients\StartMenuInternet\ does not exist. In this case you should read the default browser from HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\. I suspect this is also the case on fresh installs of other versions of Windows.
Addendum:
The ShellExecute method is a great solution if all you want to do is open a web page in the default browser. However, if you want to, for example, install an extension in only the default browser, ShellExecute does not solve the problem.
You normally do not need to know this. ShellExecute(0,0,"http://stackoverflow.com",0,0,SW_SHOWNORMAL); will do the trick. Windows will spot the http:// and figure out from there that you want to open a URL. The "default" webbrowser is pretty much defined as the webbrowser used by Windows for this task.
It's not just http:// which is supported. ShellExecute can start the default webbrowser with https:// URLs as well. For mailto: URLs, it starts the default mail client.
you can find the default browser in the registry
i.e. for Windows XP and Vista is located at
HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\
As its name suggests, StartMenuInternet is for registering a Web browser onto the Start Menu (and it only applies to XP and Vista, it is deprecated starting with Windows 7). That does not necessarily establish the browser as the default browser for the entire system. There are many different ways a browser can be registered for different purposes (loading a file, loading a URL, loading data based on a MIME type, etc). Each of those registrations are separate.
Default Programs
How to Register an Internet Browser or Email Client With the Windows Start Menu
Registering an Application to a URL Protocol
File Types
Personally, I would probably look at the registration of the "http" and/or "https" URL handler to determine the default browser, since that will be the app that loads when the user types a URL into the Start Menu or Windows Explorer, or an app passes a URL to ShellExecute/Ex().
Read the default value of HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet and optionally check HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\XXX\shell\open\command where XXX is that value picked up from the first key.

Changing domain password from TS box inside VPC VM

I'm running a VirtualPC 2007 VM with Windows2003 as the OS. Inside of this I am using a web based VPN to connect to my client's network. I cannot use this VPN from my host machine because it does not work with Vista (still!). Inside the VM I'm connecting to a Terminal Server at the client site which I'm logging into using their domain.
I need to change my password. Obviously what you would normally do is hit ctrl-alt-del and click change password. However since I'm inside of a TS inside of a VM this is not an option. When logging in to the VM I have to press alt-(left arrow)-del and then type in my password. I also know that usually when using remote desktop, in order to simulate a ctrl-alt-del inside there you would press ctrl-alt-end. With this knowledge, I've tried every possible combination of these keys that I can think of, but none of them bring up the Windows Security Dialog Box.
What I'm looking for is either
A way to open the Windows Security Dialog Box (or simply the change password form from there) without pressing ctrl-alt-del (is there a command line I can use?)
A different way to change my domain password without using the aforementioned box

Resources