Home > App-V > App-V: Don’t use WMI for querying virtual registries.

App-V: Don’t use WMI for querying virtual registries.


It is important to understand that the virtual registry is designed for virtualization of an application’s registry and it facilitates it through the interception of standard Win32 registry APIs. These APIs (i.e. RegOpenKeyEx, RegEnumKeyEx,  RegEnumValue,  RegCreateKeyEx, etc.)

I have, from time to time, dealt with alleviating confusion with how to access the virtual registry. I have often encountered a problem with applications and especially scripting where the application or script is unable to properly accessing the registry. Here is an example scenario which you can practice and demonstrate on your own sequencer and client.

On a machine with the App-V sequencer, pre-create the following registry key and value:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Test1\Key1
  • Value: Value1
  • Type: REG_SZ
  • Data: Data1

On an App-V 4.6 sequencer machine, create the following VREG exclusion:

  • \REGISTRY\Machine\Software\Test3\Key3\

Now, open up the App-V sequencer and create a new virtual application package. I do the experiment on both the 4.6 and 4.6 SP1 sequencer.

Accept the defaults, give it a test name. Start monitoring. During the monitoring phase, open a command prompt and do the following using the “reg” command.

Create the following key and value:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Test2\Key2
  • Value: Value2
  • Type: REG_SZ
  • Data: Data2

Using the following command:

reg add HKLM\Software\Test2\Key2

reg add HKLM\Software\Test2\Key2 /v Value2 /d Data2

Now Create the following key and value:

HKEY_LOCAL_MACHINE\SOFTWARE\Test3\Key3

  • Value: Value3
  • Type: REG_SZ
  • Data: Data3

Using the following command:

reg add HKLM\Software\Test3\Key3

reg add HKLM\Software\Test3\Key3 /v Value3 /d Data3

Don’t click Stop Monitoring button. Now run “regedit” from the same command prompt.

Verify the entries under HKEY_LOCAL_MACHINE\SOFTWARE\

You will see keys for test1 and test2, because of what was locally present (Test1) and remember the exclusion (Test3).

Now stop monitoring. Continue to configure the package by creating a command prompt shortcut for the package. Now launch the Command prompt when optimizing for streaming phase (launch phase) – then launch regedit.exe.

You will see only Test1 and Test2 keys again.  Exit regedit and exit the command prompt. Don’t close – select option to modify package.

Now confirm that under the “Virtual Registry” you will see keys test2 only.

Save the package and deploy and launch the application on a test App-V client. On that same machine with the App-V client, pre-create the following registry key and value:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Test1\Key1
  • Value: Value1
  • Type: REG_SZ
  • Data: Data1

Launch the application (which will launch the command prompt.) From a command prompt, launch regedit and you will see the virtual registry entries.

Open notepad, create and run a vbscript as below for using WMI to read registry keys that are created in above steps.

SCRIPT1.VBS

---------------BEGIN--------------------
dim RegKeyPath, RegValueName, RegValue
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set RegObj=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
RegKeyPath = "SOFTWARE\Test2\Key2"
RegValueName = "Value2"
RegValue = ""
RegObj.GetStringValue HKEY_LOCAL_MACHINE,RegKeyPath,RegValueName,RegValue
If IsNULL(RegValue) Then
 msgbox "Returns NULL"
Else
 msgbox RegValue
End If
---------END----------------

Now when you run this script in the virtual command prompt, it returns null. Now when you run this next script:

SCRIPT2.VBS

------------BEGIN-------------------
dim RegKeyPath, RegValueName, RegValue
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set RegObj=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
RegKeyPath = "SOFTWARE\Test1\Key1"
RegValueName = "Value1"
RegValue = ""
RegObj.GetStringValue HKEY_LOCAL_MACHINE,RegKeyPath,RegValueName,RegValue
If IsNULL(RegValue) Then
 msgbox "Returns NULL"
Else
 msgbox RegValue
End If
-----------END-----------------

Now when you run this script, it returns success. Why? If you look at the VBSCRIPT syntax, notice it uses the WMI provider to query the registry which is local and outside the virtual registry. Key Test1 is resident locally, and Key Test2 is virtual.

Steve Thomas

About these ads
Categories: App-V Tags: , , , , ,
  1. woter324
    September 14, 2011 at 8:37 am | #1

    Ok, So I think you’re saying, running WMI scripts, even when packaged with the App-V app won’t work. So how does one modify the registry from a script at run-time?

    Thanks

    • September 21, 2011 at 11:39 am | #2

      You can import using regedit -s during monitoring or use the reg.exe command.

  2. September 25, 2012 at 4:47 pm | #3

    You are really a excellent webmaster. The site loading pace is incredible. It kind of feels that you’re doing any unique trick. In addition, The contents are masterpiece. you’ve performed a great task in this matter!

  3. September 26, 2012 at 1:06 am | #4

    Remarkable issues here. I’m very satisfied to look your article. Thanks so much and I’m having a look ahead to contact you. Will you please drop me a mail?

  4. wordpresysGync
    January 13, 2014 at 6:46 pm | #5

    http://i60.fastpic.ru/big/2014/0109/bf/4dee091ea346ba9d299cc691d81f35bf.jpg
    Название: Быстро и вкусно! № 17 2013. Готовим национальные блюдаИздательство: OOО "ИГЛМОСС РУС"Страниц: 100Формат: PDFРазмер: 37,74 МбЯзык: РусскийГод издания: 2013Качество: ОтличноеОписание: «Быстро и вкусно!» – это коллекционная серия книг с простыми рецептами быстрых, вкусных и недорогих блюд. Они отобраны опытной командой поваров, гарантирующих великолепный результат. Каждый рецепт сопровождается красочной фотографией и лаконичной пошаговой инструкцией. Собрав все книги, вы получите исчерпывающую кулинарную коллекцию, которая поможет вам сделать ещё вкуснее всё, что вы любите, и освоить новые оригинальные блюда.

    Скачать с Летит бит (одним файлом рекомендуем)
    Скачать с vip-file.com
    Скачать с dfiles.ru

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: