XenApp: VBScript to write to users registry

Some applications have requirement that they expects/read some values/data from current users hive in registry and this data usually get added to the users registry during application installation. Now in XenApp, since the application will be installed on the single XenApp server so the data will be added to current user hive in registry for the administrator who will install it. Now when such application will be published for users and when users will try to run this application, this application might break or might not behave properly as it will try to read some data from the current users hive which is not present for that particular user.

To implement this requirement in XenApp, we have to write VBScript to write data into the current user registry hive.

Let me describe problem statement:

Problem statement:

  1. User’s do not have rights to use “regedit” command. The only allowed way for user’s to write to their registry is by using RegWrite command.
  2. We need to write some value say “VALUE” to the key “Folder” at current user hive “HKEY_CURRENT_USER\Software\XYZ\ABC\11.1”
  3. We need to write “123456” to the key “aaa/bbb” at the current user hive “HKEY_CURRENT_USER\Software\XYZ\ABC”. Please note the forward slash in-between the key.
  4. Once above steps will be implemented, application should be launched.

Solution: Below VBScript is the solution. Let us discuss the solution of above four problems.

For first problem, where users are restricted rights, we have created function “WriteReg” which is taking key, value and type as input and executing RegWrite command to write the value into the registry.

For second problem, we are calling “WriteReg” function with the required parameters.

For third problem, we have to pass key with the format “\\\aaa/bbb”.

For forth problem, we have used notepad as an example.



' NAME: RegistryEdit.vbs


' AUTHOR: Mohd Aslam

' DATE  : 06/18/2010



' This script edits registry



Dim objFSO, WshShell


Set WshShell = WScript.CreateObject("WScript.Shell")

set objFSO = CreateObject("Scripting.FileSystemObject")


WriteReg "HKEY_CURRENT_USER\Software\XYZ\ABC\11.1\Folder", "VALUE", "REG_SZ"

WriteReg "HKEY_CURRENT_USER\Software\XYZ\ABC\\\aaa/bbb", "123456", "REG_SZ"


Sub WriteReg(strKey, strValue, strType)

WshShell.RegWrite strKey, strValue, strType   

End Sub


'Execute the Noteoad program

WshShell.Run "c:\WINDOWS\notepad.exe"


If Err.Number<>0 Then    

MsgBox "Unable to launch Notepad program!"

MsgBox "Error #" & Err.Number & " " & Err.Source & " " & Err.Description

End If


set WshShell = Nothing

Now in XenApp, we just need to publish this VBScript.

It can be published in XenApp as shown below:

Note: For more information on publishing in XenApp, refer to my article https://mdaslam.wordpress.com/2010/06/10/application-publish-in-xenapp/



One thought on “XenApp: VBScript to write to users registry

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s