Enhanced CPU Stress Tool

June 11, 2016

The old (but still useful) tool called CPUSTRES (notice the 8-character name) allows simulating CPU activity with up to 4 threads, which can be controlled with activity level and priority. The tool can be downloaded from http://live.sysinternals.com/windowsinternals. Here's a screenshot: Old timers may recognize the tool's icon as the default MFC icon used with Visual C++ 6. The tool still works, but its age is showing (the binary has been modified in 1999). It has no minimize button, no way to create more threads, no way to change settings for multiple threads at a time, and lacks some other features that...
no comments

WPF Tip – Limiting the number of items in an ItemsControl

May 29, 2016

This sounds like a simple thing – how do we limit the number of items in an ItemsControl or one of its derivatives, such as a DataGrid. The problem is that the DataGrid can be sorted and perhaps filtered using an ICollectionView. Let's say we have a DataGrid that shows a list of Process objects with some of their properties shown. Sorting comes practically for free – we just need to set the SortMemberPath of a DataGridColumn and the DataGrid will take care of the rest. Let's further assume that we have a TextBox that allows filtering of process objects by...
no comments

QSlice – WPF Style

May 21, 2016

Old timers may be familiar with the Windows NT/2000 Resource kit tool named QSlice that shows the relative CPU consumption of processes graphically. QSlice can still be found floating on the web somewhere. Here's a screenshot: It still works on Windows 10 version 1511 ("Threshold 2"), but fails to launch properly on latest builds of "Redstone 1" ("Anniversary Update"). Regardless, I thought it was high time to create a modern sequel to QSlice, given that the original has poor user interface – no sorting or filtering (always sorted by process ID). I created a WPF version of QSlice, complete with sorting...
no comments

Code Injection with Image File Execution Options

April 9, 2016

A well-known features of Windows is the Image File Execution Options registry key located in HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options. Under that key, key names with executable files (e.g. Notepad.exe) can be created and various options can be set. These options are observed when a process with the key name (from any directory) is about to be created. A convenient tool to set these options is the Gflags.exe utility, available as part of the Debugging Tools for Windows. One of the useful values is "Debugger" that allows another process (typically a debugger) to be launched when the specific executable is...
3 comments

Tip for using static in C# 6

January 1, 2016

One of the new features introduced in C# 6 is the "using static" keyword that is aimed at simplifying repeated access to static members of a particular class. A classic example is using Console.WriteLine a lot. In this case it can be simplified. Instead of: class Program {    static void Main(string args) {        Console.WriteLine("Hello, world!");        Console.WriteLine("This is C# 6 in action!");    }}  We can write: using static System.Console; class Program {    static void Main(string args) {        WriteLine("Hello, world!");        WriteLine("This is C# 6 in action!");    }}  Another common example might be using a lot of math calculations with the static methods of the System.Math class. Here's some method calculating points along the circumference of a circle: static IEnumerable<Point> CalcPoints(double radius, int count) {    for(int i = 0; i < count; i++) {        var x = radius * Math.Cos(2 * Math.PI * i / count);        var y = radius * Math.Sin(2 * Math.PI * i / count);        yield return new Point(x, y);    }}  All that Math stuff can be simplified like so: using static System.Math; … static IEnumerable<Point> CalcPoints(double radius, int count) {    for(int i = 0; i < count; i++) {        var x = radius * Cos(2 * PI * i / count);        var y = radius * Sin(2 * PI * i / count);        yield return new Point(x, y);    }}  Certainly convenient. One feature that is still missing, in my humble opinion, is allowing "using static"...
no comments

The many ways of getting process information

November 29, 2015

Processes are one of the most fundamental building blocks in Windows (and most other operating systems for that matter, even if the term is differently named). These are management objects, managing various resources such as memory and handles, to be used by actual executing threads within that process. Various tools, such as Task Manager and Process Explorer show information about processes, but how can we get that information programmatically? At first, it seems rather easy. If we’re working in .NET, then all we have to do is call the static Process.GetProcesses method and receive back an array of...
no comments

Launching Windows Store Apps Programmatically

October 24, 2015

Windows Apps (a.k.a. Store apps or Metro apps) run in a dedicated sandbox, providing “extra protection” from outside apps and OS as opposed to classic Windows applications. One consequence of this is that launching a Windows App using a classic CreateProcess call will generally fail. For example, if we run the Weather app that comes with Windows and look at the command line that was used to start the process (e.g. using Task Manager or Process Explorer), this is what we see: "C:\Program Files\WindowsApps\Microsoft.BingWeather_4.6.169.0_x86__8wekyb3d8bbwe\Microsoft.Msn.Weather.exe"      -ServerName:App.AppX2m6wj6jceb8yq7ppx1b3drf7yy51ha6f.mca Clearly, there...
one comment

RegRenameKey – Hidden registry API

September 29, 2015

While working on a pet project called Registry Explorer (yes, I know there are a bunch of those floating around, most of them pretty old) to be yet another RegEdit.exe replacement, I wanted to add the option to rename a registry key (which RegEdit.exe allows as well). However, looking at the registry APIs (both managed and native) there seems to be no function to rename a key. The closest is the ability to copy a key (with its subkeys and values) via RegCopyTree, so that I can copy the original key with the new name and delete the original...
one comment

Mandelbrot Set with Xamarin Forms (part 1)

August 11, 2015

Reader following my blog already know of my fondness of the Mandelbrot Set. I’ve written versions for WPF, Silverlight, Windows Phone Silverlight, the Windows Runtime and even C++ AMP. Missing still are the Windows 10 Universal Windows Platform and Xamarin Forms. In this post (and the next) I’ll tackle Xamarin Forms. If you’re not familiar with Xamarin Forms, it’s a cross platform library for writing mobile apps for iOS, Android and Windows Phone – all with the C# language and .NET principles. It’s based on “classic” Xamarin, where the application logic could be written just once for all...
no comments

Writing a Simple Debugger with DbgEng.Dll

July 27, 2015

In my post on using CLRMD’s debugger engine wrappers to “debug” a dump file, I’ve shown how we can take advantage of the documented API of DbgEng.Dll – the debugger engine that drives the Microsoft debuggers – CDB, NTSD, KD and WinDbg. In this post, we’ll take a step further and create a basic functioning user mode debugger that is able to attach to a process and do “normal” debugging, somewhat similar to CDB/NTSD but with some small colorful bonuses. As you may recall, I’ve taken the CLRMD project and made some enhancements to the callback interop types...
no comments