Capturing Alt+Tab in Citrix sessions

When using a Citrix client to access a remote computer then the Alt + Tab shortcut normally switches out of the client and selects other applications on the client machine. This is most likely not what you expect when being immersed in the remote Windows desktop session. Luckily, there’s a way to let the Citrix client capture the shortcut and switch between applications on the remote desktop:

https://support.citrix.com/article/CTX232298

For 64-bit Windows, put this into a .reg file for easy reuse:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Citrix\ICA Client\Engine\Lockdown Profiles\All Regions\Lockdown\Virtual Channels\Keyboard]
"TransparentKeyPassthrough"="Remote"

Execute the .reg file and restart the Citrix client and you should be good to go.

Note that this setting may be reset when updating the Citrix client so it may have to be reapplied afterwards (hence the use a of .reg file rarther manuall editing the registry).

Related tip

If you experience blurry text in the remote desktop, then this tip might help: https://lazyadmin.nl/it/citrix-receiver-blurry-in-windows-10/

/Emil

Uninstalling McAfee LiveSafe

I recently bought a new computer and as usual there was quite a bit of unwanted software on it, such as McAfeee LiveSafe anti-virus software. Getting rid of it proved near impossible, using normal Windows uninstall procedures resulted in strange error messages and there were services, registry entries and McAfee folders in many places so manual deletion was not really an option either.

Luckily, McAfee has created a utility for uninstalling their software, named McAfee Consumer Product Removal, MCPR. If find it interesting that a separate tool was developed for something so basic as uninstalling the product, but at least it worked. I’m writing this small post to remind myself of it the next time I need it, but maybe someone else will find it useful as well…

The tool is described and can be downloaded here: https://service.mcafee.com/webcenter/portal/cp/home/articleview?articleId=TS101331

/Emil

Changing a dynamic disk into a basic one

I have just removed a SATA hard disk from my old desktop computer and inserted it into an external case from Deltaco so that it could be used from a laptop. Unfortunatly it did not work straight away, no disk showed up in the File Explorer.

Slighty worried, I opened the Disk Manager and there it was shown as “Dynamic” and “Invalid”. More worried, I started googling and found a solution that involved using a hex editor to modify a byte directly on the hard drive to switch it from dynamic into basic. It worked perfectly and the drive now works as expected. I’m not sure what the change means exactly but I’m very happy right now. It felt kind of hard core to use a hex editor to fix a problem like this, that does not happen every day. 🙂

/Emil

Setting the font of a PowerShell console to Lucida Console won’t work

Ever tried changing the font of a PowerShell console to Lucida Console, only to see the setting gone the next time you open the console? In that case, you’re not alone! I’ve been pulling my hair over this problem many times but today I decided to investigate it further.

There are several different solutions and none of them worked for me. For some people it helps if you set the font size to something other than 12 points, but not for me. For others it helps to start the console as administrator, but not for me. And here’s a strange thing: In a good old Command Prompt (CMD.EXE) Lucida Console works as a default font with no problem at all. It’s only in PowerShell console I can’t set it as default.A few of these tricks are discussed at superuser.com.

My problem turned out to be different as it was related to the regional settings of my Windows installations. The problem is described very briefly by a Microsoft support engineer here. Apparently Lucide Console “is not properly supported on CJK languages and other languages that are not localized by PowerShell (e.g. Arabic, Hebrew, etc.)”. It seems that Swedish belongs to the same category of languages that for some reason is not deemed compatible with Lucida Console. Strange thing is that it works perfectly when setting it on the console instance…

Anyway, to fix the problem all I had to do was to change my system locale to “English (United States)”:

Setting system locale to a language that is "supported" for Lucida Console solves the problem...

Setting system locale to a language that is “supported” for Lucida Console solves the problem…

Voila, my PowerShell prompt is pretty everytime I open it, instead of using the ugly “Raster Fonts” which it falled back to before.

The problem description that Lucida Console is not compatible with all languages makes very little sense to me, but at least my problem is solved.

/Emil

Running Windows 8 with wide screen display in VirtualBox

If you have tried running Windows 8 in Virtual Box (a great way to try out a new Windows version before taking the leap to install it as your main OS) you might have noticed that the only display resolutions available are in 4:3 aspect ratio.

To fix this, open a command prompt (PowerShell in my case) do this:

C:\Program Files\Oracle\VirtualBox> .\VBoxManage.exe setextradata “Windows 8 test” CustomVideoMode1 1600x900x24

“Windows 8 test” is the name of the virtual machine in VirtualBox and you can select any resolution you want. Restart the virtual machine if it’s running and after that the new resolution will be available in the Screen Resolution settings inside Windows 8.

Note that it’s possible to add several new resolutions to choose from by using CustomVideoMode1, CustomVideoMode2, etc. This can be useful if you want to move between monitors in multi-monitor setups. To do that in full-screen mode, press <Host>-Home which will show a popup menu where the display can be configured. <Host> is mapped to Right-Ctrl by default.

Credits for this tip:
Running Windows 8 on VirtualBox with Additional Wide Screen Resolution

/Emil

Retrieving the message count for MSMQ queues

Sometimes it can be useful to retrieve the number of messages in an MSMQ queue, for example for monitoring. However, it’s not immediately apparent how to do it if you google it, so here are my thoughts on the subject.

Other blog posts suggest iterating over messages (e.g. Counting Messages in an MSMQ MessageQueue from C#) or doing it using WMI. WMI is the best alternative in my opinion and if you want a quick way of doing it then PowerShell is the easiest:

$queues = Get-WmiObject Win32_PerfFormattedData_msmq_MSMQQueue
$queues | ft -property Name,MessagesInQueue

The result will be something similar to this:

Name                                                         MessagesInQueue
----                                                         ---------------
active714\private$\notify_queue$                                           0
active714\private$\deltagarloggservice\deltagarloggservi...                0
active714\private$\order_queue$                                            0
active714\private$\admin_queue$                                            0
Computer Queues                                                           27

This can also be done on remote machines:

$host = ...
$cred = get-credential
$queues = Get-WmiObject Win32_PerfFormattedData_msmq_MSMQQueue -computer $host -credential $cred
$queues | ft -property Name,MessagesInQueue

The Get-Credential Cmdlet will display a login dialog which is fine in interactive sessions but if you need to set the credentials in a non-interactive script, then the tip in this blog post might help: PowerShell – How to create a PSCredential object.

Retrieving message counts from code takes a little more coding but here’s an example in C# that searches for a given queue and returns its message count:

private static int GetMsmqMessageCount(string queuePath, string machine,
  string username, string password)
{
  var options = new ConnectionOptions
    {Username = username, Password = password};
  var path = string.Format(@"\\{0}\root\CIMv2", machine);
  var scope = new ManagementScope(path, options);
  scope.Connect();

  string queryString = 
    String.Format("SELECT * FROM Win32_PerfFormattedData_msmq_MSMQQueue WHERE Name = '{0}'",
	  queuePath);
  var query = new ObjectQuery(queryString);

  var searcher = new ManagementObjectSearcher(scope, query);

  IEnumerable<int> messageCountEnumerable = 
    from ManagementObject queue in searcher.Get()
    select (int) (UInt64) queue.GetPropertyValue("MessagesInQueue");

  return messageCountEnumerable.First();
}

This code also uses WMI but this time we do a query rather than enumerate all queues.

The above snippets has worked well for us so I felt it would be useful to post them here. Please leave a comment if you have issues with them or suggestions for improvement!

/Emil

Calling a PowerShell script from a Windows shortcut

Executing a PowerShell script from outside PowerShell (for example via a Windows shortcut) can be a little complicated, especially if the path to the script contains spaces and it has parameters, so here’s how to do it:

powershell.exe -command "& 'C:\A path with spaces\login.ps1' -password XXX"

Note that I’m using the PowerShell & operator to execute the script. This is because I have to surround the path with quotes so that it’s interpreted by PowerShell as a single literal even though it contains spaces. If I would leave out the “&” then the quoted string would simply be interpreted as a string literal to output, so the script would not be executed.

The parameters to the script should not be included within the single quotes since they are not part of the first literal, which should only contain the path to the script to execute.

/Emil

Working with remote Windows services in PowerShell

Here’s how to list, start and stop Windows services on a remote computer using PowerShell:

[reflection.assembly]::loadwithpartialname("System.ServiceProcess")

# List all services on the remote computer
[System.ServiceProcess.ServiceController]::GetServices('10.123.123.125')

# Stop the service and wait for it to change status
$service = (new-object System.ServiceProcess.ServiceController('Service name','10.123.123.125'))
$service.WaitForStatus('Stopped',(new-timespan -seconds 5))
$service.Stop()

# Start the service again
$service.Start()

This can come in really handy in deployment scripts, etc.

(Parts of this post came from The PowerShell Guy).

/Emil

Update: In the earlier version of this post I used new-object every time I needed a reference to the service. That’s not necessary, it’s much prettier to use a variable for the reference, so I have now updated the code.

Zune Desktop Theme for Windows XP

Tired of your old Windows XP theme? Can’t decide which color scheme is the least ugly (blue, olive green or silver)?

Then why not try the Zune Desktop Theme for Windows XP? It’s designed to resemble the look of the Zune player, so I suppose its purpose is to inspire an interest in that device. Still, it looks quite good if you ask me:

zunetheme_crop

If you’re interested, download the theme here:

http://go.microsoft.com/fwlink/?LinkID=75078

Windows hibernation problems – solved!

Do you use the hibernation feature of Windows? Ever had any problems with it? I suspect that the answers to these two questions generally are the same…

Firstly, if you’re using Windows XP and have more than 2 GB of RAM, it doesn’t work. Fortunately there’s a fix. For more info, see here.

Secondly, you’re likely to have run into a host of other problems. My experiences include:

  • Hibernation works, but the computer is immediately awakened
  • Instead of hibernating, the computer is turned off
  • Instead of hibernating, I’m logged out to the welcome screen

All these are extremely irritating, of course. Fortunately I’ve found a solution to all my problems so far, namely a little known but excellent free tool called MCE Standby tool (MST) that helps you configure the hibernation options. If you have similar problems to mine, give it a go!

When you install the tool, it puts a small, green “power” icon in the system tray:

To configure the hibernation options, right-click the system tray icon, and the main window is displayed:

To fix my two last problems above, I changed Selected sleep state to “S3”, restarted the computer (might be unnecessary) and then changed back to “S4”. Voilá, problems gone.

If you have problems with the computer awakening immediately after hibernation then it might be a USB-connected device that’s waking the computer up (a mouse, keyboard, remote control receiver, etc). To fix this, you can select which deviced should be allowed to wake the computer up and this is done in the Devices tab:

Deselect all devices you suspect to be causing problems, and no awakening should occur. For me it was my keyboard.

There are more options in the useful little tool, but these are the ones that helped me so far. Give it a try if you have similar problems!

/Emil

BTW, “MCE” in the tools name stands for “Media Center Edition” indicating that hibernation problems can often be related to media systems. And indeed, many of my problems started after I installed Media Portal. My advice concerning that system is of course to keep away from it…