Export (0) Print
Expand All

Deleting Resources

Microsoft® Windows® 2000 Scripting Guide

The Delete method lets you delete instances of a managed resource. Not all WMI classes support the Delete method; those that do include Win32_Directory, CIM_DataFile, Win32_Share, and Win32_ScheduledJob. This means that you can use scripts to delete files, folders, shared folders, or scheduled tasks.

To delete a managed resource, retrieve the instance to be deleted, and then call the Delete method. The script template in Listing 6.28 demonstrates this operation by deleting the shared folder named "New Share Name."

Listing 6.28 Template for Deleting Resources

  
1
2
3
4
5
6
7
8
9
10
11
12
13


strComputer = "."
strNamespace = "\root\cimv2"
strClassName = "Win32_Share"
strKeyName = "Name"
strKeyValue = "New Share Name"

Set objSWbemServices = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & strNamespace)

Set objInstance = objSWbemServices.Get(strClassName & "." &_
 strKeyName & "='" &_
 strKeyValue & "'")
objInstance.Delete

To use this template to delete other managed resources:

  1. Set the value of strClassName to the appropriate WMI class.

  2. If necessary, set the value of strNamespace to the appropriate WMI namespace.

  3. Set the value of strKeyName to the name of the key property for the class.

  4. Set the value of strKeyValue to the appropriate value.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft