Workspace Virtualization - Script to Find the Magic Number
There are often times where I want to modify either the read-only or writeable portion of a Workspace Virtualization layer. One of the things that makes this challenging is that the sublayer values are assigned when the layer is imported. I have found that I have to keep recreating a script to find the layers magic number. I have decided to finally write the blog post so I don't have to rewrite this script every time.
I hope this helps someone in the future.
Option Explicit
Dim layerName, strComputer, objWMIService, selectStatement, colItems, layerGuid
Dim thisLayer, registryPath, filePath, readOnlyMagicNumber, writeableMagicNumber
' Check to make sure there is a layer name on the command line.
If WScript.Arguments.Count = 0 Then
WScript.Echo "You must specify a layer name on the command line"
WScript.Quit
End If
' Get the Layer Name from the commandline
layerName = WScript.Arguments.Item(0)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\DEFAULT")
selectStatement = "SELECT Id FROM VirtualSoftwarePackage WHERE Name = "
selectStatement = selectStatement + Chr(34) + layerName + Chr(34)
Set colItems = objWMIService.ExecQuery(selectStatement,,48)
For Each thisLayer in colItems
layerGuid = thisLayer.Id
Next
Set thisLayer = Nothing
Set colItems = Nothing
selectStatement = "SELECT FileRedirectPath FROM VirtualSoftwareSublayer "
selectStatement = selectStatement + "WHERE Id = " + Chr(34) + layerGuid + Chr(34)
Set colItems = objWMIService.ExecQuery(selectStatement,,48)
For Each thisLayer in colItems
filePath = thisLayer.FileRedirectPath
Next
readOnlyMagicNumber = StrReverse(filePath)
readOnlyMagicNumber = Left(readOnlyMagicNumber, Instr(readOnlyMagicNumber, "\") - 1)
readOnlyMagicNumber = StrReverse(readOnlyMagicNumber)
Set thisLayer = Nothing
Set colItems = Nothing
Set objWMIService = Nothing
Dim objRegistry, swvRegistryLocation, subKeys, currentKey, layerRegistryLocation, peerValue
Dim writeableRedirect, layerFound
Const hklm = &H80000002
swvRegistryLocation = "System\CurrentControlSet\services\FSLX\Parameters\FSL"
Set objRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
objRegistry.EnumKey hklm, swvRegistryLocation, subKeys
layerFound = false
For Each currentKey in subKeys
layerRegistryLocation = swvRegistryLocation + "\" + currentKey
objRegistry.GetStringValue hklm, layerRegistryLocation, "PeerID", peerValue
If (peerValue = layerGuid) And (layerFound = false) Then
objRegistry.GetStringValue hklm, layerRegistryLocation, "FileRedirect", writeableRedirect
layerFound = true
End If
Next
writeableMagicNumber = StrReverse(writeableRedirect)
writeableMagicNumber = Left(writeableMagicNumber, Instr(writeableMagicNumber, "\") - 1)
writeableMagicNumber = StrReverse(writeableMagicNumber)
WScript.Echo "Read Only Magic Number: " + readOnlyMagicNumber
WScript.Echo "Writable Magic Number: " + writeableMagicNumber
The Endpoint Virtualization Community Blog is the perfect place to share short, timely insights including product tips, news and other information relevant to the Endpoint Virtualization community. Any authenticated Connect member can contribute to this blog.