login vsi company logo login vsi company logo 250x40
  • Home
  • Login VSI Blog
  • Solve Multi User Issues In Environments without App-V by Using Expandable Strings

Solve Multi User Issues In Environments without App-V by Using Expandable Strings

Solve Multi User Issues In Environments without App-V by Using Expandable Strings

I’m describing a situation that is typically solved by application virtualization using Microsoft App-V or any other application virtualization product but I still encounter a lot of companies that do not want to virtualize their apps. In my mind, with good reason. This post is about a simple trick using the Windows registry that may help you to personalize an application that stores its settings in HKEY_LOCAL_MACHINE. The trick is about strings and expandable strings.

Imagine an application called BadApp. Now, imagine that when the BadApp is installed, the installer of BadApp stores some settings about BadApp in HKLM. One of these settings could for instance be where BadApp stores its cache (or whatever). In the registry a value with the following settings may have been added:

registry editor badapp

Registry Editor BadApp

Now when a different user logs on to the system and tries to use BadApp, the application doesn’t work properly. Very annoying indeed. On a traditional desktop the solution to this issue may not prove too difficult to solve; simply change the value to c:\BadAppCache right? But on a terminal server this may not be the right answer because you would end up with multiple users using the same cache folder (as BadApp is an imaginary app and I have no idea what is does and why this cache is needed, my gut feeling tells me that I should share this cache with multiple users).

If I use my primary interface to windows and retrieve the value of CacheLocation, I would see this very unsurprising result:

windows powershell value of cachelocation

Windows PowerShell value of CacheLocation

I really want this value to point to my profile, instead of the administrator’s profile. So let’s try to change the registry value like this:

registry editor

Registry Editor

So let’s look at the output of my PowerShell command again:

windows powershell command

Windows PowerShell command

Again, not very surprising. Depending on how the application was written, this may have solved the problem. Only way to find out is to start BadApp and see what happens. Unfortunately, I did a mental launch of BadApp and I must info that BadApp failed to launch with the error message:

BadApp failed: could not find the path “%userprofile%\BadApp\Cache”.

So, now let’s try something different. Let’s change the type of the registry value from a string (REG_SZ) to an expandable string (REG_EXPAND_SZ) and see what happens (apart from the wider screenshot):

expandable string

Registry Editor - expandable string

And the output:

windows powershell output

Windows PowerShell output

As you can see, the value is first expanded and then displayed. Below, you will find some C code that uses the Win32 API to read the content of a string value from the registry. This code does not enforce the registry value to be a REG_SZ and will behave in the same way as the PowerShell example I’ve shown earlier.

#include"stdafx.h"
#include<windows.h>
#include<stdio.h>
int_tmain(int argc, _TCHAR* argv[])
{
      LONG returnStatus;
      DWORD Size=0; 
      returnStatus = RegGetValueA(HKEY_LOCAL_MACHINE, (LPCSTR) 
"SOFTWARE\\ BadApp", (LPCSTR) "CacheLocation",RRF_RT_ANY,NULL, NULL, (LPDWORD) &Size);         
      char * buffer = (char *) malloc(Size);         
      returnStatus = RegGetValueA(HKEY_LOCAL_MACHINE, (LPCSTR) 
"SOFTWARE\\ BadApp", (LPCSTR) "CacheLocation",RRF_RT_ANY,NULL, (LPBYTE)buffer, (LPDWORD) &Size);         
      printf("Value from registry %s\n",buffer);         
      delete [] buffer;         
      system("pause"); 
}          

The code above produces the following output:

badapp output

Code output

So does this work for all applications? I’m afraid not, it depends on how the application was written. But see it as yet another tool in your toolkit that may allow for a simple solution to a simple problem.

By the way, if you need to convert a string value to an expandable string in a .reg file you might find the PowerShell code below to suite your needs:

"%userprofile%\BadApp\Cache" | %{"hex(2):" + [string]::join(",",( ([char[]] $_) | %{ "{0:X4}" -f [int16] $_ } | %{"$($_[2])$($_[3]),$($_[0])$($_[1])"})) +",00,00"}

Hope this trick also works for you.

Tags: How-to, Microsoft

Popular Blogs

Login VSI - Press Release - Login VSI Releases Login Enterprise 4.0

[Press Release] Login VSI Releases Login Enterprise 4.0

Login VSI Releases Login Enterprise 4.0 New Application Load Testing Functionality Maximizes End-User Experience Continue Reading
Windows Virtual Desktop - Update - December 2019

Windows Virtual Desktop Enhanced in the Latest Update

A lot has already been written about WVD in the last months. And while I had my initial concerns on this service many people are suggesting that they are willing to move to a platform like WVD in the next two years. Continue Reading
[Press Release] IGEL Expands Alliance with Login VSI; Integrates Login Enterprise into IGEL OS 11.03

[Press Release] IGEL Expands Alliance with Login VSI

Integrating Login Enterprise into IGEL OS 11.03 The combined solution enables IT organizations to leverage their IGEL infrastructure to continuously test the performance and availability of virtual and cloud workspaces. Continue Reading
How Using a Virtual User can Quantify the Performance of SAP and Citrix

How Using a Virtual User can Quantify the Performance of SAP and Citrix

When interacting with enterprise applications, the user experience is important. Users must be able to smoothly and efficiently interact with the application to be productive and achieve the goals of the enterprise. The applications are expected to be responsive, dependable, and consistent in their presentation. Continue Reading
Login VSI and Ymor Form Partnership to Deliver Performance Improvement to Business-Critical Applications

[Press Release] Login VSI and Ymor Form Partnership to Deliver Performance Improvement to Business-Critical Applications

The partnership offers a total solution for enterprise organizations to monitor and test business-critical applications from end-to-end via VDI or in the Cloud. Ymor offers various monitoring solutions, used to test and monitor the performance of critical business chains from end-to-end. In VDI environments, Ymor can now offer the monitoring solutions of Login VSI. Continue Reading
Login VSI - Blog - 4 Things to Consider when Running Office 365 in the Cloud

4 Things to Consider when Running Office 365 in the Cloud

Recently a customer decided to move their entire VDI infrastructure into the cloud. The VDI environment was approximately 20,000 users. As you can imagine there are a lot of design decisions necessary to ensure the success of this migration. Continue Reading