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.

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.

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
Login VSI - Blog - Windows 10 1909 - Performance Results Windows 10 - 1909

Windows 10 – 1909 performance results and a look ahead at 2004

Is it just me or does Windows 10 2004 just not feel right as a name? Regardless of my opinion on that, Microsoft will release this 20H1 build in April of this year. But most organizations today are not going to implement this new version right away. Market research by VDI Like a Pro shows that most enterprises today are running Windows 10 1803, or 1809. Continue Reading
Login VSI Releases Login Enterprise 4.1

[Press Release] Login VSI Releases Login Enterprise 4.1

Login VSI Releases Login Enterprise 4.1 Comprehensive Testing Platform Ensures Business Continuity 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 - Login VSI Results for HPE SimpliVity 325

Login VSI results for HPE SimpliVity 325

Congratulations to HPE SimpliVity for another successful validated by Login VSI achievement! This latest hyperconverged (HCI) result is based on the HPE SimpliVity 325 platform leveraging 2nd Gen AMD EPYC processors. Continue Reading
Login VSI - Validating Your Remote Infrastructure at Scale - Man at Desk

Enabling Your Remote Workforce

Given recent global events, a majority of my users may need to work remotely. Many of our customers have been asking us if we can help them test the user-experience for their remote workforce, as well as the infrastructure that delivers it. We have seen requests range from the quality of the remote user-experience to the ability of their VPN to handle the throughput of a large volume of concurrent connections. Continue Reading