Add “Open with” for any executable to the Explorer context menu

 Windows  Comments Off on Add “Open with” for any executable to the Explorer context menu
Jun 102019
 

Many tools optionally add an “Open with [Name of tool]” entry to the context menu of the Windows Explorer. Some others don’t, even though it would be useful. Here is how to do it yourself:

  1. Open any text editor (Notepad will do)
  2. Copy and paste the following text into it:
    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\*\shell\Open with [DisplayName]\command]
    @="[Path\\to\\executable] %1"
    
  3. Replace [DisplayName] with the name of the tool.
  4. Replace [Path\\to\\executable] with the full path of the executable to open. Not that you must replace all backslashes with a dual backslash for this to work.
  5. Save the file as “Add-Open-with-MyTool-to-Context-Menu.reg”. Make sure that it is saved as a .reg file, not as a .txt file! (One of the annoyances of Notepad.)
  6. Open the created file with a double click and let the Registry Editor add it to the Registry

Examples:

Open with (portable) Notepad++

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\Open with Notepad++\command]
@="C:\\PortableApps\\Notepad++Portable\\Notepad++Portable.exe %1"

Notepad++ is a free and powerful replacement for Notepad and can be downloaded from notepad-plus-plus.org.

Open with (portable) HxD

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Open with HxD\command]
@="C:\\PortableApps\\HxD\\HxD64.exe %1"

HxD is a free and powerful hex editor and can be downloaded from https://mh-nexus.de/en/hxd/.

Created entries

The created entries look like this:

 Posted by on 2019-06-10 at 11:53

Installing dotNet 2.0 on Windows 10

 Windows, Windows 10  Comments Off on Installing dotNet 2.0 on Windows 10
May 232019
 

In theory it is simple to install the dotNet 2.0 framework on Windows 10: Just go to “Programs and Features”, select “Turn Windows Features on or off”, set the checkmark for “.NET Framework 3.5 (includes .NET 2.0 and 3.0)”, press OK and let Windows download the necessary files from Windows Update.

Unfortunately this only works most of the time. If you are unlucky like me and it doesn’t, you will start an odyssey of downloading installers from Microsoft (which also fail, because they try to download files from Windows Update for whatever reason), using the dism tool and possibly Power Shell to install it offline (both of which failed too in my case) and then either despair or find a reference to the “Missed Features Installer”.

When I arrived there, I was very suspicious (and so should you!) of downloading and using such a 3rd party installer. I used the download from Computer Bild not because I think they are the most brilliant computer magazine in Germany (they are not) but at least I trust them not to distribute malware (which is more than I trust the computer magazine CHIP). In addition, I used Virus Total to scan the installer. It gave me a thumbs up, so I was brave enough to run it.

Guess what? It worked. I now have a working .NET 3.5 and 2.0 framework on my computer and could finally install the program I actually wanted to install: The AVT Universal Package for accessing a camera.

 Posted by on 2019-05-23 at 18:29

Blocking the Windows Screen Saver in Delphi

 Delphi, Windows, Windows 10, Windows 7, Windows 8.1  Comments Off on Blocking the Windows Screen Saver in Delphi
May 222019
 

Sometimes your program needs to block the screen saver from automatically kicking in. My use case was that the program was recording data and whenever the screen saver was active, the data was lost (No idea why, it probably had something to do with the way HID is implemented in Windows.)
So I was looking for a way to fix that without forcing the user to turn off the screen saver. The methods that used to work under Windows XP no longer work in Windows 7 and later (I don’t care about Vista), so I googled and found this question on StackOverflow. The Windows API functions PowerCreateRequest + PowerSetRequest mentioned in the highest voted answer looked promising. Unfortunately they don’t seem bo be available in Delphi (Delphi 2007, which I used for that project, is too old to know them, but I coudn’t find them in Delphi 10.3 either). The first task was therefore to get a function declaration for Delphi. Google didn’t help here which meant that I had do create them myself. Not a big deal:

type
  TPowerCreateRequest = function(_Context: PReasonContext): THandle; stdcall;
  TPowerSetRequest = function(_Handle: THandle; _RequestType: TPowerRequestType): LongBool; stdcall;
  TPowerClearRequest = function(_Handle: THandle; _RequestType: TPowerRequestType): LongBool; stdcall;

I prefer loading such functions at runtime rather than the program not starting because some external reference is not avaiable. These functions are exported by kernel32.dll.

  FDllHandle := SafeLoadLibrary(kernel32);
  PowerCreateRequest := GetProcAddress(FDllHandle, 'PowerCreateRequest');
  PowerSetRequest := GetProcAddress(FDllHandle, 'PowerSetRequest');
  PowerClearRequest := GetProcAddress(FDllHandle, 'PowerClearRequest');
  if not Assigned(PowerCreateRequest) or not Assigned(PowerSetRequest) or not Assigned(PowerClearRequest) then
    raise EOsFunc.Create(_('Could not initialize the PowerXxxxRequest functions from kernel32.'));

Usage is not without its own problems. First, I had to declare the constants and parameters:

const
  POWER_REQUEST_CONTEXT_VERSION = 0;
  POWER_REQUEST_CONTEXT_DETAILED_STRING = 2;
  POWER_REQUEST_CONTEXT_SIMPLE_STRING = 1;
type
  PReasonContext = ^TReasonContext;
  TReasonContext = record
    Version: ULONG;
    Flags: DWORD;
    case Boolean of
      False: (
        SimpleReasonString: PWideChar;
        );
      True: (
        Detailed: record
          LocalizedReasonModule: HMODULE;
          LocalizedReasonId: ULONG;
          ReasonStringCount: ULONG;
          ReasonStrings: PPWideChar;
        end;
        );
  end;
type
  TPowerRequestType = (
    PowerRequestDisplayRequired = 0,
    PowerRequestSystemRequired = 1,
    PowerRequestAwayModeRequired = 2,
    PowerRequestExecutionRequired = 3);

Now, how do these functions work?

The first thing to do is creating a power request with PowerCreateRequest. This function requires a PReasonContext pointer which must be initialized correctly. The Version and Flags fields are simple: Assign one of the POWER_REQUEST_CONTEXT_xxx constants declared above. But what aobut the other fields? I decided to go with the simple case, that is: Set Flags to POWER_REQUEST_CONTEXT_SIMPLE_STRING and provide a value for SimpleReasonString.

var
  FRequestHandle: THandle;
  FContext: TReasonContext;
  FReason: array[0..255] of WideChar;
  // [...]
  FContext.Version := POWER_REQUEST_CONTEXT_VERSION;
  FContext.Flags := POWER_REQUEST_CONTEXT_SIMPLE_STRING;
  FContext.SimpleReasonString := @FReason;
  FRequestHandle := PowerCreateRequest(@FContext);
  if FRequestHandle = INVALID_HANDLE_VALUE then
    RaiseLastOSError;

Where FReason is an array of WideChar. My tests showed that the TReasonContext record and the reason string it points to must be available through the lifetime of the reason context. If it isn’t, the reason displayed by the powercfg tool (see below) will be corrupted. Therefore I did not use a WideString but a static array.

After the power request has been created, calls to PowerSetRequest and PowerClearRequest are possible.

  Win32Check(PowerSetRequest(FRequestHandle, PowerRequestDisplayRequired));

This call prevents the screen saver from starting automatically. A call to PowerClearRequest supposedly turns that off again (but I haven’t tested it).

I mentionend the powercfg tool above. It’s a Windows command line tool that among other functionality can display processes that have active power requests. e.g.

powercfg /requests
DISPLAY:
[PROCESS] \Device\HarddiskVolume2\Source\dzlib\tests\BlockScreenSaver\BlockScreenSaver.exe
test

SYSTEM:
None.

AWAYMODE:
None.

EXECUTION:
None.

PERFBOOST:
None.

The string “test” is the reason I passed to PowerCreateRequests.

I mentioned that failing to preserver the reason string results in a corrupted message in the display. It looked like this:

powercfg /requests
DISPLAY:
[PROCESS] \Device\HarddiskVolume2\Source\dzlib\tests\BlockScreenSaver\BlockScreenSaver.exe
?a?E?I???↑?E?↑?E?↑?E?↑?E?↑

Note that this tool requires administrator privileges (but power requests don’t).

I have added this code to my dzlib. It’s in u_dzOsUtils. There is also a simple test / demo program BlockScreenSaver.

If you would like to comment on this, go to this post in the international Delphi Praxis forum.

 Posted by on 2019-05-22 at 14:15

Deleting unwanted entries from the “New” submenu of Windows Explorer

 Batch, Windows  Comments Off on Deleting unwanted entries from the “New” submenu of Windows Explorer
Apr 092019
 

Microsoft Office has the annoying habit of adding itself to various places in the Windows user interface. One of them is the popup menu of the Windows Explorer. It adds one entry for each of the installed programs to the “New” submenu.

Have you ever used them? I have only used that submenu for creating folders, shortcuts and text files, but never ever (apart from trying it once I think) for creating new MS Office documents.

So I have removed these entries several times (every time having to google the process) but every update recreates the entries and today I’ve had enough.

So here is a cmd file which will delete them (works for Office 2016 only). You will have to run it as administrator to work.

@echo off
echo This batch file will delete the Registry entries for
echo the "New" submenu of Windows Explorer
echo added by MS Office 2016.
echo This batch file must be run as Administrator.
echo Continue?
pause
reg delete HKEY_CLASSES_ROOT\.docx\Word.Document.12\ShellNew /f
reg delete HKEY_CLASSES_ROOT\.xlsx\Excel.Sheet.12\ShellNew /f
reg delete HKEY_CLASSES_ROOT\.pptx\PowerPoint.Show.12\ShellNew /f
pause

download link

It uses the built in reg command. The /f switch forces the deletion without confirmation. Maybe you want to remove it.

As always: Check any exectuable code you download from the Internet! It might damage your computer.

 Posted by on 2019-04-09 at 11:27

How to defeat useful tools

 Windows  Comments Off on How to defeat useful tools
Apr 042019
 

Sizer is a very useful tool for sizing and positioning windows. It adds a right click menu to a window’s title bar where you can select one of multiple configured window sizes and positions. It also displays the current window size while you are resizing it by dragging its frame.

Now, why would somebody try to defeat the usability of this tool?

Because they can?

Google and Mozilla did exactly that: By moving the tab bar into the window title. In Chrome, Thunderbird and Firefox right clicking on the title bar no longer brigs up the Sizer menu. In Chrome at least clicking on the window frame still gets this menu. Both browsers also prevent the size display while dragging the frame which at least works for Thunderbird.

And now guess which windows I would like to use Sizer the most?

Some software developers should be shot, just so they don’t have a bad influence on others.

(Since nowadays it apparently is necessary to explicitly say that: No, I don’t want anybody to take this as an ecouragement to commit a felony or act of terror.)

 Posted by on 2019-04-04 at 10:16

Don’t give the user any information!

 Windows, Windows 10, Windows 7  Comments Off on Don’t give the user any information!
Mar 282019
 

… seems to be the motto of Microsoft.

How else can you explain that a recent update of Windows 7 and Windows 10, that broke older versions of one of our programs (no idea yet what exactly is the problem, but the error code indicates an out of memory error) has different effects.

Windows 7 shows a dialog that the program could not be started and even gives some additional information. But that’s not good enough, the user could be irritated by telling him a program has crashed. So Windows 10 goes a step further and simply does … nothing. The program starts (as you can verify in the task manager), but nothing appears on the screen.

If you have administrator privileges, you can look into the event log (If know how to do that). If you haven’t or don’t know how to, you are lost.

<sarcasm>Great feature, guys!</sarcasm>

 Posted by on 2019-03-28 at 16:04

DeltaChat Messenger

 Android, Linux, Windows  Comments Off on DeltaChat Messenger
Jan 272019
 

DeltaChat is a messenger that uses email as the transport medium, so potentially almost everybody already has an account for it. Today, they announced a new release, not only for the existing Android app but also for Desktop (Mac and Linux only so far) and iOS.

I think that is a very interesting project since it does not require yet another central server. It also supports encryption using the Autocrypt Level 1 standard, if both ends use DeltaChat. It is possible to use the same protocol (but without encryption) between DeltaChat and a regular email program.

In my tests with the older Android release it worked well. I created a new email address specifically for DeltaChat. That’s what I would suggest to everybody who wants to use it. I plan to replace Google Hangouts with DeltaChat when Hangouts gets shut down later this year. But I would need a Windows client first.

 Posted by on 2019-01-27 at 14:06

Completely disable Windows 10 telemetry collection

 Windows, Windows 10  Comments Off on Completely disable Windows 10 telemetry collection
Jan 072019
 

So I don’t forget: According to an article in c’t magazine, disabling the “DiagTrack” service (“Connected User Experience and Telemetry”) will completely disable user tracking in Windows 10. They also say that they did not see any negative effects.

Source: Telefonierverbot in c’t 01/2019 page 172 (in German)

 Posted by on 2019-01-07 at 15:57

If Ctrl+Alt+F8 disables your secondary monitor

 Windows  Comments Off on If Ctrl+Alt+F8 disables your secondary monitor
Nov 182018
 

I just pressed Ctrl+Alt+F8 and wondered why all of a sudden my secondary monitor went blank. Turns out that this is a “Feature” of the Intel HD graphics driver.

It restores the graphics default.

And since it is such a great feature, you can’t disable or customize this hotkey. Great work Intel!

Again StackOverflow was helpful. It also provided a workaround: Using AutoHotkey you catch that hotkey to do something else, e.g. show a dialog. And since I already use AutoHotkey, I added the following to my default script:

; Disable the shortcut of the Intel Graphics driver for resetting the graphics settings
; Whoever came up with this functionality and made it impossible to disable the shortcut
; is an idiot!
^!f8::msgbox, You hit Ctrl+Alt+F8 which would have reset the Intel graphics card settings to default.
 Posted by on 2018-11-18 at 16:52

USB tethering a OnePlus One phone to Windows XP

 Android, Windows  Comments Off on USB tethering a OnePlus One phone to Windows XP
Jun 102018
 

For whatever reason my old Windows XP netbook doesn’t connect to our holiday flat’s WIFI while my OnePlus One Android phone does. So I thought I’d simply tether it to the Netbook via USB to get around this problem. I tried that before with other phones and other computers and don’t remember ever having a problem. This time I got a prompt to install a driver for a rndis device, which failed because I had no Internet connection (It might also have failed if I had one but I couldn’t try.)

So I turned to Google and found multiple posts suggesting to download a tetherxp.inf file and simply use that to install the drivers which apparently are already available in a standard Windows XP installation.

I downloaded that file from one of the links, put it in an empty folder and tried to install it. No luck. It took me a while to find this post on quora, which contains an additional point:

4. Now this is where some of you will get lost, you need to open up the tetherxp.inf file with your favorite code editor (Start->Run->Wordpad). Create a new line below “[AndroidDevices.NT.5.1]” containing your Device Instance Id.

This turned out to be the important part: The tetherxp.inf file contained entries for several widely used phones, but of course not for my rather rare one, so I had to add two lines to it:

[AndroidDevices]
; OnePlus One without adb
%AndroidDevice%    = RNDIS, USB\VID_05C6&PID_676A

[AndroidDevices.NT.5.1]
; OnePlus One without adb
%AndroidDevice%    = RNDIS.NT.5.1, USB\VID_05C6&PID_676A

The part after “USB\” is taken from the details pane of the “rndis” device in the hardware manager.

After adding these two lines I switched back to the “Driver” tab and clicked “Install Driver”. In the following Wizard, I selected “No, not this time” -> “Next” -> “Install from a list or specific location” -> “Next” -> “Don’t search, I’ll choose the driver to install” -> “Next” -> “Have Disk” -> “Browse”. Then I selected the modified tetherxp.inf file and pressed “Open” and “OK” and “Next” again. I then had to tell Windows to ignore that the “Driver” was not digitally signed to finally really get it to install it.

Diesmal funktioniert alles. (Spliff, “Computer sind doof”).

 Posted by on 2018-06-10 at 21:55