login vsi company logo login vsi company logo 250x40


Get the best possible VDI performance, density and availability with Login VSI
Our Solutions

  • Home
  • 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.

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;         

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.



Start using Login VSI today

Our industry-standard software is built to help you avoid problems, lower costs and improve performance. Request a Quote or get your free Trial below, and benefit from our award-winning services.

Free Price Request  Your Free Trial


About the company Login VSI

The company Login VSI provides end-user performance insights for virtualized desktop and server-based computing environments. Enterprise IT departments use flagship product Login VSI (for load testing) and Login PI (for continuity testing) in all phases of their virtual desktop deployment—from planning to deployment to change management—to build and safeguard a good performance, a high availability, and (as a result) a good and consistent end-user experience. For more information about Login VSI or for a free test license contact us.

Tags: How-to, Microsoft

Popular Blogs

Login VSI Blog - Ongoing Effects CPU Flaws

The Ongoing Effects of Intel CPU Flaws

The Ongoing Effects of Intel CPU Flaws Over the last year, we’ve seen many Intel CPU hardware flaws come to light and when news first broke about Meltdown & Spectre there was a lot of panic: "should we patch?", "What’s the performance impact?", "Can we still rely on this hardware?" Continue Reading
Login VSI Blog - Updating to Windows 10 1903? Make Sure to Test!

Updating to Windows 10 1903? Make Sure to Test!

Updating to Windows 10 1903? Make Sure to Test! It’s that time of the year again. Microsoft have released their spring update and the first IT-Pro’s are getting ready to move their VDI environment over. Continue Reading
Login VSI officially recognized as an integration partner for WVD by Microsoft

Windows Virtual Desktop

I’m excited to share with you that as of this week Login VSI has officially been recognized as an integration partner for Windows Virtual Desktop (WVD) by Microsoft. Continue Reading
Join us at VMworld 2019 - Booth #866

Join us at VMworld 2019 - Booth #866

Join us at VMworld 2019 - Booth #866 Are you attending VMworld in San Francisco next week? Great, we are too! Continue Reading
State Of The Union Survey Results 2019

State of EUC Survey Results

State of EUC Survey Results At community site VDILIKEAPRO.com we recently surveyed almost 600 people who work in the End User Computing (EUC) industry with a focus on VDI and SBC. Continue Reading
Login VSI at VMworld 2019 - Our Debrief

VMworld 2019 - Our Debrief

VMworld 2019 It’s that time of the year again, we’ve just wrapped up VMworld US and it was great meeting many folks on the expo floor, vendor booths, sessions and of course for a drink in the evening. Continue Reading
Cookie Settings