Using SVS WMI and HTML to Create a Custom SVS User Tool

Using SVS WMI and HTML to Create a Custom SVS User Tool
Jordan's picture

I recently got an e-mail about a company that wanted to push out 40+ layers to most of their computers and were seeing a huge performance hit because of this, I'm assuming they were activating all those layers from what the descriptions of their experience was and it got me thinking about the best way to deal with this situation. Well obviously you'd reply "have the users activate them when they need them and deactivate when they're done", the problem here is with the nature of SVS Admin-it's an admin tool and while you can do some permission stuff to limit its features it's not designed to customized in that way.

You probably don't have time to create your own SVS user tool via the SDK, that would take a lot of effort unless you were really familiar with GUI tools and testing as well. But there's another option, it's quick, easy and allows for themes so you could easily design it with your company logos and colors and that's making an HTA application.

HTA applications are basically HTML files running as applications, unlike normal HTML they cannot connect to the web, have higher permissions but still use HTML/CSS and scripting for designing a user experience. So how does this relate to SVS? Well it's not common but you can use VBscript in an HTML file just like you use Javascript which means you can use SVS's WMI classes and methods to design a tool. Since its HTML you can make it look however you want, it uses WMI which means you don't have to test to make sure you're doing the SVS calls correctly and you have the ability to limit what your users can do because you're only including the features you want. Best of all, since we're using VBScript, we can just copy functions out of my WMI article for use.

Creating a Tool

I'm not going to cover HTML or CSS here, if you're not familiar with it there are plenty of sites that will show you how to do this.

In this tutorial I'm going to cover how to get all the layers and let you activate and deactivate them, with that info I think it's pretty easy to add anything else you want. Attached to this article is a Zip that contains the files used.

Design

Since it's an HTML page we can't easily change the right mouse click menu to do what we want (it's doable but we're not going to cover that here) and with an HTA file you get the default IE menu. That's OK because we're making this for your average co-worker and we want to simplify things as much as possible, so what we're going to do is show next to each layer name an activate and deactivate link. Another issue is whether a layer is active or inactive, in SVSadmin the layer name is bolded but that's not clear enough so we're going to change the background behind the layer name to yellow for active and gray for inactive. That should be clear for everyone.

For the background and the rest of the colors I'm going to use my Juice ReMix theme since I've already got most of that content easily at hand.

I'm not really going much into design for this example outside to show what can be done and give some examples, because this isn't really that pretty looking-but it gets the points I want across quite well.

CSS

Make a CSS file or just embed this in the HTML file itself:

body{
font-family:Times New Roman, Times, serif;
font-size:14px;
color:white;
width: 300px;
height:100%;
background-image: url("background.gif"); 
}

We're setting the width to a default because we want it to never be longer that 300px wide, the actual application will be 400 px wide, but we want the height to fit to content so we're using the value 100%.

Next we're going to add the styles for activate and deactivate:

.active{
background-color:yellow;
color:black;
}
.inactive{
background-color:gray;
}

ul{
width:350px;
list-style-type: none;
}

Active and inactive classes define the color of the font and the background color that an inactive and active layers have. The ul style removes the bullets from the list so we have something that looks a little cleaner.

HTML

Create a new HTML page and copy and paste this code:

<html>
<head><title>Custom SVS tool</title></head>
<body onload="load">
<div id="myLayers"></div>
</body>
<html>

This is really simple, no fancy HTML. On the body Tag we're adding an onLoadEvent, this will call the load function we'll define next, and we have a div named myLayers which is empty, this is where we'll place our list of layers once we load them.

VBScript

In the <head> element after the closing </title> tag but before the closing </head> tag add <script language="vbscript"></script> in between these two tags is where we're going to add all our VBscript functions.

Sub Load
  dim myLayers
myLayers="<ul>"
 strComputer = "." 
SET objWMIService = GetObject( _ 
"winmgmts:{impersonationLevel=impersonate}!\\" & _ 
strComputer & "\root\default" ) 
SET colItems = objWMIService.ExecQuery( _ 
"Select * from VirtualSoftwarePackage" )
FOR EACH objItem IN colItems 
IF objItem.Active = true THEN
myLayers=mylayers & "<li name='"&objItem.Name&"' id='"&objItem.Id&"' ><span class='active'>" & objItem.Name & " <a href='#' onclick='deactivateSVS(""" & objItem.Id & """)'>Deactivate</a></span></li>"
ELSE
myLayers=mylayers & "<li name='"&objItem.Name&"' id='"&objItem.Id&"' ><span class='inactive'>" & objItem.Name & "<a href='#' onclick='activateSVS(""" & objItem.Id & """)'>Activate</a></span></li>"
end if
NEXT
myLayers=mylayers & "</ul>"
layerTest.innerhtml=mylayers
End Sub

When the window launches we need to query all the layers and populate the list, this is done in our load subroutine. It can be kind of intimidating if you're not that familiar with everything I'm doing, especially because I'm using some DHTML only objects in here, one of which is the layerTest.innerHTML.

LayerTest is the Div element we placed in our HTML, since it's a static name I can call it here without using the document prefix. innerHTML is the property that contains all the HTML code that will go inside the div element. myLayers is the HTML list of all the SVS layers in the system right now, I'm just looping through all of them and adding the proper information into myLayers.

Lastly in my anchor tag I'm creating an event action of onClick which calls either activeSVS or deactivateSVS and that passes in an ID (which in this case is a guid) that will tell the function which SVS layer to affect, also I've added that same ID to each <li> element in that defines my list, this is so I can also change the content inside my list which is how you get the color and text changing affect you see when you click on a link in my example.

Activate and Deactivate

FUNCTION activateSVS(myGuid)
  strComputer = "."
SET objWMIService = GetObject( _ 
"winmgmts:{impersonationLevel=impersonate}!\\" & _ 
strComputer & "\root\default" ) 
Set objItem = objWMIService.Get( "VirtualSoftwarePackage.Id=""" & myGuid &"""")
objItem.Activate()
set myobject = document.getElementByID("" & myGuid & "")
myName=myobject.name
myobject.innerhtml= "<span class='active'>" & myName & " <a href='#' onclick='deactivateSVS(""" & myGuid & """)'>Deactivate</a></span>"
END FUNCTION

FUNCTION deactivateSVS(myGuid)
  strComputer = "." 
SET objWMIService = GetObject( _ 
"winmgmts:{impersonationLevel=impersonate}!\\" & _ 
strComputer & "\root\default" ) 
Set objItem = objWMIService.Get( "VirtualSoftwarePackage.Id=""" & myGuid &"""")
objItem.Deactivate()
set myobject = document.getElementByID("" & myGuid & "")
myName=myobject.name
myobject.innerhtml="<span class='inactive'>" & myName & "<a href='#' onclick='activateSVS(""" & myGuid & """)'>Activate</a></span>"
END FUNCTION

Both of these functions are very similar the only real difference is the innerHTML and the method being called. If you've read my SVS and WMI article this code should look pretty familiar, it's just my activate function example from that article with some extra code added.

We're binding an WMI SVS object then calling activate or deactivate based off the function--that's pretty straight forward--what's not is what I do next which is create an object myObject that contains a information about the list element that we just clicked on, document.getElementByID is the method you call to reference and HTML object in DHTML by it's id (Which we set to the layer guid) and once I have this object I can get the name of the list element (which was set to the layer name) and then switch out the content inside the list-which in this case is the span element and the anchor element.

Finishing Touches

First off we want to make our window a certain size so inside our Script tags we're going to add one last function.

Sub Window_onLoad
  window.resizeTo 400,250
End Sub

Window_onLoad is an event function that VBscript already knows what to do with, you don't need to place an event caller in the HTML for this function to get called. What is does is set our program to a width of 400 and height of 250.

Lastly we need to define this as an HTA document, renaming the .html extension to .hta does some of the work for you, in our head tag place the following code:

<HTA:APPLICATION ID="SVSDemo"
   APPLICATIONNAME="SVStest"
   BORDER="thin"
   BORDERSTYLE="normal"
   CAPTION="yes"
   MAXIMIZEBUTTON="yes"
   MINIMIZEBUTTON="yes"
   SYSMENU="yes"
   VERSION="1.0"/>

This defines how the HTA application behaves and there are a lot more options then what I've listed here, so instead of going over all these I'm going to provide a link to the MSDN which does a better job explaining this then I ever could. But I think it's sufficient to say that most of that is pretty obvious as to what it does.

Conclusion

There you have it, a simple user tool for activating and deactivating SVS. Now in my example we're querying all the layers on a system but you could just as easily hard code GUIDS into the program and only allow people the ability to activate or deactivate certain layers.

And while the VBS and WMI doesn't allow you do everything that you can do with the SDK you still have a lot to work with (especially if you VBS to launch a hidden command line to run other tools found here on the juice) and the ability to use HTML for your interface gives an easy to use-and well known-tool for making your tools accessible to your average user

4.030305
Average: 4 (33 votes)
License: Altiris EULA
By downloading this software, you agree to the terms and conditions in the Altiris End User License Agreement
Support: User-contributed tools on the Juice are not supported by Altiris Technical Support. If you have questions about a tool, please communicate directly with the author by visiting their profile page and clicking the 'contact' tab.
AttachmentSize
SVSHTA.zip53.01 KB
Syndicate content