Using WiseScript to Manage the Delivery Time Logic of SVS Applications, Part 2

Using WiseScript to Manage the Delivery Time Logic of SVS Applications, Part 2

In this scenario, we are a corporate repackager with the full power of Wise Package Studio 7.0 SP2 at our disposal. Our assigned task is to deploy a Microsoft Office 2003 SVS package to all of the machines in the company. The problem is that each department within the company has a specific Office Profile Configuration setting that they are required to use. We don't want to create a separate MS Office VSA package for each department with the customized settings baked into it and we don't want to configure the MS Office layer after it has been installed because resetting the layer will wipe out all of our settings. So, what can we do...?

Tutorial goals:

In this tutorial we are going to use WiseScript to create an installation wrapper for our Microsoft Office 2003 SVS application that will query Active Directory to determine what Organization Unit the current computer is a member of, then based off the organizational unit, install the appropriate departmentalized Office Profile Configuration File (.OPS) into the Office SVS Layer, activate the Office layer, and restore the departmentalized Office Profile Settings. Then lastly, to cover ourselves in the event of the user resetting the layer, we will create a "Post Reset" Event to re-restore the department Office Profile.

I know that is a lot to take in and may be a little confusing, but it is not as hard as it sounds. So let's get started.

Assumptions:

For this example we are going to assume the following:

  • All of the company's computers are broken up within Active Directory into departmentalized Organizational Units. (Finance, Marketing, Support, etc...)
  • Each Department has a unique configuration setting for all of their Microsoft Office applications
  • As a result of the different Office configuration settings between departments, each department has created a Standard Office Profile that they require all members of their departments to use.
    Note: an Office Profile Setting file (.OPS) can be created using the "Microsoft Office Save My Settings Wizard" tool that is a part of Microsoft Office

Prerequisites:

This tutorial assumes that you have a basic knowledge of WiseScript, VBScript, and the Wise Virtual Package Editor.

Preparation:

In preparation for this project, I have done the following:

  • Captured "Microsoft Office 2003" into a Wise Virtual Package (.wvp) project using the Wise Virtual Package Editor.
  • Created four Office Profiles using the "Microsoft Office 2003 Save My Settings Wizard" (Finance.ops, Marketing.ops, Support.ops, and Standard.ops)
  • Created a VBScript that queries Active Directory to determine what organizational unit the current computer is a member of. (This VBScript will interact with the WiseScript deployment wrapper.)

Disclaimer:

Just to clarify things, I am not a master of VBScript, however, I do know enough to get the results I'm looking for. With that said, I am sure there is a much more stream-lined approach to getting the Active Directory information using VBScript other than what I have included in this tutorial. Feel free to improve upon your attempt at this tutorial as you see fit, this tutorial is merely an attempt to give you a practical example of what you can achieve with using WiseScript to handle the delivery time logic of your SVS Applications.

Tutorial:

First off, let's create our WiseScript installation wrapper to install and configure our SVS Application. Go ahead and launch the WiseScript Package Editor and create a new "Blank Script".

Next, let's declare a few variables that we will use throughout our WiseScript. Add the following "Set Variable" actions to your script: RET, PROFILE, DEPARMENT, COMMONFILES, and PROFILEFOLDER.

Your script should look like this when you are done with this step:

Next, we are going to set a few of these variables with default values. Add a "Get Environment Variable" action:

  • Set the value of Env. Variable to "CommonProgramFiles"
  • Set the Variable Name to our COMMONFILES variable we created.

Next add a "Set Variable" action to the script.

  • Set the Variable to PROFILEFOLDER
  • Set the Value to "%COMMONFILES%\Microsoft Shared\OfficeProfile"
    This is the location of where our Office Profile file (.OPS) will be installed into our SVS Layer.
Note: If you are using SVS version 2.0 then you can skip this step. If you are using the latest release version of SVS version 2.1, then you will need to add an additional bit of code to initialize SVS prior to performing the WiseScript SVS script actions that we will be using later on in our script. To simplify this, I have done this step for you. Copy and paste the following text into your WiseScript, this text will create the appropriate script actions to perform the SVS Initialization task:
item: Remark
Text=- - - - - Initialize SVS - - - - - - - - -
end
item: Set Variable
Variable=_PRODUCTKEY_
end
item: Set Variable
Variable=_DAYSREMAINING_
end
item: Set Variable
Variable=_RET_
end
item: Check if File/Dir Exists
Pathname=%SYS32%\fsllib32.dll
Message=Unable to load Software Virtualization Agent library.  This script requires the Software Virtualization Agent in order to execute.
Title=Error
Flags=00000011
end
item: Call DLL Function
Pathname=%SYS32%\fsllib32.dll
Function Name=FSL2GetProductKey
Argument List=3171
Argument List=y0@ÿ_PRODUCTKEY_
Argument List=31255
Return Variable=3_RET_
Flags=01100000
end
item: If/While Statement
Variable=_RET_
Value=0
end
item: Call DLL Function
Pathname=%SYS32%\fsllib32.dll
Function Name=FSL2InitSystem
Argument List=40_PRODUCTKEY_
Argument List=3171
Argument List=80_DAYSREMAINING_
Return Variable=3_RET_
Flags=01100000
end
item: End Block
end
item: Remark
Text=- - - - - End Initialize SVS - - - - -
end

Once added to your script it should look something like this:

Now we need to add an "Execute VBScript" action to our WiseScript, browse and select your VBScript.

Below is the VBScript that I created for this project. This script will be run to query Active Directory and return the name of the organizational unit that this computer is a member of. It will also store this value into the WiseScript DEPARTMENT variable that we created earlier so we can use it later on in our script. (Note: this script was designed to be run from within WiseScript and will not work by itself. There are actions included in this VBScript to set a WiseScript variable with the return results and these actions will not work outside of WiseScript.)

VBScript:

OPTION EXPLICIT
DIM objNetwork
DIM computerName
DIM ou

' Get the computerName of PC
set objNetwork = createobject("Wscript.Network")
computerName = objNetwork.ComputerName

' Call function to find OU from computer name
ou = getOUByComputerName(computerName)

' Pass the return results (organizational Unit Name) to the WiseScript variable %DEPARTMENT%
SetVariable "DEPARTMENT", ou


function getOUByComputerName(byval computerName)
' *** Function to find ou/container of computer object from computer name ***

DIM namingContext, ldapFilter, ou
DIM cn, cmd, rs
DIM objRootDSE

' Bind to the RootDSE to get the default naming context for
' the domain.  e.g. dc=wisesoft,dc=co,dc=uk
set objRootDSE = getobject("LDAP://RootDSE")
namingContext = objRootDSE.Get("defaultNamingContext")
set objRootDSE = nothing

' Construct an ldap filter to search for a computer object
' anywhere in the domain with a name of the value specified.
ldapFilter = "<LDAP://" & namingContext & _
">;(&(objectCategory=Computer)(name=" & computerName & "))" & _
";distinguishedName;subtree"

' Standard ADO code to query database
set cn = createobject("ADODB.Connection")
set cmd = createobject("ADODB.Command")

cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn
cmd.commandtext = ldapFilter

set rs = cmd.execute

if rs.eof <> true and rs.bof <> true then
     ou = rs(0)
     ' Convert distinguished name into just the OU.
     ' e.g. cn=CLIENT01,OU=Computer_Group,dc=wisesoft,dc=co,dc=uk
     ' to: OU=Computer_Group,dc=wisesoft,dc=co,dc=uk
     ou = mid(ou,instr(ou,",")+1,len(ou)-instr(ou,","))
  ' Convert again to just: OU=Computer_Group
  ou = Left(ou, instr(ou,",")-1)
  ' Convert again to just: Computer_Group
  ou = Right(ou, len(ou)-3)
     getOUByComputerName = ou

end if

rs.close
cn.close

End Function

Once the "Execute VBScript" action has been added to your WiseScript, a tab will appear at the bottom of the WiseScript Editor. You can now select this tab to view and edit your VBScript from within the WiseScript Editor.

Ok, now that our WiseScript has the Organizational Unit that the computer is a member of stored in the DEPARTMENT variable, we can install our SVS application.

Add an "Install File" action.

  • Browse and select your "Office2003.vsa" file
  • Set the Destination Pathname to %TEMP%\Office2003.vsa.
    (We need to install the .VSA to the destination machine before we can import it into SVS.)

Now this is just a personal preference, but I usually like to add a "Pause" action between actions that deal with file operations, just as a buffer to make sure the file has time to get created or to make sure the previous operation doesn't still have that file locked. It is up to you, but I am placing a "Pause" action here for about 3000 milliseconds.

Next add an "Import SVS Layer" action

  • Set the Archive path to where we installed the Office2003.vsa file: "%TEMP%\Office2003.vsa"
  • Set the GUID Variable to "GUID"
  • Set the Return Variable to "RET".

The WiseScript will wait until the SVS layer has been imported before moving on in the script but I am still going to place another small buffer here by adding a "Pause" action for another 3000 milliseconds.

Note: If you want to know when the import SVS layer has completed, I recommend placing a "Display Progress Message" action before the "Import SVS layer" action and another "Display Progress Message" action to remove the previous message after the "Import SVS Layer" action.

Now that our layer has been imported into SVS, we can prep it for the customized Office profile. First we will create the directory within the "Read-Only" section of the layer for where our Office Profile will be installed.

Add a "Create Directory in SVS Layer" action.

  • Set the Layer GUID to the value we have stored in the %GUID% variable we created during the import SVS layer action.
  • Set the "Path to create" field to "[MSSHAREDTOOLS]\OfficeProfile"
  • Set the Return Variable to RET

Next we are going to add the logic to install the appropriate Office Profile (.Ops) into the layer depending on the value of the DEPARTMENT variable (organizational unit). To do this we are going to use a multiple "If" / "ElseIf" statement.

Add an "If" statement to the WiseScript

  • Set the variable to be checked to DEPARTMENT
  • Set the comparison operator to "Equals"
  • Set the value to "Finance".

Now we are going to create a variable to store the file name of our Office Profile (.OPS) file. This will be used later on in the command line to restore the office profile.

Add a "Set Variable" action

  • Name the variable "PROFILE"
  • Set the New Value to "FinanceDept.OPS"

Next we are going to create a Temporary file name for our office profile to get installed under. Add a "Get Temporary file name" action to the script

  • Set the Variable to "FINANCE".

Now we are going to install our FinanceDept.OPS file to the TEMP directory under a TEMP name in preparation to permanently install it into the Office2003 SVS layer.

Add an "Install File" action to the script.

  • Browse and select the "FinanceDept.OPS" Office profile file
  • Set the Destination Directory to %TEMP%\%FINANCE%

(Optional) I am going to place another "Pause" action here for about 3000 milliseconds to give a little pause before I install this file from the TEMP directory into the SVS Layer.

Now we are going to install this Office Profile (.OPS) file into the "Read-Only" section of our Office2003 SVS Layer. This will make the Office Profile (.OPS) become apart of our SVS application permanently to ensure that it will still exist even if the SVS layer is reset.

Add an "Add file to SVS Layer" action.

  1. Set the Layer GUID to %GUID%
  2. Set the source path to your temp file we just installed "%TEMP%\%FINANCE%"
  3. Set the Layer path to the new folder we created "[MSSHAREDTOOLS]\OfficeProfile\FinanceDept.OPS"
  4. And Set the return variable to "RET"

The "If" Statement should look some thing like this so far:

Next we are going to add some "ElseIf" statements for the other two departments (Marketing and Support). Add an "ElseIf" Statement.

  • Set the variable to be checked to DEPARTMENT
  • Set the comparison operator to "Equals"
  • Set the value to "Marketing".

Now to save time, we can just copy the same actions that we just created under the first "If" Statement and paste them under this "ElseIf" statement. Then all we have to do is change all the references from "FINANCE" to "MARKETING".

  • Change the PROFILE variable to "MarketingDept.OPS"
  • Change the Temp File name variable to MARKETING
  • On the install File action, Change the source file to "MarketingDept.OPS" and change the destination path to %TEMP%\%MARKETING%
  • On the "Add file to SVS Layer" action, change the source path to "%TEMP%\%MARKETING%" and change the Layer path to the marketing file: "[MSSHAREDTOOLS]\OfficeProfile\MarketingDept.OPS"

Your new "ElseIF" Statement should look like this when you are done.

Now let's do the same thing for the Support Department. Add another "ElseIf" Statement.

  • Set the variable to be checked to DEPARTMENT
  • Set the comparison operator to "Equals"
  • Set the value to "Support".

Copy and paste the actions from the previous "ElseIf" Statement. Then all we have to do is change all the references from "MARKETING" to "SUPPORT".

  • Change the PROFILE variable to "SupportDept.OPS"
  • Change the Temp File name variable to SUPPORT
  • On the install File action, Change the source file to "SupportDept.OPS" and change the destination path to %TEMP%\%SUPPORT%
  • On the "Add file to SVS Layer" action, change the source path to "%TEMP%\% SUPPORT%" and change the Layer path to the Support file: "[MSSHAREDTOOLS]\OfficeProfile\SupportDept.OPS"

And in the case where we are unable to determine what department (Organizational Unit) the computer is a member of, we will add an "Else" Statement as a catch all. In this circumstance we will install and restore a "Standard" company Office Profile.

Add an "Else" Statement to the script.

  1. Copy and paste the actions from the previous "ElseIf" Statement. And change all the references from "SUPPORT" to "STANDARD".
  2. Change the PROFILE variable to "Standard.OPS"
  3. Change the Temp File name variable to STANDARD
  4. On the install File action, Change the source file to "Standard.OPS" and change the destination path to %TEMP%\% STANDARD%
  5. On the "Add file to SVS Layer" action, change the source path to "%TEMP%\% STANDARD%" and change the Layer path to the Standard file: "[MSSHAREDTOOLS]\OfficeProfile\Standard.OPS"

And lastly, Add an "End" Statement to complete the "If" Block.

Your completed "IF / ESLEIF" statement should look something like this:

Now that we have installed our profile into the SVS Layer, we need to activate our SVS Application in order to restore our Office Profile settings.

Add an "Activate SVS Layer" action to our WiseScript.

  • Set the Layer GUID to "%GUID%"
  • Set the return value to "RET"

(Optional) I added a "Pause" action here for about 5000 milliseconds

Next let's add the Command line to restore our Office Configuration settings. This will execute the Office Profile Wizard from within our SVS Application Layer and restore the settings of our .OPS file.

Add an "Execute Program" action to the script.

  • Set the .EXE path to: "C:\Program Files\Microsoft Office\OFFICE11\PROFLWIZ.EXE"
  • Set the Command Line to: /a /r "%PROFILEFOLDER%\%PROFILE%"
    Note: you can set the Office Profile Wizard to restore the profile silently by adding a "/q" at the end of the command line. For this example, we will leave it normal so we can verify that it is actually restoring our settings.
  • Check the "Wait for Program to Exit" checkbox

And lastly, we are going to add a final action to our WiseScript wrapper to clean up the "Office2003.vsa" file we installed to the TEMP directory. Add a "Delete File" action to the WiseScript and set the Pathname to: "%TEMP%\Office2003.vsa"

Your completed Office2003 WiseScript wrapper script should look something like this:

Now, save and compile the WiseScript wrapper and let's test it out to make sure it works properly. Run the newly generated "Office2003.exe" on a machine that has SVS installed.

Eventually after it has installed and imported your Office2003.vsa into SVS, you should see your office configuration settings get restored and a message indicating that it was successful.

Note: Adding the "/q" at the end of the command line will suppress these dialogs to the end user.

Recap to this point:

To recap on what we have accomplished with our WiseScript wrapper up to this point:

  • We have created a WiseScript wrapper to install and import our "Office2003.vsa" into SVS.
  • Our WiseScript executes and interacts with a VBScript we created to determine the Active Directory Organizational Unit that the target machine is a member of.
  • Based on the Organizational Unit (department) we install the appropriate Office Profile (.OPS) into the "Read-Only" section of our SVS Application so it resides permanently within the layer. And as a catch all, if we are unable to determine the Organizational Unit, we install and restore the company "Standard" profile settings.
  • We then activate the Office2003 SVS application and restore the configuration settings from within the layer.

The last thing we need to do in order to complete this application deployment package is to create a "Post Reset" event to restore the Office Profile setting in the event the layer is reset. This will ensure that the configurations to our SVS application will last as long as it is installed on the machine.

Now, you are probably thinking, "We installed the Office Profile permanently into the layer, why do we need the Post Reset event?" This is true, we did install the Office Profile Archive (.OPS) permanently into the layer, however, we applied the Office Profile settings using the application within that layer. This means that we applied the settings after the layer already existed in its default state. If we reset the layer, it would revert back to the default state before the settings had been applied. That is the reason we need to create a "Post Reset" event to ensure the Office Profile settings are re-applied in the event of a layer reset.

Let's get started on the last piece of our project.

  • To do this portion we are going to open up our "Office2003.wvp" project using the Wise Virtual Package Editor.
  • Once open we are going to select the "Events" Page and select "Post Reset" from the dropdown.
  • Then click "Add" and select the WiseScript option.
  • Name the Description: "Restore Office Profile"
  • Uncheck the "Wait for this script to complete" checkbox

To save time, copy and paste the beginning of our wrapper script into this Event script to set up all the variables we will use:

You can delete the DEPARTMENT Variable because it is not needed for this script, but everything else we will reuse.

Now because we are restoring the profile configuration setting from within the layer, we need the layer to be active. SVS allows users to reset a layer while it is both active and inactive, so we will need to make sure the layer is active before attempting to restore the Office profile configuration settings. In order to do this we need to get the Layer GUID for our Office2003 layer.

Add a "Find SVS Layer GUID" action to the script. This will store the Office2003 layer GUID into the GUID variable.

  • Set the Layer Name to: Office2003
  • Set the GUID Variable to: "GUID"
  • Set return variable to: "RET"

(Optional) I placed a short 1000 millisecond "Pause" action at this point in the script before attempting to activate the layer.

Next, add an "Activate SVS Layer" action:

  • Set the Layer GUID to the value of "%GUID%"
  • Set the return variable to "RET"

Then add a "Pause" action for about 7000 milliseconds to give adequate time for the SVS layer to activate before attempting to restore the Office Profile settings.

Once the Office2003 layer is activated, we need to locate and retrieve the name of the Office Profile archive (.OPS) that was installed into the layer. To do this, we are going to add a search action to search our PROFILEFOLDER directory we set in the beginning of the script.

Add a "Search for File" action to your WiseScript.

  • Set the filename to: "%PROFILEFOLDER%\*.OPS"
    Note: we are performing the search using a wildcard "*" because this script does not know what department .OPS file was installed.
  • Set the Variable Name to "PROFILE"
  • Set Return Type to "Return first file that matches"
  • Set Drives to Search field to "Directory given by File Name field"

Next after locating the Office Profile Archive (.OPS) we are going to put in some simple logic using an "If" statement to determine what action to perform based on if the Profile was found. We could make this a very thorough script and add much more validation and actions to it, however, we are not going to get that detailed with this tutorial. This tutorial is just designed to give you an idea of what you can do with WiseScript and SVS.

Add an "If" Statement to your script:

  • Set the variable to PROFILE
  • Set the condition to "Not Equal"
  • And leave the value blank

If the value of PROFILE is not blank, then it has found our Office Profile .OPS file. The Search action we used returns back the full path of the file if one is found. So now all we need to do is add our command line to restore the Profile setting using the value that we have stored in the PROFILE variable.

Add an "Execute Program" action to the script:

  • Set the .EXE path to: "C:\Program Files\Microsoft Office\OFFICE11\PROFLWIZ.EXE"
  • Set the Command Line to: /a /r "%PROFILE%"
    Note: same as before, adding a "/q" at the end of the command line will restore the profile settings silently.
  • Check the "Wait for Program to Exit" checkbox

Add an "Else" statement.

Add an "Exit Installation" action.

Like I said earlier, we could put in the added logic to find the Organizational Unit again and to install the correct .OPS file if it was not found, but for this tutorial we will just abort the Office Profile configuration if we are unable to locate it after the Layer is reset, even though this situation is unlikely to occur.

And lastly add an "End" Statement to finish out our "If" block.

Your completed script should look something along these lines:

Test your SVS Application:

Now let's get it ready to test:

  • Click OK on the WiseScript Editor to complete your WiseScript.
  • Compile your Office2003.wvp project.
  • Open your Office2003 WiseScript wrapper project and compile.

Next, test the newly created "Office2003.exe" on a clean machine that has SVS installed. The layer will be activated and the office profile will be restored by the wrapper script that we already created and tested earlier. Now let's test the Event script.

With the Office2003 Layer active, reset the layer. You should see your Office Profile Wizard come up and restore your office profile.

Next, deactivate the Office2003 layer and reset the layer. You should see the layer automatically activate and restore the office profile.

And that's it, we have successfully created a practical way to permanently configure our SVS application on a per-machine level using WiseScript to manage the delivery time logic.

Conclusion:

In conclusion, WiseScript is a very simple and versatile tool that allows you to combine various elements and scripting languages together to create a universal package that is customized to your company's needs. I hope this tutorial has been helpful to you or at least sparked some ideas of what you can accomplish using WiseScript to manage the delivery time logic of your SVS applications.

Thank you,
Aaron Phillips

License: AJSL
By clicking the download link below, you agree to the terms and conditions in the Altiris Juice Software License
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
ProjectFiles.zip5.29 KB
4.02857
Average: 4 (35 votes)