Video Screencast Help
Protect Your POS Environment Against Retail Data Breaches. Learn More.
Endpoint Virtualization Community Blog

Workspace Virtualization - Script to Find the Magic Number

Created: 23 Feb 2011 • 1 comment
Scot Curry's picture
0 0 Votes
Login to vote

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

Comments 1 CommentJump to latest comment

ardevaz's picture

I've got this "simpler" version working

 

' 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

'get the readonly number
selectStatement = "SELECT FileRedirectPath FROM VirtualSoftwareSublayer "
selectStatement = selectStatement + "WHERE PackageId = " + Chr(34) + layerGuid + Chr(34) + " AND Type = 0"
 
Set colItems = objWMIService.ExecQuery(selectStatement,,48)
 For Each thisLayer in colItems
  filePath = thisLayer.FileRedirectPath
 Next

readOnlyMagicNumber = right(filePath, len(filePath) - Instrrev(filePath, "\") )
Set thisLayer = Nothing
Set colItems = Nothing
 
'get the writable number
selectStatement = "SELECT FileRedirectPath FROM VirtualSoftwareSublayer "
selectStatement = selectStatement + "WHERE PackageId = " + Chr(34) + layerGuid + Chr(34) + " AND Type = 1"
 
Set colItems = objWMIService.ExecQuery(selectStatement,,48)
 For Each thisLayer in colItems
  filePath = thisLayer.FileRedirectPath
 Next

writeableMagicNumber = right(filePath, len(filePath) - Instrrev(filePath, "\") )
Set thisLayer = Nothing
Set colItems = Nothing

Set objWMIService = Nothing
 
WScript.Echo "Read Only Magic Number: " + readOnlyMagicNumber
WScript.Echo "Writable Magic Number: " + writeableMagicNumber

-3
Login to vote