Video Screencast Help

One-Click VBS Script to Activate SWV Layer(s) Through WMI

Created: 10 Nov 2012 • Updated: 10 Nov 2012 | 1 comment
This issue has been solved. See solution.

Hi everyone. I am looking to activate an individual layer (by name) through a simple VBS script utilizing the WMI on Windows 7 64bit.

Up until this point I have been activating layers through .BAT files and SVSCmd, but this method results in constant screen/icon refreshing which is not ideal for my purposes of constantly starting/stopping individual layers on demand. I've read that activating layers through WMI does not refresh the system in the same way and that would be ideal for my purposes. I've looked through the VBS/WMI articles here, but it is over my head. If someone could provide an example script or method of how this might be achieved, it would be very helpful.

Comments 1 CommentJump to latest comment

tritonxiv's picture

I didn't find the specific script I wanted, but going through some examples in this forum I managed to hack together some code that appears to work. I'm sure there's a much more elegant solution, but unless anyone knows of a cleaner solution, I'm satisfied with this. Save as .VBS and double click to activate the specified layer. All credits go to AngelID for the original code.

LayerName = "YourLayerHere"
Set WMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Restore,Backup)}!\\" _
& ".\root\default")
Set LayerItems = WMIService.ExecQuery("Select * From VirtualSoftwarePackage" & _
" Where Name=""" & LayerName & """")
For Each Layer In LayerItems
ActionResult = Layer.Activate
Exit For