Example VBScripts for most common Tasks on the Altiris Agent

book

Article ID: 181135

calendar_today

Updated On:

Products

Management Platform (Formerly known as Notification Server)

Issue/Introduction

 

Resolution

Question
Do you have some VBScript examples for some of the most common Altiris Agent Tasks? For example:
  1. Update Basic Inventory
  2. Update Altiris Agent Configuration
  3. Delete Temporary Files
  4. End a Process
  5. Hardware Inventory

Answer
Note: The following VBScripts are provided as examples. You should test them before running them on your production environment.

The following VBScripts are part of the example scripts provided by the Task Server (Task Management Solution). The commands provide a simple example of to accomplish some of the basic Altiris Agent tasks.

Example of How to Force to Send Basic Inventory:

' Cause the 6.0 agent to send basic inv
' We now have the ability to ignore blockouts and to send the basic inv only if something has changed
' The <ignoreBlockouts> variable works the same way as for config requests
' The <sendIfUnchanged> variable controls whether basic inv is sent even when it has not changed
' If <sendIfUnchanged> is 1 basic inv will be sent whether it has changed or not
' If it is 0 basic inv will be sent only if it has changed since the last time it was sent
dim client
set client = wscript.createobject ( "Altiris.AeXNSClient" )
ignoreBlockouts = 1
sendIfUnchanged = 1
client.SendBasicInventory sendIfUnchanged, ignoreBlockouts

Example of How to Force to Update Altiris Agent Configuration

' Cause the client / agent to request config, works for 5.5 and 6.0
dim client
set client = wscript.createobject ( "Altiris.AeXNSClient" )
dim policymgr
set policymgr = client.ClientPolicyMgr
policymgr.Refresh

Example of How to Delete Temporary Files 

Option explicit
on error resume next
Dim fso, sProfileRoot, oProfilesDir, oProfileDir, FolderName, oTempFolder, oTempFolderSubFolders, oFolder, oFile, oTempFiles, sDebug

'This script will delete all files in all temp directories for all profiles.

sDebug = "false"
set fso = CreateObject("Scripting.FileSystemObject")
sProfileRoot = "C:\Documents and Settings"

'iterate thru Profile Directories
set oProfilesDir = fso.GetFolder(sProfileRoot)

For Each oProfileDir In oProfilesDir.SubFolders
 if sDebug = "true" Then
  WScript.StdOut.Writeline "Checking Profile " & oProfileDir.Path
 End IF
 call deleteFolders(oProfileDir.Path & "\Local Settings\Temp")
 call deleteFolders(oProfileDir.Path & "\Local Settings\Temporary Internet Files")
Next
set fso = nothing
wscript.quit

Sub deleteFolders(FolderName)
 Set oTempFolder = fso.GetFolder(FolderName)
 if sDebug = "true" Then
  WScript.StdOut.Writeline "Checking " &  FolderName
 End if
 'delete folders in temp Folder
 Set oTempFolderSubFolders = oTempFolder.SubFolders
 
 If Not IsNull(oTempFolderSubFolders) Then
  For Each oFolder in oTempFolderSubFolders
   if sDebug = "true" Then
    WScript.StdOut.Writeline "Deleting " &  oFolder.Path
   End IF
   fso.DeleteFolder oFolder.Path, True
  Next
 End If
 
 'delete files in temp folder
 Set oTempFiles = oTempFolder.Files
 If Not IsNull(oTempFiles) Then
  For Each oFile in oTempFiles
   if sDebug = "true" Then
    WScript.StdOut.Writeline "Deleting " &  oFile.Path
   End If
   fso.DeleteFile oFile.Path, True
  Next
 End IF
End Sub

Note: if this does not appear to work see KB 38045

Example of How to End a Process

function Query(obj, query)
{
    rtnValue = new Enumerator(obj.ExecQuery(query));
    return rtnValue.item();
}

function Start()
{
    var proc = '%!Enter the Process Name (Example: notepad.exe)!%';
    var obj = GetObject("winmgmts:{impersonationLevel=Impersonate}\\\\.\\root\\cimv2");
    var process = Query(obj, "Select * From Win32_Process Where Description='" + proc + "'");

    if (process == null)
        WScript.Quit(-1);
    else
        process.Terminate();
}

Start();

Example of How to Show Hardware Inventory Locally

'This script output basic Hardware Inventory information to the screen locally. 
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")

Wscript.Echo "BIOS INFO:"

For each objBIOS in colBIOS
    Wscript.Echo "Manufacturer: " & objBIOS.Manufacturer
    Wscript.Echo "Name: " & objBIOS.Name
    Wscript.Echo "Primary BIOS: " & objBIOS.PrimaryBIOS
    Wscript.Echo "Release Date: " & objBIOS.ReleaseDate
    Wscript.Echo "Serial Number: " & objBIOS.SerialNumber
    Wscript.Echo "SMBIOS Version: " & objBIOS.SMBIOSBIOSVersion
    Wscript.Echo "SMBIOS Major Version: " & objBIOS.SMBIOSMajorVersion
    Wscript.Echo "SMBIOS Minor Version: " & objBIOS.SMBIOSMinorVersion
    Wscript.Echo "SMBIOS Present: " & objBIOS.SMBIOSPresent
    Wscript.Echo "Status: " & objBIOS.Status
    Wscript.Echo "Version: " & objBIOS.Version
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Fan")

Wscript.Echo ""
Wscript.Echo "COMPUTER FAN INFO:"

For Each objItem in colItems
    Wscript.Echo "Active Cooling: " & objItem.ActiveCooling
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Status Information: " & objItem.StatusInfo
    Wscript.Echo
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_OnBoardDevice")

Wscript.Echo ""
Wscript.Echo "ONBOARD DEVICES:"

For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device Type: " & objItem.DeviceType
    Wscript.Echo "Model: " & objItem.Model
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Tag: " & objItem.Tag
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")

Wscript.Echo "PROCESSOR INFO:"

For Each objItem in colItems
    Wscript.Echo "Address Width: " & objItem.AddressWidth
    Wscript.Echo "Architecture: " & objItem.Architecture
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "CPU Status: " & objItem.CpuStatus
    Wscript.Echo "Current Clock Speed: " & objItem.CurrentClockSpeed
    Wscript.Echo "Data Width: " & objItem.DataWidth
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "External Clock: " & objItem.ExtClock
    Wscript.Echo "Family: " & objItem.Family
    Wscript.Echo "L2 Cache Size: " & objItem.L2CacheSize
    Wscript.Echo "L2 Cache Speed: " & objItem.L2CacheSpeed
    Wscript.Echo "Level: " & objItem.Level
    Wscript.Echo "Load Percentage: " & objItem.LoadPercentage
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Maximum Clock Speed: " & objItem.MaxClockSpeed
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Processor ID: " & objItem.ProcessorId
    Wscript.Echo "Processor Type: " & objItem.ProcessorType
    Wscript.Echo "Revision: " & objItem.Revision
    Wscript.Echo "Role: " & objItem.Role
    Wscript.Echo "Socket Designation: " & objItem.SocketDesignation
    Wscript.Echo "Status Information: " & objItem.StatusInfo
    Wscript.Echo "Stepping: " & objItem.Stepping
    Wscript.Echo "Unique Id: " & objItem.UniqueId
    Wscript.Echo "Upgrade Method: " & objItem.UpgradeMethod
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo "Voltage Caps: " & objItem.VoltageCaps
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_IRQResource")

Wscript.Echo ""
Wscript.Echo "IRQ SETTINGS:"

For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Hardware: " & objItem.Hardware
    Wscript.Echo "IRQ Number: " & objItem.IRQNumber
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Trigger Level: " & objItem.TriggerLevel
    Wscript.Echo "Trigger Type: " & objItem.TriggerType
    Wscript.Echo
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard")

Wscript.Echo ""
Wscript.Echo "BASEBOARD PROPERTIES:"

For Each objItem in colItems
    For Each strOption in objItem.ConfigOptions
        Wscript.Echo "Configuration Option: " & strOption
    Next
    Wscript.Echo "Depth: " & objItem.Depth
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Height: " & objItem.Height
    Wscript.Echo "Hosting Board: " & objItem.HostingBoard
    Wscript.Echo "Hot Swappable: " & objItem.HotSwappable
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Model: " & objItem.Model
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Other Identifying Information: " & _
        objItem.OtherIdentifyingInfo
    Wscript.Echo "Part Number: " & objItem.PartNumber
    Wscript.Echo "Powered-On: " & objItem.PoweredOn
    Wscript.Echo "Product: " & objItem.Product
    Wscript.Echo "Removable: " & objItem.Removable
    Wscript.Echo "Replaceable: " & objItem.Replaceable
    Wscript.Echo "Requirements Description: " & objItem.RequirementsDescription
    Wscript.Echo "Requires Daughterboard: " & objItem.RequiresDaughterBoard
    Wscript.Echo "Serial Number: " & objItem.SerialNumber
    Wscript.Echo "SKU: " & objItem.SKU
    Wscript.Echo "Slot Layout: " & objItem.SlotLayout
    Wscript.Echo "Special Requirements: " & objItem.SpecialRequirements
    Wscript.Echo "Tag: " & objItem.Tag
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo "Weight: " & objItem.Weight
    Wscript.Echo "Width: " & objItem.Width
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Bus")

Wscript.Echo ""
Wscript.Echo "BUS PROPERTIES:"

For Each objItem in colItems
    Wscript.Echo "Bus Number: " & objItem.BusNum
    Wscript.Echo "Bus Type: " & objItem.BusType
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Next

Set colChassis = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")

Wscript.Echo ""
Wscript.Echo "CHASSIS PROPERTIES:"

For Each objChassis in colChassis
    For i = Lbound(objChassis.ChassisTypes) to Ubound(objChassis.ChassisTypes)
        Wscript.Echo objChassis.ChassisTypes(i)
    Next
Next