The Portable Script Center

Version 2.0, September 2003

This help file contains all the scripts found in the TechNet Script Center (http://www.microsoft.com/technet/scriptcenter) as of September 15, 2003. Most of the scripts are designed to run with either Windows 2000, Windows XP, or Windows Server 2003, although many will also run on Windows NT 4.0 or Windows 98; in the latter two cases, however, you might need to install additional scripting technologies such as ADSI or WMI before the scripts will work. For more information about obtaining and installing ADSI, WMI, and the latest version of Windows Script Host (WSH 5.6), see the Script Center’s Scripting FAQ.

To help you identify which scripts will work with your computers, each script is accompanied by a table similar to this:

Supported Platforms

Windows Server 2003

Yes

Windows XP

Yes

Windows 2000

Yes

Windows NT 4.0

Yes, with Active Directory Client Extensions installed

Windows 98

Yes, with Active Directory Client Extensions installed

To use the scripts, copy the appropriate script code, paste the code into Notepad or another text editor, and save the file with a .vbs file extension. You can then run the script either by double-clicking the icon in Windows Explorer or by typing cscript at the command-line followed by the script name (this is generally preferred method of running the scripts). For example, to run the script my_script.vbs, type the following:

cscript my_script.vbs

For more information about these scripts, contact the Microsoft Scripting Guys at scripter@microsoft.com. If you would like to keep informed of the latest additions to the Script Center, receive beta copies of scripting utilities, and otherwise keep up-to-date on what’s going on in the world of scripting, subscribe to the Scripting Newswire. To subscribe to this free service (which is nothing more than periodic emails sent by the Scripitng Guys), send mail to scripter@microsoft.com, with the subject line Subscribe.

If you are interested in learning more about these scripts and how they work, check out the Microsoft Windows 2000 Scripting Guide. Many (but by no means all) of these scripts are featured in the Scripting Guide, along with a step-by-step explanation of what they do, how they work, and how they can be modified to better fit your individual needs. The Scripting Guide also provides a good introduction to basic scripting technologies such as WSH, VBScript, WMI, and ADSI.

A Note About the WMI Scripts

Most of the WMI scripts in this repository create a variable named strComputer, and then set the value of that variable to "." Thus, the scripts generally include this line:

strComputer = "."

This causes the script to run against the local computer. This is due to the way that the script has been composed, and the fact that WMI views a computer named "." as being the local computer. If you want to run the script against a remote computer, simply replace the "." with the name of the remote computer, surrounded by double quotation marks. For example, this line of code runs the script against a remote computer named PrintServer1:

strComputer = "PrintServer1"

This is the only change you need to make in order to run the WMI scripts against a remote computer. Bear in mind, however, that you will need to have administrative rights on the remote computer in order for the script to succeed. In addition, WMI must be installed both on the local computer and on the remote computer.


Changing Computer Account Attributes

Description
Demonstration script that changes the location attribute for a computer account in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objComputer = GetObject _
    ("LDAP://CN=atl-dc-01,CN=Computers,DC=fabrikam,DC=com")
objComputer.Put "Location" , "Building 37, Floor 2, Room 2133"
objComputer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying an Active Directory Computer Account

Description
Retrieves the attributes of an existing computer object and copies the attributes to a new computer object that the script creates.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objCompt = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")
Set objComptCopy = objCompt.Create("computer", "cn=SEA-SQL-01")
objComptCopy.Put "sAMAccountName", "sea-sql-01"
objComptCopy.SetInfo

Set objComptTemplate = _
    GetObject("LDAP://cn=SEA-PM-01,cn=Computers,dc=NA,dc=fabrikam,dc=com")
arrAttributes = Array("description", "location")

For Each strAttrib in arrAttributes
    strValue = objComptTemplate.Get(strAttrib)
    objComptCopy.Put strAttrib, strValue
Next

objComptCopy.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Computer Account For a User

Description
Creates and enables a computer account in Active Directory, which a specific, authenticated user can use to add his or her workstation to the domain.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Option Explicit

Dim strComputer, strComputerUser
Dim objRootDSE, objContainer, objComputer
Dim objSecurityDescriptor, objDACL
Dim objACE1, objACE2, objACE3, objACE4, objACE5
Dim objACE6, objACE7, objACE8, objACE9

strComputer = "atl-pro-002"
strComputerUser = "fabrikam\lewjudy"

' ADS_USER_FLAG_ENUM
Const ADS_UF_PASSWD_NOTREQD            = &h0020
Const ADS_UF_WORKSTATION_TRUST_ACCOUNT = &h1000

' ADS_ACETYPE_ENUM
Const ADS_ACETYPE_ACCESS_ALLOWED        = &h0
Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &h5

' ADS_FLAGTYPE_ENUM
Const ADS_FLAG_OBJECT_TYPE_PRESENT = &h1

' ADS_RIGHTS_ENUM
Const ADS_RIGHT_GENERIC_READ      = &h80000000
Const ADS_RIGHT_DS_SELF           = &h8
Const ADS_RIGHT_DS_WRITE_PROP     = &h20
Const ADS_RIGHT_DS_CONTROL_ACCESS = &h100

'controlAccessRight rightsGuid values
Const ALLOWED_TO_AUTHENTICATE    = "{68B1D179-0D15-4d4f-AB71-46152E79A7BC}"
Const RECEIVE_AS                 = "{AB721A56-1E2f-11D0-9819-00AA0040529B}"
Const SEND_AS                    = "{AB721A54-1E2f-11D0-9819-00AA0040529B}"
Const USER_CHANGE_PASSWORD       = "{AB721A53-1E2f-11D0-9819-00AA0040529b}"
Const USER_FORCE_CHANGE_PASSWORD = "{00299570-246D-11D0-A768-00AA006E0529}"
Const USER_ACCOUNT_RESTRICTIONS  = "{4C164200-20C0-11D0-A768-00AA006E0529}"
Const VALIDATED_DNS_HOST_NAME    = "{72E39547-7B18-11D1-ADEF-00C04FD8D5CD}"
Const VALIDATED_SPN              = "{F3A64788-5306-11D1-A9C5-0000F80367C1}"

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Computers," & _
                             objRootDSE.Get("defaultNamingContext"))

Set objComputer = objContainer.Create("Computer", "cn=" & strComputer)
objComputer.Put "sAMAccountName", strComputer & "$"
objComputer.Put "userAccountControl", _
                ADS_UF_PASSWD_NOTREQD Or ADS_UF_WORKSTATION_TRUST_ACCOUNT
objComputer.SetInfo

Set objSecurityDescriptor = objComputer.Get("ntSecurityDescriptor")
Set objDACL = objSecurityDescriptor.DiscretionaryAcl

Set objACE1 = CreateObject("AccessControlEntry")
objACE1.Trustee    = strComputerUser
objACE1.AccessMask = ADS_RIGHT_GENERIC_READ
objACE1.AceFlags   = 0
objACE1.AceType    = ADS_ACETYPE_ACCESS_ALLOWED

' objACE2 through objACE6: Extended Rights
Set objACE2 = CreateObject("AccessControlEntry")
objACE2.Trustee    = strComputerUser
objACE2.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
objACE2.AceFlags   = 0
objACE2.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE2.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE2.ObjectType = ALLOWED_TO_AUTHENTICATE

Set objACE3 = CreateObject("AccessControlEntry")
objACE3.Trustee    = strComputerUser
objACE3.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
objACE3.AceFlags   = 0
objACE3.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE3.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE3.ObjectType = RECEIVE_AS

Set objACE4 = CreateObject("AccessControlEntry")
objACE4.Trustee    = strComputerUser
objACE4.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
objACE4.AceFlags   = 0
objACE4.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE4.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE4.ObjectType = SEND_AS

Set objACE5 = CreateObject("AccessControlEntry")
objACE5.Trustee    = strComputerUser
objACE5.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
objACE5.AceFlags   = 0
objACE5.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE5.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE5.ObjectType = USER_CHANGE_PASSWORD

Set objACE6 = CreateObject("AccessControlEntry")
objACE6.Trustee    = strComputerUser
objACE6.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
objACE6.AceFlags   = 0
objACE6.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE6.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE6.ObjectType = USER_FORCE_CHANGE_PASSWORD

' objACE7: Property Sets
Set objACE7 = CreateObject("AccessControlEntry")
objACE7.Trustee    = strComputerUser
objACE7.AccessMask = ADS_RIGHT_DS_WRITE_PROP
objACE7.AceFlags   = 0
objACE7.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE7.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE7.ObjectType = USER_ACCOUNT_RESTRICTIONS

' objACE8 and objACE9: Validated Rights
Set objACE8 = CreateObject("AccessControlEntry")
objACE8.Trustee    = strComputerUser
objACE8.AccessMask = ADS_RIGHT_DS_SELF
objACE8.AceFlags   = 0
objACE8.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE8.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE8.ObjectType = VALIDATED_DNS_HOST_NAME

Set objACE9 = CreateObject("AccessControlEntry")
objACE9.Trustee    = strComputerUser
objACE9.AccessMask = ADS_RIGHT_DS_SELF
objACE9.AceFlags   = 0
objACE9.AceType    = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT
objACE9.Flags      = ADS_FLAG_OBJECT_TYPE_PRESENT
objACE9.ObjectType = VALIDATED_SPN

objDACL.AddAce objACE1
objDACL.AddAce objACE2
objDACL.AddAce objACE3
objDACL.AddAce objACE4
objDACL.AddAce objACE5
objDACL.AddAce objACE6
objDACL.AddAce objACE7
objDACL.AddAce objACE8
objDACL.AddAce objACE9

objSecurityDescriptor.DiscretionaryAcl = objDACL
objComputer.Put "ntSecurityDescriptor", objSecurityDescriptor
objComputer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Computer Account

Description
Deletes an individual computer account in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "atl-pro-040"
set objComputer = GetObject("LDAP://CN=" & strComputer & _
                            ",CN=Computers,DC=fabrikam,DC=com")
objComputer.DeleteObject (0)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling a Global Catalog Server

Description
Disables the global catalog service on a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "atl-dc-01"

Const NTDSDSA_OPT_IS_GC = 1

Set objRootDSE = GetObject("LDAP://" & strComputer & "/rootDSE")
strDsServiceDN = objRootDSE.Get("dsServiceName")
Set objDsRoot  = GetObject("LDAP://" & strComputer & "/" & strDsServiceDN)
intOptions = objDsRoot.Get("options")

If intOptions And NTDSDSA_OPT_IS_GC Then
    objDsRoot.Put "options", intOptions Xor NTDSDSA_OPT_IS_GC
    objDsRoot.Setinfo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling a Global Catalog Server

Description
Enables the global catalog service on a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client extensions installed

Script Code

strComputer = "atl-dc-01"

Const NTDSDSA_OPT_IS_GC = 1

Set objRootDSE = GetObject("LDAP://" & strComputer & "/RootDSE")
strDsServiceDN = objRootDSE.Get("dsServiceName")
Set objDsRoot  = GetObject("LDAP://" & strComputer & "/" & strDsServiceDN)
intOptions = objDsRoot.Get("options")

If (intOptions And NTDSDSA_OPT_IS_GC) = FALSE Then
    objDsRoot.Put "options" , intOptions Or NTDSDSA_OPT_IS_GC
    objDsRoot.Setinfo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Computer Account Attributes

Description
Demonstration script that retrieves the location and description attributes for a computer account in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client extensions installed
Windows 98 | Yes, with Active Directory Client extensions installed

Script Code

On Error Resume Next
Set objComputer = GetObject _
    ("LDAP://CN=atl-dc-01,CN=Computers,DC=fabrikam,DC=com")
objProperty = objComputer.Get("Location")
If IsNull(objProperty) Then
    Wscript.Echo "The location has not been set for this computer."
Else
    Wscript.Echo "Location: " & objProperty
    objProperty = Null
End If
objProperty = objComputer.Get("Description")
If IsNull(objProperty) Then
    Wscript.Echo "The description has not been set for this computer."
Else
    Wscript.Echo "Description: " & objProperty
    objProperty = Null
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Computer Accounts in Active Directory

Description
Returns the name and location for all the computer accounts in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://DC=fabrikam,DC=com' " _
        & "where objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
    Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying a Global Catalog Server

Description
Indicates whether or not a specified domain controller is a global catalog server.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client extensions installed
Windows 98 | Yes, with Active Directory Client extensions installed

Script Code

strComputer = "atl-dc-01"

Const NTDSDSA_OPT_IS_GC = 1

Set objRootDSE = GetObject("LDAP://" & strComputer & "/rootDSE")
strDsServiceDN = objRootDSE.Get("dsServiceName")
Set objDsRoot  = GetObject("LDAP://" & strComputer & "/" & strDsServiceDN)
intOptions = objDsRoot.Get("options")

If intOptions And NTDSDSA_OPT_IS_GC Then
    WScript.Echo strComputer & " is a global catalog server."
Else
    Wscript.Echo strComputer & " is not a global catalog server."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Computer Roles

Description
Returns the basic role (domain controller, member server, workstation, etc.) for a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
    ("Select DomainRole from Win32_ComputerSystem")
For Each objComputer in colComputers
    Select Case objComputer.DomainRole
        Case 0
            strComputerRole = "Standalone Workstation"
        Case 1
            strComputerRole = "Member Workstation"
        Case 2
            strComputerRole = "Standalone Server"
        Case 3
            strComputerRole = "Member Server"
        Case 4
            strComputerRole = "Backup Domain Controller"
        Case 5
            strComputerRole = "Primary Domain Controller"
    End Select
    Wscript.Echo strComputerRole
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Computer Roles Using Services

Description
Indicates whether SQL Server is running on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, but only against remote computers

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name = 'MSSQLServer'")
If colServices.Count > 0 Then
    For Each objService in colServices
        Wscript.Echo "SQL Server is " & objService.State & "."
    Next
Else
    Wscript.Echo "SQL Server is not installed on this computer."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying FSMO Roles

Description
Identify which Active Directory domain controllers are providing the five FSMO roles: Schema Master, Domain Naming Master, PDC Emulator, RID Master, and Infrastructure Master.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objRootDSE = GetObject("LDAP://rootDSE")

' Schema Master
Set objSchema = GetObject("LDAP://" & objRootDSE.Get("schemaNamingContext"))
strSchemaMaster = objSchema.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strSchemaMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Forest-wide Schema Master FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' Domain Naming Master
Set objPartitions = GetObject("LDAP://CN=Partitions," & _
                              objRootDSE.Get("configurationNamingContext"))
strDomainNamingMaster = objPartitions.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strDomainNamingMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Forest-wide Domain Naming Master FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' PDC Emulator
Set objDomain = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext"))
strPdcEmulator = objDomain.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strPdcEmulator)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's PDC Emulator FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' RID Master
Set objRidManager = GetObject("LDAP://CN=RID Manager$,CN=System," & _
                              objRootDSE.Get("defaultNamingContext"))
strRidMaster = objRidManager.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strRidMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's RID Master FSMO: " & objComputer.Name

Set objNtds = Nothing
Set objComputer = Nothing

' Infrastructure Master
Set objInfrastructure = GetObject("LDAP://CN=Infrastructure," & _
                                  objRootDSE.Get("defaultNamingContext"))
strInfrastructureMaster = objInfrastructure.Get("fSMORoleOwner")
Set objNtds = GetObject("LDAP://" & strInfrastructureMaster)
Set objComputer = GetObject(objNtds.Parent)
WScript.Echo "Domain's Infrastructure Master FSMO: " & objComputer.Name

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Joining a Computer to a Domain

Joining Computer to a Domain

Description
Joins a computer to a domain and creates the computer's account in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const JOIN_DOMAIN             = 1
Const ACCT_CREATE             = 2
Const ACCT_DELETE             = 4
Const WIN9X_UPGRADE           = 16
Const DOMAIN_JOIN_IF_JOINED   = 32
Const JOIN_UNSECURE           = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET        = 256
Const INSTALL_INVOCATION      = 262144

strDomain   = "FABRIKAM"
strPassword = "ls4k5ywA"
strUser     = "shenalan"

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
    strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
        strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
                                                strPassword, _
                                                strDomain & "\" & strUser, _
                                                NULL, _
                                                JOIN_DOMAIN + ACCT_CREATE)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a Computer Account

Description
Moves a computer account from the Computers container in Active Directory to an OU.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objNewOU = GetObject("LDAP://OU=Finance,DC=fabrikam,DC=com")
Set objMoveComputer = objNewOU.MoveHere _
    ("LDAP://CN=atl-pro-03,CN=Computers,DC=fabrikam,DC=com", "CN=atl-pro-03")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Performing a Cross-Domain Move of a Computer Object

Description
Uses the MoveHere method in IADsContainer to move an object to another domain. Note that there are a number of restrictions associated with performing this type of move operation. For details, see the Directory Services Platform SDK.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")
objOU.MoveHere "LDAP://cn=Computer01,cn=Users,dc=fabrikam,dc=com", _
    vbNullString

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming a Computer Account

Description
Renames an Active Directory computer account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objNewOU = GetObject("LDAP://OU=Finance,DC=fabrikam,DC=com")
Set objMoveComputer = objNewOU.MoveHere _
    ("LDAP://CN=atl-pro-037,OU=Finance,DC=fabrikam,DC=com", _
        "CN=atl-pro-003")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming a Computer and Computer Account

Description
Renames a computer and its corresponding Active Directory computer account. Requires Windows XP or Windows .NET Server, and must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
    err = ObjComputer.Rename("WebServer")
    Wscript.Echo err
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resetting a Computer Account Password

Description
Resets a computer account password in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objComputer = GetObject _
    ("LDAP://CN=atl-dc-01,CN=Computers,DC=Reskit,DC=COM")
objComputer.SetPassword "atl-dc-01$"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Searching for Computer Accounts

Description
Returns the name and location for all the computer accounts in Active Directory that are running Windows .NET Server.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name, Location, operatingSystemVersion from 'LDAP://DC=fabrikam,DC=com'" _
       & " where objectClass='computer' and operatingSystemVersion = '5.1 (3600)'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
    Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Computer Baseboard Properties

Description
Returns information about the computer baseboard.

For more information about the Win32_Baseboard class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard")
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

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Computer Bus Properties

Description
Returns information about the computer bus.

For more information about the Win32_Bus class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Bus")
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

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Desktop Monitor Properties

Description
Returns information about the desktop monitor connected to a computer.

For more information about the Win32_DesktopMonitor class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DesktopMonitor")
For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Bandwidth: " & objItem.Bandwidth
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Display Type: " & objItem.DisplayType
    Wscript.Echo "Is Locked: " & objItem.IsLocked
    Wscript.Echo "Monitor Manufacturer: " & objItem.MonitorManufacturer
    Wscript.Echo "Monitor Type: " & objItem.MonitorType
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Pixels Per X Logical Inch: " & objItem.PixelsPerXLogicalInch
    Wscript.Echo "Pixels Per Y Logical Inch: " & objItem.PixelsPerYLogicalInch
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Screen Height: " & objItem.ScreenHeight
    Wscript.Echo "Screen Width: " & objItem.ScreenWidth
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Device Memory Addresses

Description
Returns starting and ending memory addresses for all devices installed in a computer.

For more information about the Win32_DeviceMemoryAddress class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DeviceMemoryAddress")
For Each objItem in colItems
    Wscript.Echo "Ending Address: " & objItem.EndingAddress
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Starting Address: " & objItem.StartingAddress
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating DMA Channel Information

Description
Returns information about the configuration of DMA channels on a computer.

For more information about the Win32_DMAChannel class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DMAChannel")
For Each objItem in colItems
    Wscript.Echo "Address Size: " & objItem.AddressSize
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Byte Mode: " & objItem.ByteMode
    Wscript.Echo "Channel Timing: " & objItem.ChannelTiming
    Wscript.Echo "DMA Channel: " & objItem.DMAChannel
    Wscript.Echo "Maximum Transfer Size: " & objItem.MaxTransferSize
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Type C Timing: " & objItem.TypeCTiming
    Wscript.Echo "Word Mode: " & objItem.WordMode
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating IRQ Settings

Description
Returns information about the IRQ settings on a computer.

For more information about the Win32_IRQResource class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_IRQResource")
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

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Keyboard Properties

Description
Returns information about the keyboard connected to a computer.

For more information about the Win32_Keyboard class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Keyboard")
For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Is Locked: " & objItem.IsLocked
    Wscript.Echo "Layout: " & objItem.Layout
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Number of Function Keys: " & objItem.NumberOfFunctionKeys
    Wscript.Echo "Password: " & objItem.Password
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Memory Devices

Description
Returns starting and ending addresses for all memory devices installed on a computer.

For more information about the Win32_MemoryDevice class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_MemoryDevice")
For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Ending Address: " & objItem.EndingAddress
    Wscript.Echo "Starting Address: " & objItem.StartingAddress
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Onboard Devices

Description
Returns information about devices built into the motherboard installed in a computer.

For more information about the Win32_OnboardDevice class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OnBoardDevice")
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

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Parallel Port Properties

Description
Returns information about the parallel ports installed on a computer.

For more information about the Win32_ParallelPort class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ParallelPort",,48)
For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    For Each strCapability in objItem.Capabilities
        Wscript.Echo "Capability: " & strCapability
    Next
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "OS Auto Discovered: " & objItem.OSAutoDiscovered
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Physical Memory Properties

Description
Returns information about the physical memory installed on a computer.

For more information about the Win32_PhysicalMemoryArray class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_PhysicalMemoryArray")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Maximum Capacity: " & objItem.MaxCapacity
    Wscript.Echo "Memory Devices: " & objItem.MemoryDevices
    Wscript.Echo "Memory Error Correction: " & _
        objItem.MemoryErrorCorrection
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Plug and Play Devices

Description
Returns a list of all the Plug and Play devices installed on a computer.

For more information about the Win32_PnPEntity class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPEntity")
For Each objItem in colItems
    Wscript.Echo "Class GUID: " & objItem.ClassGuid
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Service: " & objItem.Service
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Plug and Play Signed Drivers

Description
Returns information about the signed plug and play drivers installed on a computer.

For more information about the Win32_PnPSignedDriver class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PnPSignedDriver")
For Each objItem in colItems
    Wscript.Echo "Class Guid: " & objItem.ClassGuid
    Wscript.Echo "Compatability ID: " & objItem.CompatID
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device Class: " & objItem.DeviceClass
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Device Name: " & objItem.DeviceName
    dtmWMIDate = objItem.DriverDate
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Driver Date: " & strReturn
    Wscript.Echo "Driver Provider Name: " & objItem.DriverProviderName
    Wscript.Echo "Driver Version: " & objItem.DriverVersion
    Wscript.Echo "HardWare ID: " & objItem.HardWareID
    Wscript.Echo "Inf Name: " & objItem.InfName
    Wscript.Echo "Is Signed: " & objItem.IsSigned
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "PDO: " & objItem.PDO
    Wscript.Echo "Signer: " & objItem.Signer
    Wscript.Echo
Next

Function WMIDateStringToDate(dtmWMIDate)
    If Not IsNull(dtmWMIDate) Then
    WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
         Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
             & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
                 Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate, _
                     13, 2))
    End If
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Pointing Device Properties

Description
Returns information about all the pointing devices (including mice and trackballs) installed on a computer.

For more information about the Win32_PointingDevice class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PointingDevice")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Device Interface: " & objItem.DeviceInterface
    Wscript.Echo "Double Speed Threshold: " & objItem.DoubleSpeedThreshold
    Wscript.Echo "Handedness: " & objItem.Handedness
    Wscript.Echo "Hardware Type: " & objItem.HardwareType
    Wscript.Echo "INF File Name: " & objItem.InfFileName
    Wscript.Echo "INF Section: " & objItem.InfSection
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Number Of Buttons: " & objItem.NumberOfButtons
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Pointing Type: " & objItem.PointingType
    Wscript.Echo "Quad Speed Threshold: " & objItem.QuadSpeedThreshold
    Wscript.Echo "Resolution: " & objItem.Resolution
    Wscript.Echo "Sample Rate: " & objItem.SampleRate
    Wscript.Echo "Synch: " & objItem.Synch
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Port Connector Properties

Description
Returns information about port connectors installed on a computer.

For more information about the Win32_PortConnector class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PortConnector")
For Each objItem in colItems
    Wscript.Echo "Connector Pinout: " & objItem.ConnectorPinout
    For Each strConnectorType in objItem.ConnectorType
        Wscript.Echo "Connector Type: " & strConnectorType
    Next
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "External Reference Designator: " & _
        objItem.ExternalReferenceDesignator
    Wscript.Echo "Internal Reference Designator: " & _
        objItem.InternalReferenceDesignator
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Port Type: " & objItem.PortType
    Wscript.Echo "Serial Number: " & objItem.SerialNumber
    Wscript.Echo "Tag: " & objItem.Tag
    Wscript.Echo "Version: " & objItem.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Possible Video Controller Resolutions

Description
Returns a list of all possible video display resolutions that can be configured on a computer.

For more information about the CIM_VideoControllerResolution class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from CIM_VideoControllerResolution")
For Each objItem in colItems
    Wscript.Echo "Horizontal Resolution: " & objItem.HorizontalResolution
    Wscript.Echo "Number Of Colors: " & objItem.NumberOfColors
    Wscript.Echo "Refresh Rate: " & objItem.RefreshRate
    Wscript.Echo "Scan Mode: " & objItem.ScanMode
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Vertical Resolution: " & objItem.VerticalResolution
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Processor Information

Description
Returns information about the processors installed on a computer.

For more information about the Win32_Processor class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
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 "Ext 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

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Physical Memory Configuration

Description
Returns information about the way physical memory is configured on a computer.

For more information about the Win32_PhysicalMemory class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
For Each objItem in colItems
    Wscript.Echo "Bank Label: " & objItem.BankLabel
    Wscript.Echo "Capacity: " & objItem.Capacity
    Wscript.Echo "Data Width: " & objItem.DataWidth
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device Locator: " & objItem.DeviceLocator
    Wscript.Echo "Form Factor: " & objItem.FormFactor
    Wscript.Echo "Hot Swappable: " & objItem.HotSwappable
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Memory Type: " & objItem.MemoryType
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Part Number: " & objItem.PartNumber
    Wscript.Echo "Position In Row: " & objItem.PositionInRow
    Wscript.Echo "Speed: " & objItem.Speed
    Wscript.Echo "Tag: " & objItem.Tag
    Wscript.Echo "Type Detail: " & objItem.TypeDetail
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Serial Port Configuration Properties

Description
Enumerates configuration values for all the serial ports installed on a computer.

For more information about the Win32_SerialPortConfiguration class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_SerialPortConfiguration")
For Each objItem in colItems
    Wscript.Echo "Abort Read Write On Error: " & _
        objItem.AbortReadWriteOnError
    Wscript.Echo "Baud Rate: " & objItem.BaudRate
    Wscript.Echo "Binary Mode Enabled: " & objItem.BinaryModeEnabled
    Wscript.Echo "Bits Per Byte: " & objItem.BitsPerByte
    Wscript.Echo "Continue XMit On XOff: " & objItem.ContinueXMitOnXOff
    Wscript.Echo "CTS Outflow Control: " & objItem.CTSOutflowControl
    Wscript.Echo "Discard NULL Bytes: " & objItem.DiscardNULLBytes
    Wscript.Echo "DSR Outflow Control: " & objItem.DSROutflowControl
    Wscript.Echo "DSR Sensitivity: " & objItem.DSRSensitivity
    Wscript.Echo "DTR Flow Control Type: " & objItem.DTRFlowControlType
    Wscript.Echo "EOF Character: " & objItem.EOFCharacter
    Wscript.Echo "Error Replace Character: " & objItem.ErrorReplaceCharacter
    Wscript.Echo "Error Replacement Enabled: " & _
        objItem.ErrorReplacementEnabled
    Wscript.Echo "Event Character: " & objItem.EventCharacter
    Wscript.Echo "Is Busy: " & objItem.IsBusy
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Parity: " & objItem.Parity
    Wscript.Echo "Parity Check Enabled: " & objItem.ParityCheckEnabled
    Wscript.Echo "RTS Flow Control Type: " & objItem.RTSFlowControlType
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Stop Bits: " & objItem.StopBits
    Wscript.Echo "XOff Character: " & objItem.XOffCharacter
    Wscript.Echo "XOff XMit Threshold: " & objItem.XOffXMitThreshold
    Wscript.Echo "XOn Character: " & objItem.XOnCharacter
    Wscript.Echo "XOn XMit Threshold: " & objItem.XOnXMitThreshold
    Wscript.Echo "XOn XOff InFlow Control: " & _
        objItem.XOnXOffInFlowControl
    Wscript.Echo "XOn XOff OutFlow Control: " & _
        objItem.XOnXOffOutFlowControl
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Serial Port Properties

Description
Returns information about the serial ports installed on a computer.

For more information about the Win32_SerialPort class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_SerialPort",,48)
For Each objItem in colItems
    Wscript.Echo "Binary: " & objItem.Binary
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Maximum Baud Rate: " & objItem.MaxBaudRate
    Wscript.Echo "Maximum Input Buffer Size: " & objItem.MaximumInputBufferSize
    Wscript.Echo "Maximum Output Buffer Size: " & objItem.MaximumOutputBufferSize
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "OS Auto Discovered: " & objItem.OSAutoDiscovered
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Provider Type: " & objItem.ProviderType
    Wscript.Echo "Settable Baud Rate: " & objItem.SettableBaudRate
    Wscript.Echo "Settable Data Bits: " & objItem.SettableDataBits
    Wscript.Echo "Settable Flow Control: " & objItem.SettableFlowControl
    Wscript.Echo "Settable Parity: " & objItem.SettableParity
    Wscript.Echo "Settable Parity Check: " & objItem.SettableParityCheck
    Wscript.Echo "Settable RLSD: " & objItem.SettableRLSD
    Wscript.Echo "Settable Stop Bits: " & objItem.SettableStopBits
    Wscript.Echo "Supports 16-Bit Mode: " & objItem.Supports16BitMode
    Wscript.Echo "Supports DTRDSR: " & objItem.SupportsDTRDSR
    Wscript.Echo "Supports Elapsed Timeouts: " & objItem.SupportsElapsedTimeouts
    Wscript.Echo "Supports Int Timeouts: " & objItem.SupportsIntTimeouts
    Wscript.Echo "Supports Parity Check: " & objItem.SupportsParityCheck
    Wscript.Echo "Supports RLSD: " & objItem.SupportsRLSD
    Wscript.Echo "Supports RTSCTS: " & objItem.SupportsRTSCTS
    Wscript.Echo "Supports Special Characters: " & objItem.SupportsSpecialCharacters
    Wscript.Echo "Supports XOn XOff: " & objItem.SupportsXOnXOff
    Wscript.Echo "Supports XOn XOff Setting: " & objItem.SupportsXOnXOffSet
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Sound Card Properties

Description
Retrieves information about all the sound cards installed on a computer.

For more information about the Win32_SoundDevice class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_SoundDevice")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "DMA Buffer Size: " & objItem.DMABufferSize
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "MPU 401 Address: " & objItem.MPU401Address
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Product Name: " & objItem.ProductName
    Wscript.Echo "Status Information: " & objItem.StatusInfo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating System Slot Properties

Description
Returns information about the system slots installed on a computer.

For more information about the Win32_SystemSlot class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_SystemSlot",,48)
For Each objItem in colItems
    For Each strConnectorPinout in objItem.ConnectorPinout
        Wscript.Echo "Connector Pinout: " & strConnectorPinout
    Next
    Wscript.Echo "Connector Type: " & objItem.ConnectorType
    Wscript.Echo "Current Usage: " & objItem.CurrentUsage
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Height Allowed: " & objItem.HeightAllowed
    Wscript.Echo "Length Allowed: " & objItem.LengthAllowed
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Maximum Data Width: " & objItem.MaxDataWidth
    Wscript.Echo "Model: " & objItem.Model
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Number: " & objItem.Number
    Wscript.Echo "PME Signal: " & objItem.PMESignal
    Wscript.Echo "Shared: " & objItem.Shared
    Wscript.Echo "Slot Designation: " & objItem.SlotDesignation
    Wscript.Echo "Supports Hot Plug: " & objItem.SupportsHotPlug
    Wscript.Echo "Tag: " & objItem.Tag
    Wscript.Echo "Thermal Rating: " & objItem.ThermalRating
    For Each strVccVoltageSupport in objItem.VccMixedVoltageSupport
        Wscript.Echo "VCC Mixed Voltage Support: " & strVccVoltageSupport
    Next
    Wscript.Echo "Version: " & objItem.Version
    For Each strVppVoltageSupport in objItem.VppMixedVoltageSupport
        Wscript.Echo "VPP Mixed Voltage Support: " & strVppVoltageSupport
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Video Controller Properties

Description
Retrieves information about the video controller installed on a computer.

For more information about the Win32_VideoController class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_VideoController")
For Each objItem in colItems
    For Each strCapability in objItem.AcceleratorCapabilities
        Wscript.Echo "Accelerator Capability: " & strCapability
    Next
    Wscript.Echo "Adapter Compatibility: " & objItem.AdapterCompatibility
    Wscript.Echo "Adapter DAC Type: " & objItem.AdapterDACType
    Wscript.Echo "Adapter RAM: " & objItem.AdapterRAM
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Color Table Entries: " & objItem.ColorTableEntries
    Wscript.Echo "Current Bits Per Pixel: " & objItem.CurrentBitsPerPixel
    Wscript.Echo "Current Horizontal Resolution: " & _
        objItem.CurrentHorizontalResolution
    Wscript.Echo "Current Number Of Colors: " & objItem.CurrentNumberOfColors
    Wscript.Echo "Current Number Of Columns: " & _
        objItem.CurrentNumberOfColumns
    Wscript.Echo "Current Number Of Rows: " & objItem.CurrentNumberOfRows
    Wscript.Echo "Current Refresh Rate: " & objItem.CurrentRefreshRate
    Wscript.Echo "Current Scan Mode: " & objItem.CurrentScanMode
    Wscript.Echo "Current Vertical Resolution: " & _
        objItem.CurrentVerticalResolution
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Device Specific Pens: " & objItem.DeviceSpecificPens
    Wscript.Echo "Dither Type: " & objItem.DitherType
    Wscript.Echo "Driver Date: " & objItem.DriverDate
    Wscript.Echo "Driver Version: " & objItem.DriverVersion
    Wscript.Echo "ICM Intent: " & objItem.ICMIntent
    Wscript.Echo "ICM Method: " & objItem.ICMMethod
    Wscript.Echo "INF Filename: " & objItem.InfFilename
    Wscript.Echo "INF Section: " & objItem.InfSection
    Wscript.Echo "Installed Display Drivers: " & _
        objItem.InstalledDisplayDrivers
    Wscript.Echo "Maximum Memory Supported: " & objItem.MaxMemorySupported
    Wscript.Echo "Maximum Number Controlled: " & objItem.MaxNumberControlled
    Wscript.Echo "Maximum Refresh Rate: " & objItem.MaxRefreshRate
    Wscript.Echo "Minimum Refresh Rate: " & objItem.MinRefreshRate
    Wscript.Echo "Monochrome: " & objItem.Monochrome
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Number of Color Planes: " & objItem.NumberOfColorPlanes
    Wscript.Echo "Number of Video Pages: " & objItem.NumberOfVideoPages
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Reserved System Palette Entries: " & _
        objItem.ReservedSystemPaletteEntries
    Wscript.Echo "Specification Version: " & objItem.SpecificationVersion
    Wscript.Echo "System Palette Entries: " & objItem.SystemPaletteEntries
    Wscript.Echo "Video Architecture: " & objItem.VideoArchitecture
    Wscript.Echo "Video Memory Type: " & objItem.VideoMemoryType
    Wscript.Echo "Video Mode: " & objItem.VideoMode
    Wscript.Echo "Video Mode Description: " & objItem.VideoModeDescription
    Wscript.Echo "Video Processor: " & objItem.VideoProcessor
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Computer Chassis Type

Description
Retrieves an integer value indicating the chassis type for a computer (mini-tower, laptop, etc.). Script does not include a description of each value that can be returned.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
    For i = Lbound(objChassis.ChassisTypes) to Ubound(objChassis.ChassisTypes)
        Wscript.Echo objChassis.ChassisTypes(i)
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Processor Type

Description
Determines the processor architecture (such as x86 or ia64) for a specified computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objProcessor = objWMIService.Get("win32_Processor='CPU0'")

If objProcessor.Architecture = 0 Then
    Wscript.Echo "This is an x86 computer."
ElseIf objProcessor.Architecture = 1 Then
    Wscript.Echo "This is a MIPS computer."
ElseIf objProcessor.Architecture = 2 Then
    Wscript.Echo "This is an Alpha computer."
ElseIf objProcessor.Architecture = 3 Then
    Wscript.Echo "This is a PowerPC computer."
ElseIf objProcessor.Architecture = 6 Then
    Wscript.Echo "This is an ia64 computer."
Else
    Wcript.Echo "The computer type could not be determined."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Inventorying Computer Hardware

Description
Returns information about the pointing devices installed on a computer. Used as an example of how to retrieve hardware information using WMI.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMice = objWMIService.ExecQuery _
    ("Select * from Win32_PointingDevice")
For Each objMouse in colMice
    Wscript.Echo "Hardware Type: " & objMouse.HardwareType
    Wscript.Echo "Number of Buttons: " & objMouse.NumberOfButtons
    Wscript.Echo "Status: " & objMouse.Status
    Wscript.Echo "PNP Device ID: " & objMouse.PNPDeviceID
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Battery Information

Description
Returns information about all batteries connected to a computer.

For more information about the Win32_Battery class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery")
For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Battery Status: " & objItem.BatteryStatus
    Wscript.Echo "Chemistry: " & objItem.Chemistry
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Design Voltage: " & objItem.DesignVoltage
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Estimated Run Time: " & objItem.EstimatedRunTime
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Power Management Capabilities: "
    For Each objElement In objItem.PowerManagementCapabilities
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "Power Management Supported: " & objItem.PowerManagementSupported
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving BIOS Information

Description
Retrieves BIOS information for a computer, including BIOS version number and release date.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, except for the Version property
Windows NT 4.0 | Yes, with WMI installed, and except for the Version property
Windows 98 | Yes, with WMI installed, and except for the Version property

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
    Wscript.Echo "Build Number: " & objBIOS.BuildNumber
    Wscript.Echo "Current Language: " & objBIOS.CurrentLanguage
    Wscript.Echo "Installable Languages: " & objBIOS.InstallableLanguages
    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
    For i = 0 to Ubound(objBIOS.BiosCharacteristics)
        Wscript.Echo "BIOS Characteristics: " & _
            objBIOS.BiosCharacteristics(i)
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Cache Memory Information

Description
Returns information about both the internal and external cache memory found on a computer.

For more information about the Win32_CacheMemory class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CacheMemory")
For Each objItem in colItems
    Wscript.Echo "Access: " & objItem.Access
    Wscript.Echo "Additional Error Data: "
    For Each objElement In objItem.AdditionalErrorData
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "Associativity: " & objItem.Associativity
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Block Size: " & objItem.BlockSize
    Wscript.Echo "Cache Speed: " & objItem.CacheSpeed
    Wscript.Echo "Cache Type: " & objItem.CacheType
     Wscript.Echo "Current SRAM: "
    For Each objElement In objItem.CurrentSRAM
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Error Correct Type: " & objItem.ErrorCorrectType
    Wscript.Echo "Installed Size: " & objItem.InstalledSize
    Wscript.Echo "Level: " & objItem.Level
    Wscript.Echo "Location: " & objItem.Location
    Wscript.Echo "Maximum Cache Size: " & objItem.MaxCacheSize
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Number Of Blocks: " & objItem.NumberOfBlocks
    Wscript.Echo "Status Information: " & objItem.StatusInfo
    Wscript.Echo "Supported SRAM: "
    For Each objElement In objItem.SupportedSRAM
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "WritePolicy: " & objItem.WritePolicy
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Computer Fan Information

Description
Retrieves information about cooling fans installed in a computer.

For more information about the Win32_Fan class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Fan")
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

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Memory Array Information

Description
Returns starting and ending addresses for all memory arrays installed on a computer.

For more information about the Win32_MemoryArray class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_MemoryArray")
For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Ending Address: " & objItem.EndingAddress
    Wscript.Echo "Starting Address: " & objItem.StartingAddress
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Modem Information

Description
Retrieves information about all the modems installed in a computer.

For more information about the Win32_POTSModem class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_POTSModem")
For Each objItem in colItems
    Wscript.Echo "Attached To: " & objItem.AttachedTo
    Wscript.Echo "Blind Off: " & objItem.BlindOff
    Wscript.Echo "Blind On: " & objItem.BlindOn
    Wscript.Echo "Compression Off: " & objItem.CompressionOff
    Wscript.Echo "Compression On: " & objItem.CompressionOn
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Configuration Dialog: " & objItem.ConfigurationDialog
    Wscript.Echo "Country Selected: " & objItem.CountrySelected
    Wscript.Echo "DCB: "
    For Each objElement In objItem.DCB
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "Default: "
    For Each objElement In objItem.Default
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Device Type: " & objItem.DeviceType
    Wscript.Echo "Driver Date: " & objItem.DriverDate
    Wscript.Echo "Error Control Forced: " & objItem.ErrorControlForced
    Wscript.Echo "Error Control Off: " & objItem.ErrorControlOff
    Wscript.Echo "Error Control On: " & objItem.ErrorControlOn
    Wscript.Echo "Flow Control Hard: " & objItem.FlowControlHard
    Wscript.Echo "Flow Control Off: " & objItem.FlowControlOff
    Wscript.Echo "Flow Control Soft: " & objItem.FlowControlSoft
    Wscript.Echo "Inactivity Scale: " & objItem.InactivityScale
    Wscript.Echo "Inactivity Timeout: " & objItem.InactivityTimeout
    Wscript.Echo "Index: " & objItem.Index
    Wscript.Echo "Maximum Baud Rate To SerialPort: " & _
        objItem.MaxBaudRateToSerialPort
    Wscript.Echo "Model: " & objItem.Model
    Wscript.Echo "Modem Inf Path: " & objItem.ModemInfPath
    Wscript.Echo "Modem Inf Section: " & objItem.ModemInfSection
    Wscript.Echo "Modulation Bell: " & objItem.ModulationBell
    Wscript.Echo "Modulation CCITT: " & objItem.ModulationCCITT
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Port SubClass: " & objItem.PortSubClass
    Wscript.Echo "Prefix: " & objItem.Prefix
    Wscript.Echo "Properties: "
    For Each objElement In objItem.Properties
        WScript.Echo vbTab & objElement
    Next
    Wscript.Echo "Provider Name: " & objItem.ProviderName
    Wscript.Echo "Pulse: " & objItem.Pulse
    Wscript.Echo "Reset: " & objItem.Reset
    Wscript.Echo "Responses Key Name: " & objItem.ResponsesKeyName
    Wscript.Echo "Speaker Mode Dial: " & objItem.SpeakerModeDial
    Wscript.Echo "Speaker Mode Off: " & objItem.SpeakerModeOff
    Wscript.Echo "Speaker Mode On: " & objItem.SpeakerModeOn
    Wscript.Echo "Speaker Mode Setup: " & objItem.SpeakerModeSetup
    Wscript.Echo "Speaker Volume High: " & objItem.SpeakerVolumeHigh
    Wscript.Echo "Speaker Volume Info: " & objItem.SpeakerVolumeInfo
    Wscript.Echo "Speaker Volume Low: " & objItem.SpeakerVolumeLow
    Wscript.Echo "Speaker Volume Med: " & objItem.SpeakerVolumeMed
    Wscript.Echo "Status Info: " & objItem.StatusInfo
    Wscript.Echo "Terminator: " & objItem.Terminator
    Wscript.Echo "Tone: " & objItem.Tone
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Motherboard Device Information

Description
Retrieves information about the motherboard device installed in a computer.

For more information about the Win32_MotherboardDevice class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_MotherboardDevice")
For Each objItem in colItems
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Primary Bus Type: " & objItem.PrimaryBusType
    Wscript.Echo "Secondary Bus Type: " & objItem.SecondaryBusType
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving PCMCIA Controller Information

Description
Returns information about all PCMCIA controllers installed in a computer.

For more information about the Win32_PCMCIAController class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PCMCIAController")
For Each objItem in colItems
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Port Resource Information

Description
Returns information about all the I/O ports found on a computer.

For more information about the Win32_PortResource class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PortResource")
For Each objItem in colItems
    Wscript.Echo "Alias: " & objItem.Alias
    Wscript.Echo "Ending Address: " & objItem.EndingAddress
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Starting Address: " & objItem.StartingAddress
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Portable Battery Information

Description
Returns information about any portable battery (such as the batteries used to power laptop computers) in use on a computer.

For more information about the Win32_PortableBattery class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PortableBattery")
For Each objItem in colItems
    Wscript.Echo "Capacity Multiplier: " & objItem.CapacityMultiplier
    Wscript.Echo "Chemistry: " & objItem.Chemistry
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Design Capacity: " & objItem.DesignCapacity
    Wscript.Echo "Design Voltage: " & objItem.DesignVoltage
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Location: " & objItem.Location
    dtmWMIDate = objItem.ManufactureDate
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Manufacture Date: " & strReturn
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Maximum Battery Error: " & objItem.MaxBatteryError
    Wscript.Echo "Smart Battery Version: " & objItem.SmartBatteryVersion
    Wscript.Echo
Next

Function WMIDateStringToDate(dtmWMIDate)
    If Not IsNull(dtmWMIDate) Then
    WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
         Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
             & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
                 Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate, _
                     13, 2))
    End If
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving SMBIOS Information

Description
Retrieves part number, serial number, and asset tag number from SMBIOS-compliant computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
    Wscript.Echo "Part Number: " & objSMBIOS.PartNumber
    Wscript.Echo "Serial Number: " & objSMBIOS.SerialNumber
    Wscript.Echo "Asset Tag: " & objSMBIOS.SMBIOSAssetTag
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving System Information

Description
Uses WMI to retrieve the same data found in the System Information applet.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colSettings
    Wscript.Echo "OS Name: " & objOperatingSystem.Name
    Wscript.Echo "Version: " & objOperatingSystem.Version
    Wscript.Echo "Service Pack: " & _
        objOperatingSystem.ServicePackMajorVersion _
            & "." & objOperatingSystem.ServicePackMinorVersion
    Wscript.Echo "OS Manufacturer: " & objOperatingSystem.Manufacturer
    Wscript.Echo "Windows Directory: " & _
        objOperatingSystem.WindowsDirectory
    Wscript.Echo "Locale: " & objOperatingSystem.Locale
    Wscript.Echo "Available Physical Memory: " & _
        objOperatingSystem.FreePhysicalMemory
    Wscript.Echo "Total Virtual Memory: " & _
        objOperatingSystem.TotalVirtualMemorySize
    Wscript.Echo "Available Virtual Memory: " & _
        objOperatingSystem.FreeVirtualMemory
    Wscript.Echo "OS Name: " & objOperatingSystem.SizeStoredInPagingFiles
Next
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
    Wscript.Echo "System Name: " & objComputer.Name
    Wscript.Echo "System Manufacturer: " & objComputer.Manufacturer
    Wscript.Echo "System Model: " & objComputer.Model
    Wscript.Echo "Time Zone: " & objComputer.CurrentTimeZone
    Wscript.Echo "Total Physical Memory: " & _
        objComputer.TotalPhysicalMemory
Next
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_Processor")
For Each objProcessor in colSettings
    Wscript.Echo "System Type: " & objProcessor.Architecture
    Wscript.Echo "Processor: " & objProcessor.Description
Next
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For Each objBIOS in colSettings
    Wscript.Echo "BIOS Version: " & objBIOS.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Current Display Configuration

Description
Returns information about the current display settings on a computer.

For more information about the Win32_DisplayConfiguration class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_DisplayConfiguration")
For Each objItem in colItems
    Wscript.Echo "Bits Per Pel: " & objItem.BitsPerPel
    Wscript.Echo "Device Name: " & objItem.DeviceName
    Wscript.Echo "Display Flags: " & objItem.DisplayFlags
    Wscript.Echo "Display Frequency: " & objItem.DisplayFrequency
    Wscript.Echo "Driver Version: " & objItem.DriverVersion
    Wscript.Echo "Log Pixels: " & objItem.LogPixels
    Wscript.Echo "Pels Height: " & objItem.PelsHeight
    Wscript.Echo "Pels Width: " & objItem.PelsWidth
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Specification Version: " & objItem.SpecificationVersion
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Display Controller Configuration

Description
Returns information about the video adapters installed in a computer.

For more information about the Win32_DisplayControllerConfiguration class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_DisplayControllerConfiguration")
For Each objItem in colItems
    Wscript.Echo "Bits Per Pixel: " & objItem.BitsPerPixel
    Wscript.Echo "Color Planes: " & objItem.ColorPlanes
    Wscript.Echo "Device Entries in a ColorTable: " & _
        objItem.DeviceEntriesInAColorTable
    Wscript.Echo "Device Specific Pens: " & objItem.DeviceSpecificPens
    Wscript.Echo "Horizontal Resolution: " & objItem.HorizontalResolution
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Refresh Rate: " & objItem.RefreshRate
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Vertical Resolution: " & objItem.VerticalResolution
    Wscript.Echo "Video Mode: " & objItem.VideoMode
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Converting WMI Date-Time Values

Description
Demonstrates a method for converting the Universal Time Coordinate (UTC) values used by WMI to standard date-time values. The script retrieves the date that the operating system was installed, and passes that UTC value to a function named WMIDateStringToDate. This function converts the UTC value (such as 20011029113047.000000-480) to a standard date-time value (such as 10/29/2001 11:30:47 AM).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objOS = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
For Each strOS in objOS
    dtmInstallDate = strOS.InstallDate
    strReturn = WMIDateStringToDate(dtmInstallDate)
    Wscript.Echo strReturn
Next

Function WMIDateStringToDate(dtmInstallDate)
    WMIDateStringToDate = CDate(Mid(dtmInstallDate, 5, 2) & "/" & _
        Mid(dtmInstallDate, 7, 2) & "/" & Left(dtmInstallDate, 4) _
            & " " & Mid (dtmInstallDate, 9, 2) & ":" & _
                Mid(dtmInstallDate, 11, 2) & ":" & Mid(dtmInstallDate, _
                    13, 2))
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Local Time on a Computer

Description
Returns information about the local time configured on a computer.

For more information about the Win32_LocalTime class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
For Each objItem in colItems
    Wscript.Echo "Day: " & objItem.Day
    Wscript.Echo "Day Of Week: " & objItem.DayOfWeek
    Wscript.Echo "Hour: " & objItem.Hour
    Wscript.Echo "Minute: " & objItem.Minute
    Wscript.Echo "Month: " & objItem.Month
    Wscript.Echo "Quarter: " & objItem.Quarter
    Wscript.Echo "Second: " & objItem.Second
    Wscript.Echo "Week In Month: " & objItem.WeekInMonth
    Wscript.Echo "Year: " & objItem.Year
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Time Zone Offset from Greenwich Mean Time

Description
Determines the difference (in minutes) between the time zone in use on the specified computer and Greenwich Mean Time. The time zone offset can be extremely useful in WMI scripts that need to work with date-time values.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colTimeZone = objWMIService.ExecQuery("Select * from Win32_TimeZone")

For Each objTimeZone in colTimeZone
    Wscript.Echo "Offset: "& objTimeZone.Bias
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining UTC Time

Description
Reports the Universal Time Coordinate (UTC) time on a computer.

For more information about the Win32_UTCTime class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_UTCTime")
For Each objItem in colItems
    Wscript.Echo "Day: " & objItem.Day
    Wscript.Echo "Day Of the Week: " & objItem.DayOfWeek
    Wscript.Echo "Hour: " & objItem.Hour
    Wscript.Echo "Milliseconds: " & objItem.Milliseconds
    Wscript.Echo "Minute: " & objItem.Minute
    Wscript.Echo "Month: " & objItem.Month
    Wscript.Echo "Quarter: " & objItem.Quarter
    Wscript.Echo "Second: " & objItem.Second
    Wscript.Echo "Week In the Month: " & objItem.WeekInMonth
    Wscript.Echo "Year: " & objItem.Year
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Time Zone Information for a Computer

Description
Retrieve information about the time zone configured on a computer.

For more information about the Win32_TimeZone class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TimeZone")
For Each objItem in colItems
    Wscript.Echo "Bias: " & objItem.Bias
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Daylight Bias: " & objItem.DaylightBias
    Wscript.Echo "Daylight Day: " & objItem.DaylightDay
    Wscript.Echo "Daylight Day Of Week: " & objItem.DaylightDayOfWeek
    Wscript.Echo "Daylight Hour: " & objItem.DaylightHour
    Wscript.Echo "Daylight Millisecond: " & objItem.DaylightMillisecond
    Wscript.Echo "Daylight Minute: " & objItem.DaylightMinute
    Wscript.Echo "Daylight Month: " & objItem.DaylightMonth
    Wscript.Echo "Daylight Name: " & objItem.DaylightName
    Wscript.Echo "Daylight Second: " & objItem.DaylightSecond
    Wscript.Echo "Daylight Year: " & objItem.DaylightYear
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Standard Bias: " & objItem.StandardBias
    Wscript.Echo "Standard Day: " & objItem.StandardDay
    Wscript.Echo "Standard Day Of Week: " & objItem.StandardDayOfWeek
    Wscript.Echo "Standard Hour: " & objItem.StandardHour
    Wscript.Echo "Standard Millisecond: " & objItem.StandardMillisecond
    Wscript.Echo "Standard Minute: " & objItem.StandardMinute
    Wscript.Echo "Standard Month: " & objItem.StandardMonth
    Wscript.Echo "Standard Name: " & objItem.StandardName
    Wscript.Echo "Standard Second: " & objItem.StandardSecond
    Wscript.Echo "Standard Year: " & objItem.StandardYear
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Template to the Windows Explorer New Menu

Description
Demonstrates how to add VBScript Script File to the New context menu in Windows Explorer. Requires a script template named Template.vbs to be in the \Windows\System32\ShellExt folder (on Windows XP and Windows Server 2003), or in the \Winnt\ShellNew folder (Windows 2000).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.RegWrite "HKCR\.VBS\ShellNew\FileName","template.vbs"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding “Command Prompt Here” to Windows Explorer

Description
Adds a Command Prompt Here command to the Windows Explorer system menu. If a user selects Command Prompt Here from the system menu, a command window will be displayed, open to the same folder as the current Windows Explorer folder.

For more information about writing to the registry using Windows Script Host, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, but change cmd.exe to command.com

Script Code

Set objShell = CreateObject("WScript.Shell")

objShell.RegWrite "HKCR\Folder\Shell\MenuText\Command\", _
    "cmd.exe /k cd " & chr(34) & "%1" & chr(34)
objShell.RegWrite "HKCR\Folder\Shell\MenuText\", "Command Prompt Here"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Checking the Scripting Environment on the Local Computer

Description
Gets versions of operating system, WSH, WMI & ADSI on local machine and determines which are up-to-date.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

''******************************************************************************
'* scriptenv.vbs
'* Gets versions of OS, WSH, WMI & ADSI on local machine
'* and determines which are up-to-date.
'******************************************************************************

On Error Resume Next

Const MAXIMIZE_WINDOW = 3

strComputer = "."  ' local computer
strNamespace = "\root\cimv2" ' default namespace
blnWSHUpToDate = False
blnWMIUpToDate = False
blntADSIUpToDate = False

'******************************************************************************
'* Call functions to get information on default WSH host.
'* If Wscript.exe, temporarily change to Cscript.exe
'******************************************************************************

strWshHost = GetWshHost
ChangeToCscript(strWshHost)

'******************************************************************************
'* Connect to WMI Service.
'******************************************************************************

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

If Err.Number <> 0 Then
    WScript.Echo "Error 0x" & hex(Err.Number) & " " & _
      Err.Description & ". " & VbCrLf & _
        "Unable to connect to WMI. WMI may not be installed."
    Err.Clear
    WScript.Quit
End If

'******************************************************************************
'* Call functions to get information on OS, WSH, WMI and ADSI.
'******************************************************************************

intOSVer = GetOSVer
blnWSHUpToDate = GetWSHVer(intOSVer, strWshHost)
blnWMIUpToDate = GetWMIVer(intOSVer)
blnADSIUpToDate = GetADSIVer(intOSVer)

'******************************************************************************
'* Call sub to list which versions are current.
'******************************************************************************

ListUpToDate blnWSHUpToDate, blnWMIUpToDate, blnADSIUpToDate

'******************************************************************************
'* Determines WSH script host.
'******************************************************************************

Function GetWshHost()

    strErrorMessage = "Could not determine default script host."
   strFullName = WScript.FullName

    If Err.Number <> 0 Then
        WScript.Echo "Error 0x" & hex(Err.Number) & " " & _
          Err.Description & ". " & VbCrLf & strErrorMessage
        Err.Clear
        Exit Function
    End If

    If IsNull(strFullName) Then
        WScript.Echo strErrorMessage
      Exit Function
   End If

    strWshHost = Right(LCase(strFullName), 11)
    If Not((strWshHost = "wscript.exe") Or  (strWshHost = "cscript.exe")) Then
        WScript.Echo strErrorMessage
        Exit Function
    End If

   GetWshHost = strWshHost

End Function

'******************************************************************************
'* If default Windows Script Host is Wscript, change to Cscript.
'******************************************************************************

Sub ChangeToCscript(strWshHost)

   If strWshHost = "wscript.exe" Then
      Set objShell = CreateObject("WScript.Shell")
        objShell.Run _
       "%comspec% /k ""cscript //h:cscript&&cscript scriptenv.vbs""", _
        MAXIMIZE_WINDOW
       If Err.Number <> 0 Then
           WScript.Echo "Error 0x" & hex(Err.Number) & " occurred. " & _
         Err.Description & ". " & VbCrLf & _
         "Could not temporarily change the default script host to Cscript."
           Err.Clear
         WScript.Quit
       End If
      WScript.Quit
    End If

End Sub

'******************************************************************************
'* Get OS information.
'******************************************************************************

Function GetOSVer()

    intOSType = 0
    intOSVer = 0
    strOSVer = ""

    Set colOperatingSystems = objWMIService.ExecQuery _
      ("Select * from Win32_OperatingSystem")

    For Each objOperatingSystem In colOperatingSystems
        Wscript.Echo vbCrLf & "Operating System" & vbCrLf & _
                     "================" & vbCrLf & _
          "Caption:           " & objOperatingSystem.Caption & VbCrLf & _
          "OSType:            " & objOperatingSystem.OSType & VbCrLf & _
          "Version:           " & objOperatingSystem.Version & VbCrLf & _
          "Service Pack:      " & _
          objOperatingSystem.ServicePackMajorVersion & _
          "." & objOperatingSystem.ServicePackMinorVersion & VbCrLf & _
          "Windows Directory: " & objOperatingSystem.WindowsDirectory & VbCrLf
        intOSType = objOperatingSystem.OSType
        strOSVer = Left(objOperatingSystem.Version, 3)
    Next

    Select Case intOSType
        Case 16 'Windows 95
            intOSVer = 1
        Case 17 'Windows 98
            intOSVer = 2
      ' Note: Windows Millennium is not included as an OSType by WMI.
        Case 18
         Select Case strOSVer
             Case 4.0
                 intOSVer = 4 'Windows NT 4.0
             Case 5.0
                 intOSVer = 5 'Windows 2000
             Case 5.1
                 intOSVer = 6 'Windows XP
             Case 5.2
                 intOSVer = 7 'Windows Server 2003
                Case Else
                    intOSVer = 0 'Older or newer version
                End Select
       Case Else
            intOSVer = 0 'Older or newer version
    End Select

    GetOSVer = intOSVer

End Function

'******************************************************************************
'* Display WSH information.
'******************************************************************************

Function GetWSHVer(intOSVer, strWshHost)

    Wscript.Echo "Windows Script Host" & vbCrLf & _
                 "==================="

If Not strWshHost = "" Then
    strVersion = WScript.Version
   strBuild = WScript.BuildVersion
    Wscript.Echo _
      "WSH Default Script Host: " & strWshHost & VbCrLf & _
      "WSH Path:                " & WScript.FullName & VbCrLf & _
      "WSH Version & Build:     " & strVersion & "." & strBuild & VbCrLf
Else
      Wscript.Echo "WSH information cannot be retrieved."
End If

    sngWSHVer = CSng(strVersion)
    intBuild = CInt(strBuild)

    If (sngWSHVer >= 5.6 And intBuild >= 8515) Then
        GetWSHVer = True
   Else
       GetWSHVer = False
    End If

End Function

'******************************************************************************
'* Display WMI information.
'******************************************************************************

Function GetWMIVer(intOSVer)

    dblBuildVersion = 0

    If (intOSVer >= 1 And intOSVer <= 5) Then
        strWmiVer = "1.5"
    ElseIf intOSVer = 6 Then
        strWmiVer = "5.1"
    ElseIf intOSVer = 7 Then
        strWmiVer = "5.2"
    Else
        strWmiVer = "?.?"
    End If

    Set colWMISettings = objWMIService.ExecQuery _
      ("Select * from Win32_WMISetting")

    For Each objWMISetting In colWMISettings
        Wscript.Echo "Windows Management Instrumentation" & vbCrLf & _
                     "==================================" & vbCrLf & _
          "WMI Version & Build:         " & _
          strWmiVer & "." & objWMISetting.BuildVersion & vbCrLf & _
          "Default scripting namespace: " & _
          objWMISetting.ASPScriptDefaultNamespace & vbCrLf
        dblBuildVersion = CDbl(objWMISetting.BuildVersion)
    Next

    If (intOSVer = 7 And dblBuildVersion >= 3790.0000) Or _
      (intOSVer = 6 And dblBuildVersion >= 2600.0000) Or _
      (intOSVer <= 5 And dblBuildVersion >= 1085.0005) _
      Then
        GetWMIVer = True
     Else
          GetWMIVer = False
    End If

End Function

'******************************************************************************
'* Display ADSI provider and version information.
'******************************************************************************

Function GetADSIVer(intOSVer)

    Wscript.Echo "Active Directory Service Interfaces" & VbCrLf & _
                 "===================================" & vbCrLf

    Set objShell = CreateObject("WScript.Shell")
    strAdsiVer = _
    objShell.RegRead("HKLM\SOFTWARE\Microsoft\Active Setup\Installed " & _
      "Components\{E92B03AB-B707-11d2-9CBD-0000F87A369E}\Version")

    If strAdsiVer = vbEmpty Then
        strAdsiVer = _
          objShell.RegRead("HKLM\SOFTWARE\Microsoft\ADs\Providers\LDAP")
        If strAdsiVer = vbEmpty Then
            strAdsiVer = "ADSI is not installed."
        Else
            strAdsiVer = "2.0"
        End If
    ElseIf Left(strAdsiVer, 3) = "5,0" Then
      If intOSVer = 5 Then
          strAdsiVer = "5.0.2195"
      ElseIf intOSVer = 6 Then
          strAdsiVer = "5.1.2600"
      ElseIf intOSVer = 7 Then
          strAdsiVer = "5.2.3790"
        Else
            strAdsiVer = "?.?"
      End If
    End If

    WScript.Echo "ADSI Version & Build: " & strAdsiVer & VbCrLf

    If strAdsiVer <> "ADSI is not installed." Then
        Set colProvider = GetObject("ADs:")
        Wscript.Echo "ADSI Providers" & VbCrLf & _
                 "--------------"
        For Each objProvider In colProvider
            Wscript.Echo objProvider.Name
        Next
        Wscript.Echo
   End If

   intAdsiVer = CInt(Left(strAdsiVer, 1))

    If (intOSVer = 7 And intAdsiVer >= 5) Or _
      (intOSVer = 6 And intAdsiVer >= 5) Or _
      (intOSVer = 5 And intAdsiVer >= 5) Or _
      (intOSVer = 4 And intAdsiVer >= 2) Or _
      (intOSVer <= 3 And intAdsiVer >= 2) _
      Then
        GetADSIVer = True
    Else
        GetADSIVer = False
    End If

End Function

'******************************************************************************
'* Test for current versions and display results.
'******************************************************************************

Sub ListUpToDate(blnWSHUpToDate, blnWMIUpToDate, blnADSIUpToDate)

    Wscript.Echo "Current Versions" & vbCrLf & _
                 "================"

    If blnWSHUpToDate Then
        WScript.Echo "WSH version:  most recent for OS version."
    Else
        WScript.Echo "WSH version:  not most recent for OS version."
        If intOSVer = 0 Then
            WScript.Echo "Windows Script not available for this OS"
        Else
            WScript.Echo "Get Windows Script 5.6, Build 8515"
        End If
    End If

    If blnWMIUpToDate Then
        WScript.Echo "WMI version:  most recent for OS version."
    Else
        WScript.Echo "WMI version:  not most recent for OS version."
        If intOSVer = 0 Then
            WScript.Echo "WMI not available for this OS"
        ElseIf intOSVer >= 1 And intOSVer <= 4 Then
            WScript.Echo "Get WMI CORE 1.5"
        Else
        End If
    End If

    If blnADSIUpToDate Then
        WScript.Echo "ADSI version: most recent for OS version."
    Else
        WScript.Echo "ADSI version: not most recent for OS version."
        If intOSVer = 0 Then
            WScript.Echo "ADSI not available for this OS"
        ElseIf intOSVer >= 1 And intOSVer <= 4 Then
            WScript.Echo "Get Active Directory Client Extensions"
        Else
        End If
    End If

End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Administrative Tools

Description
Uses the Shell object to enumerate all the Administrative Tools installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADMINISTRATIVE_TOOLS = &H2f&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(ADMINISTRATIVE_TOOLS)
Set objTools = objFolder.Items
For i = 0 to objTools.Count - 1
    Wscript.Echo objTools.Item(i)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Desktop Settings

Description
Enumerates the current desktop settings for a computer.

For more information about the Win32_Desktop class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Desktop")
For Each objItem in colItems
    Wscript.Echo "Border Width: " & objItem.BorderWidth
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Cool Switch: " & objItem.CoolSwitch
    Wscript.Echo "Cursor Blink Rate: " & objItem.CursorBlinkRate
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Drag Full Windows: " & objItem.DragFullWindows
    Wscript.Echo "Grid Granularity: " & objItem.GridGranularity
    Wscript.Echo "Icon Spacing: " & objItem.IconSpacing
    Wscript.Echo "Icon Title Face Name: " & objItem.IconTitleFaceName
    Wscript.Echo "Icon Title Size: " & objItem.IconTitleSize
    Wscript.Echo "Icon Title Wrap: " & objItem.IconTitleWrap
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Pattern: " & objItem.Pattern
    Wscript.Echo "Screen Saver Active: " & objItem.ScreenSaverActive
    Wscript.Echo "Screen Saver Executable: " & _
        objItem.ScreenSaverExecutable
    Wscript.Echo "Screen Saver Secure: " & objItem.ScreenSaverSecure
    Wscript.Echo "Screen Saver imeout: " & objItem.ScreenSaverTimeout
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Wallpaper: " & objItem.Wallpaper
    Wscript.Echo "Wallpaper Stretched: " & objItem.WallpaperStretched
    Wscript.Echo "Wallpaper Tiled: " & objItem.WallpaperTiled
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Special Folders

Description
Uses the Shell object to return the path to the My Pictures folder.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const MY_PICTURES = &H27&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_PICTURES)
Set objFolderItem = objFolder.Self
Wscript.Echo objFolderItem.Name & ": " & objFolderItem.Path

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Start Menu Items

Description
Returns a list of all the Start menu items found on a computer.

For more information about the Win32_LogicalProgramGroupItem class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalProgramGroupItem")

For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Start Menu Program Groups

Description
Retrieves information about all the Start menu program groups currently in use on a computer.

For more information about the Win32_ProgramGroup class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ProgramGroup")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Group Name: " & objItem.GroupName
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "User Name: " & objItem.UserName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming the My Computer Icon on the Local Computer

Description
Renames the My Computer icon on the local computer, giving it the same name as the computer itself.

For more information about the Shell object used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const MY_COMPUTER = &H11&
Set objNetwork = CreateObject("Wscript.Network")
objComputerName = objNetwork.ComputerName
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
objFolderItem.Name = objComputerName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using WMI to Enumerate Environment Variables on a Computer

Description
Uses WMI to return information about all the environment variables on a computer.

For more information about the Win32_Environment class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Environment")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "System Variable: " & objItem.SystemVariable
    Wscript.Echo "User Name: " & objItem.UserName
    Wscript.Echo "Variable Value: " & objItem.VariableValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using WMI to Enumerate Shortcuts on a Computer

Description
Uses WMI to return a list of all the shortcuts on a computer, as well as such properties as the file name, creation date, and target.

For more information about the Win32_ShortcutFile class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShortcutFile")
For Each objItem in colItems

    strCreationDate = WMIDateStringToDate(objItem.CreationDate)
    Wscript.Echo "Creation Date: " & strCreationDate
    Wscript.Echo "Drive: " & objItem.Drive
    Wscript.Echo "Eight Dot Three File Name: " & _
        objItem.EightDotThreeFileName
    Wscript.Echo "Extension: " & objItem.Extension
    Wscript.Echo "File Name: " & objItem.FileName
    Wscript.Echo "File Size: " & objItem.FileSize
    Wscript.Echo "File Type: " & objItem.FileType
    Wscript.Echo "File System Name: " & objItem.FSName
    Wscript.Echo "Hidden: " & objItem.Hidden
    strLastAccessed = WMIDateStringToDate(objItem.LastAccessed)
    Wscript.Echo "Last Accessed: " & strLastAccessed
    strLastModified = WMIDateStringToDate(objItem.LastModified)
    Wscript.Echo "Last Modified: " & strLastModified
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Path: " & objItem.Path
    Wscript.Echo "Target: " & objItem.Target
Next

Function WMIDateStringToDate(dtmDate)
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
         Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
         & " " & Mid (dtmDate, 9, 2) & ":" & _
         Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
         13, 2))
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Internet Explorer LAN Settings

Description
Returns network information (including proxy server information) for Internet Explorer.

At this point in time, the MicrosoftIE_LANSettings class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_LANSettings")
For Each strIESetting in colIESettings
    Wscript.Echo "Autoconfiguration proxy: " & strIESetting.AutoConfigProxy
    Wscript.Echo "Autoconfiguration URL: " & strIESetting.AutoConfigURL
    Wscript.Echo "Autoconfiguration Proxy detection mode: " & _
        strIESetting.AutoProxyDetectMode
    Wscript.Echo "Proxy: " & strIESetting.Proxy
    Wscript.Echo "Proxy override: " & strIESetting.ProxyOverride
    Wscript.Echo "Proxy server: " & strIESetting.ProxyServer
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Internet Explorer Security Zone Settings

Description
Retrieves the current setting level for each Internet Explorer security zone.

At this point in time, the MicrosoftIE_Security class used in this script has not been publicly documented.

Requirements
On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Security")
For Each strIESetting in colIESettings
    Wscript.Echo "Zone name: " & strIESetting.Zone
    Wscript.Echo "Security level: " & strIESetting.Level
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Internet Explorer Summary Settings

Description
Returns basic information (including version number and build number) for Internet Explorer.

At this point in time, the MicrosoftIE_Summary class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Summary")
For Each strIESetting in colIESettings
    Wscript.Echo "Active printer: " & strIESetting.ActivePrinter
    Wscript.Echo "Build: " & strIESetting.Build
    Wscript.Echo "Cipher strength: " & strIESetting.CipherStrength
    Wscript.Echo "Content advisor: " & strIESetting.ContentAdvisor
    Wscript.Echo "IE Administration Kit installed: " & _
        strIESetting.IEAKInstall
    Wscript.Echo "Language: " & strIESetting.Language
    Wscript.Echo "Name: " & strIESetting.Name
    Wscript.Echo "Path: " & strIESetting.Path
    Wscript.Echo "Product ID: " & strIESetting.ProductID
    Wscript.Echo "Version: " & strIESetting.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Internet Explorer Cache Settings

Description
Returns configuration settings for the Internet Explorer cache.

At this point in time, the MicrosoftIE_Cache class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Cache")
For Each strIESetting in colIESettings
    Wscript.Echo "Page refresh type: " & strIESetting.PageRefreshType
    Wscript.Echo "Temporary Internet files folder: " & _
        strIESetting.TempInternetFilesFolder
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Internet Explorer COM Object Settings

Description
Returns basic COM class information for Internet Explorer.

At this point in time, the MicrosoftIE_Object class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_Object")
For Each strIESetting in colIESettings
    Wscript.Echo "Code base: " & strIESetting.CodeBase
    Wscript.Echo "Program file: " & strIESetting.ProgramFile
    Wscript.Echo "Status: " & strIESetting.Status
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Internet Explorer Connection Settings

Description
Returns information about Internet Explorer connection settings.

At this point in time, the MicrosoftIE_ConnectionSettings class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_ConnectionSettings")
For Each strIESetting in colIESettings
    Wscript.Echo "Allow Internet programs: " & _
        strIESetting.AllowInternetPrograms
    Wscript.Echo "Autoconfiguration URL: " & strIESetting.AutoConfigURL
    Wscript.Echo "Auto disconnect: " & strIESetting.AutoDisconnect
    Wscript.Echo "Autoconfiguration proxy detection mode: " & _
        strIESetting.AutoProxyDetectMode
    Wscript.Echo "Data encryption: " & strIESetting.DataEncryption
    Wscript.Echo "Default: " & strIESetting.Default
    Wscript.Echo "Default gateway: " & strIESetting.DefaultGateway
    Wscript.Echo "Dialup server: " & strIESetting.DialUpServer
    Wscript.Echo "Disconnect idle time: " & strIESetting.DisconnectIdleTime
    Wscript.Echo "Encrypted password: " & strIESetting.EncryptedPassword
    Wscript.Echo "IP address: " & strIESetting.IPAddress
    Wscript.Echo "IP header compression: " & _
        strIESetting.IPHeaderCompression
    Wscript.Echo "Modem: " & strIESetting.Modem
    Wscript.Echo "Name: " & strIESetting.Name
    Wscript.Echo "Network logon: " & strIESetting.NetworkLogon
    Wscript.Echo "Network protocols: " & strIESetting.NetworkProtocols
    Wscript.Echo "Primary DNS server: " & strIESetting.PrimaryDNS
    Wscript.Echo "Primary WINS server: " & strIESetting.PrimaryWINS
    Wscript.Echo "Proxy: " & strIESetting.Proxy
    Wscript.Echo "Proxy override: " & strIESetting.ProxyOverride
    Wscript.Echo "Proxy server: " & strIESetting.ProxyServer
    Wscript.Echo "Redial attempts: " & strIESetting.RedialAttempts
    Wscript.Echo "Redial wait: " & strIESetting.RedialWait
    Wscript.Echo "Script fileame: " & strIESetting.ScriptFileName
    Wscript.Echo "Secondary DNS server: " & strIESetting.SecondaryDNS
    Wscript.Echo "Secondary WINS server: " & strIESetting.SecondaryWINS
    Wscript.Echo "Server assigned IP address: " & _
        strIESetting.ServerAssignedIPAddress
    Wscript.Echo "Server assigned name server: " & _
        strIESetting.ServerAssignedNameServer
    Wscript.Echo "Software compression: " & strIESetting.SoftwareCompression
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Internet Explorer File Version Information

Description
Returns basic file version information for Internet Explorer.

At this point in time, the MicrosoftIE_FileVersion class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_FileVersion")
For Each strIESetting in colIESettings
    Wscript.Echo "Company: " & strIESetting.Company
    Wscript.Echo "Date: " & strIESetting.Date
    Wscript.Echo "File name: " & strIESetting.File
    Wscript.Echo "Path: " & strIESetting.Path
    Wscript.Echo "File size: " & strIESetting.Size
    Wscript.Echo "Version: " & strIESetting.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Internet Explorer Connection Summary

Description
Returns basic connection information (including whether HTTP 1.1 has been enabled) for Internet Explorer.

At this point in time, the MicrosoftIE_ConnectionSummary class used in this script has not been publicly documented.

Requirements

On Windows 2000 and Windows NT 4.0, you must have Internet Explorer version 5.5 or later installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Internet Explorer version 5.5. or later installed
Windows NT 4.0 | Yes, with WMI and Internet Explorer version 5.5. or later installed
Windows 98 | Yes, with WMI and Internet Explorer version 5.5. or later installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2\Applications\MicrosoftIE")
Set colIESettings = objWMIService.ExecQuery _
    ("Select * from MicrosoftIE_ConnectionSummary")
For Each strIESetting in colIESettings
    Wscript.Echo "Connection preference: " & _
        strIESetting.ConnectionPreference
    Wscript.Echo "HTTP 1.1. enabled: " & strIESetting.EnableHTTP11
    Wscript.Echo "Proxy HTTP 1.1. enabled: " & strIESetting.ProxyHTTP11
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Installed Hot Fixes

Description
Returns a list of all the hot fixes installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery _
    ("Select * from Win32_QuickFixEngineering")
For Each objQuickFix in colQuickFixes
    Wscript.Echo "Computer: " & objQuickFix.CSName
    Wscript.Echo "Description: " & objQuickFix.Description
    Wscript.Echo "Hot Fix ID: " & objQuickFix.HotFixID
    Wscript.Echo "Installation Date: " & objQuickFix.InstallDate
    Wscript.Echo "Installed By: " & objQuickFix.InstalledBy
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the Latest Installed Service Pack

Description
Returns the last service pack to be installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.ServicePackMajorVersion  _
        & "." & objOperatingSystem.ServicePackMinorVersion
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the Operating System

Description
Returns the name and version number of the operating system installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo objOperatingSystem.Caption & " " & _
        objOperatingSystem.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Operating System Properties

Description
Retrieves information about the operating system installed on a computer, including language, encryption level, and build number.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed, and except for the EncryptionLevel property
Windows 98 | Yes, with WMI installed, and except for the EncryptionLevel property

Script Code

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    Wscript.Echo "Boot Device: " & objOperatingSystem.BootDevice
    Wscript.Echo "Build Number: " & objOperatingSystem.BuildNumber
    Wscript.Echo "Build Type: " & objOperatingSystem.BuildType
    Wscript.Echo "Caption: " & objOperatingSystem.Caption
    Wscript.Echo "Code Set: " & objOperatingSystem.CodeSet
    Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode
    Wscript.Echo "Debug: " & objOperatingSystem.Debug
    Wscript.Echo "Encryption Level: " & objOperatingSystem.EncryptionLevel
    dtmConvertedDate.Value = objOperatingSystem.InstallDate
    dtmInstallDate = dtmConvertedDate.GetVarDate
    Wscript.Echo "Install Date: " & dtmInstallDate
    Wscript.Echo "Licensed Users: " & _
        objOperatingSystem.NumberOfLicensedUsers
    Wscript.Echo "Organization: " & objOperatingSystem.Organization
    Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage
    Wscript.Echo "OS Product Suite: " & objOperatingSystem.OSProductSuite
    Wscript.Echo "OS Type: " & objOperatingSystem.OSType
    Wscript.Echo "Primary: " & objOperatingSystem.Primary
    Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser
    Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber
    Wscript.Echo "Version: " & objOperatingSystem.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Administrative Template Files

Description
Returns information about the administrative template files (.ADM files) used in applying Group Policy to a computer. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_AdministrativeTemplateFile class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_AdministrativeTemplateFile")
For Each objItem in colItems
    Wscript.Echo "GPO ID: " & objItem.GPOID
    dtmConvertedDate.Value = objItem.LastWriteTime
    dtmCreationTime = dtmConvertedDate.GetVarDate
    Wscript.Echo "Last Write Time: " & dtmCreationTime
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating RSOP Application Management Policy Settings

Description
Returns information about application management extension policies assigned to a computer by using Group Policy. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_ApplicationManagementPolicySetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_ApplicationManagementPolicySetting")
For Each objItem in colItems
    Wscript.Echo "Allow X86 on IA64: " & objItem.AllowX86OnIA64
    Wscript.Echo "Application ID: " & objItem.ApplicationId
    Wscript.Echo "Apply Cause: " & objItem.ApplyCause
    Wscript.Echo "Assignment Type: " & objItem.AssignmentType
    Wscript.Echo "Categories: " & objItem.Categories
    Wscript.Echo "Demand Installable: " & objItem.DemandInstallable
    Wscript.Echo "Deployment Last Modify Time: " & _
        objItem.DeploymentLastModifyTime
    Wscript.Echo "Deployment Type: " & objItem.DeploymentType
    Wscript.Echo "Display in Add/Remove Programs: " & objItem.DisplayInARP
    Wscript.Echo "Eligibility: " & objItem.Eligibility
    Wscript.Echo "Entry Type: " & objItem.EntryType
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Ignore Language: " & objItem.IgnoreLanguage
    Wscript.Echo "Installation UI: " & objItem.InstallationUI
    Wscript.Echo "Language ID: " & objItem.LanguageId
    Wscript.Echo "Language Match: " & objItem.LanguageMatch
    Wscript.Echo "Loss of Scope Action: " & objItem.LossOfScopeAction
    For Each strArchitecture in objItem.MachineArchitectures
        Wscript.Echo "Machine Architecture: " & strArchitecture
    Next
    Wscript.Echo "On-demand CLSID: " & objItem.OnDemandClsid
    Wscript.Echo "On-demand File Extension: " & objItem.OnDemandFileExtension
    Wscript.Echo "On-demand ProgID: " & objItem.OnDemandProgId
    Wscript.Echo "Package Location: " & objItem.PackageLocation
    Wscript.Echo "Package Type: " & objItem.PackageType
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "Precedence Reason: " & objItem.PrecedenceReason
    Wscript.Echo "Product ID: " & objItem.ProductId
    Wscript.Echo "Publisher: " & objItem.Publisher
    Wscript.Echo "Redeploy Count: " & objItem.RedeployCount
    Wscript.Echo "Removal Cause: " & objItem.RemovalCause
    Wscript.Echo "Removal Type: " & objItem.RemovalType
    Wscript.Echo "Removing Application: " & objItem.RemovingApplication
    Wscript.Echo "Replaceable Applications: " & objItem.ReplaceableApplications
    Wscript.Echo "Script File: " & objItem.ScriptFile
    Wscript.Echo "Support URL: " & objItem.SupportURL
    Wscript.Echo "Transforms: " & objItem.Transforms
    Wscript.Echo "Uninstall Unmanaged: " & objItem.UninstallUnmanaged
    Wscript.Echo "Upgradeable Applications: " & _
        objItem.UpgradeableApplications
    Wscript.Echo "Upgrade Settings Mandatory: " & _
        objItem.UpgradeSettingsMandatory
    Wscript.Echo "Version Number (High): " & objItem.VersionNumberHi
    Wscript.Echo "Version Number (Low): " & objItem.VersionNumberLo
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Audit Policies

Description
Returns information about auditing privileges assigned by using Group Policy.

For more information about the RSOP_AuditPolicy class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_AuditPolicy")
For Each objItem in colItems
    Wscript.Echo "Category: " & objItem.Category
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "Failure: " & objItem.Failure
    Wscript.Echo "Success: " & objItem.Success
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy GPOs

Description
Returns information about Group Policy Objects used in applying Group Policy to a computer. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_GPO class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPO")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "GUID Name: " & objItem.GUIDName
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Access Denied: " & objItem.AccessDenied
    Wscript.Echo "Enabled: " & objItem.Enabled
    Wscript.Echo "File System path: " & objItem.FileSystemPath
    Wscript.Echo "Filter Allowed: " & objItem.FilterAllowed
    Wscript.Echo "Filter ID: " & objItem.FilterId
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Group Policy Extension Status

Description
Returns information about client-side processing of Group Policy extensions. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_ExtensionStatus class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_ExtensionStatus")
For Each objItem in colItems
    Wscript.Echo ": " & objItem.DisplayName
    dtmConvertedDate.Value = objItem.BeginTime
    dtmTime = dtmConvertedDate.GetVarDate
    Wscript.Echo "Begin time: " & dtmTime
    dtmConvertedDate.Value = objItem.EndTime
    dtmTime = dtmConvertedDate.GetVarDate
    Wscript.Echo "End time: " & dtmTime
    Wscript.Echo "Error: " & objItem.Error
    Wscript.Echo "Extension GUID: " & objItem.ExtensionGuid
    Wscript.Echo "Logging Status: " & objItem.LoggingStatus
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Group Policy Links

Description
Returns information about Group Policy links used in applying Group Policy to a computer. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_GPLink class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPLink")
For Each objItem in colItems
    Wscript.Echo "GPO: " & objItem.GPO
    Wscript.Echo "Applied Order: " & objItem.AppliedOrder
    Wscript.Echo "Enabled: " & objItem.Enabled
    Wscript.Echo "Link Order: " & objItem.LinkOrder
    Wscript.Echo "No Overrride: " & objItem.NoOverride
    Wscript.Echo "SOM Order: " & objItem.SOMOrder
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Policy Settings

Description
Returns information about policy object setttings used in applying Group Policy to a computer. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_PolicySetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_PolicySetting")
For Each objItem in colItems
    Wscript.Echo "GPO ID: " & objItem.GPOID
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "SOM ID: " & objItem.SOMID
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Security Event Log Settings (Boolean)

Description
Returns information about access to event logs assigned by using Group Policy.

For more information about the RSOP_SecurityEventLogSettingBoolean class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_SecurityEventLogSettingBoolean")
For Each objItem in colItems
    Wscript.Echo "Key Name: " & objItem.KeyName
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "Setting: " & objItem.Setting
    Wscript.Echo "Type: " & objItem.Type
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Security Settings (Boolean)

Description
Returns information about account policy settings (such as password policy settings and account lockout policy settings) assigned by using Group Policy.

For more information about the RSOP_SecuritySettingBoolean class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_SecuritySettingBoolean")
For Each objItem in colItems
    Wscript.Echo "Key Name: " & objItem.KeyName
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "Setting: " & objItem.Setting
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Security Event Log Settings (Numeric)

Description
Returns information about event log settings (such as maximum log size) assigned by using Group Policy.

For more information about the RSOP_SecurityEventLogSettingNumeric class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_SecurityEventLogSettingNumeric")
For Each objItem in colItems
    Wscript.Echo "Key Name: " & objItem.KeyName
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "Setting: " & objItem.Setting
    Wscript.Echo "Type: " & objItem.Type
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Security Settings (Numeric)

Description
Returns information about account policy settings assigned by using Group Policy.

For more information about the RSOP_SecuritySettingNumeric class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery _
    ("Select * from RSOP_SecuritySettingNumeric")
For Each objItem in colItems
    Wscript.Echo "Key Name: " & objItem.KeyName
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "Setting: " & objItem.Setting
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy Scopes of Management

Description
Returns information about the Scope of Management (SOM) used in applying Group Policy to a computer. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_SOM class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_SOM")
For Each objItem in colItems
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Blocked: " & objItem.Blocked
    Wscript.Echo "Blocking: " & objItem.Blocking
    Wscript.Echo "Reason: " & objItem.Reason
    Wscript.Echo "SOM Order: " & objItem.SOMOrder
    Wscript.Echo "Type: " & objItem.Type
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating RSOP Sessions

Description
Returns information about the resultant set of policy session used in applying Group Policy to a computer. To return information about Group Policy applied to the logged-on user, change the WMI class from root\rsop\computer to root\rsop\user.

For more information about the RSOP_Session class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_Session")
For Each objItem in colItems
    Wscript.Echo "ID: " & objItem.ID
    dtmConvertedDate.Value = objItem.CreationTime
    dtmTime = dtmConvertedDate.GetVarDate
    Wscript.Echo "Creation Time: " & dtmTime
    Wscript.Echo "Flags: " & objItem.Flags
    For Each strSecurityGroup in objItem.SecurityGroups
        Wscript.Echo "Security group: " & strSecurityGroup
    Next
    Wscript.Echo "Site: " & objItem.Site
    Wscript.Echo "Slow Link: " & objItem.SlowLink
    Wscript.Echo "SOM: " & objItem.SOM
    Wscript.Echo "Target Name: " & objItem.TargetName
    Wscript.Echo "TTL (Minutes): " & objItem.TTLMinutes
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy System Services

Description
Returns information about the service settings (including startup mode and access permissions) assigned to a computer by using Group Policy.

For more information about the RSOP_SystemService class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_SystemService")
For Each objItem in colItems
    Wscript.Echo "Service: " & objItem.Service
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "SDDL String: " & objItem.SDDLString
    Wscript.Echo "Startup Mode: " & objItem.StartupMode
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Resultant Set of Policy User Privilege Rights

Description
Returns information about user privileges assigned by using Group Policy.

For more information about the RSOP_UserPrivilegeRight class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_UserPrivilegeRight")
For Each objItem in colItems
    For Each strAccountList in objItem.AccountList
        Wscript.Echo "Account list: " & strAccountList
    Next
    Wscript.Echo "Precedence: " & objItem.Precedence
    Wscript.Echo "User Right: " & objItem.UserRight
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Shadow Copy

Description
Creates a client-accessible shadow copy of drive C.

For more information about the Create method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const VOLUME = "C:\"
Const CONTEXT = "ClientAccessible"

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShadowStorage = objWMIService.Get("Win32_ShadowCopy")
errResult = objShadowStorage.Create(VOLUME, CONTEXT, strShadowID)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Shadow Copy Storage Area

Description
Creates a shadow copy storage area -- on drive E -- for storing shadow copies of drive C. This script reserves 130,023,424 bytes of storage space for the shadow copies.

For more information about the Create method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const VOLUME = "C:\"
Const DIFFERENTIAL_VOLUME = "E:\"
Const MAXIMUM_SPACE = 130023424

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objShadowStorage = objWMIService.Get("Win32_ShadowStorage")
errResult = objShadowStorage.Create(VOLUME, DIFFERENTIAL_VOLUME, MAXIMUM_SPACE)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting All Shadow Copies on a Computer

Description
Deletes all the shadow copies stored on a server.

For more information about the Win32_ShadowCopy class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_ShadowCopy")
For Each objItem in colItems
    objItem.Delete_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting All Shadow Copy Storage Areas

Description
Deletes all the shadow copy storage areas on a computer.

For more information about the Win32_ShadowStorage class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_ShadowStorage")
For Each objItem in colItems
    objItem.Delete_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All Shadow Copies on a Computer

Description
Enumerates the properties of all the shadow copies stored on a server.

For more information about the Win32_ShadowCopy class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowCopy")
For Each objItem in colItems
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Client accessible: " & objItem.ClientAccessible
    Wscript.Echo "Count: " & objItem.Count
    Wscript.Echo "Device object: " & objItem.DeviceObject
    Wscript.Echo "Differnetial: " & objItem.Differential
    Wscript.Echo "Exposed locally: " & objItem.ExposedLocally
    Wscript.Echo "Exposed name: " & objItem.ExposedName
    Wscript.Echo "Exposed remotely: " & objItem.ExposedRemotely
    Wscript.Echo "Hardware assisted: " & objItem.HardwareAssisted
    Wscript.Echo "Imported: " & objItem.Imported
    Wscript.Echo "No auto release: " & objItem.NoAutoRelease
    Wscript.Echo "Not surfaced: " & objItem.NotSurfaced
    Wscript.Echo "No writers: " & objItem.NoWriters
    Wscript.Echo "Originating machine: " & objItem.OriginatingMachine
    Wscript.Echo "Persistent: " & objItem.Persistent
    Wscript.Echo "Plex: " & objItem.Plex
    Wscript.Echo "Provider ID: " & objItem.ProviderID
    Wscript.Echo "Service machine: " & objItem.ServiceMachine
    Wscript.Echo "Set ID: " & objItem.SetID
    Wscript.Echo "State: " & objItem.State
    Wscript.Echo "Transportable: " & objItem.Transportable
    Wscript.Echo "Volume name: " & objItem.VolumeName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All Shadow Copy Storage Areas on a Computer

Description
Retrieves a list of all the shadow copy storage areas on a computer, as well as the properties of each storage area.

For more information about the Win32_ShadowStorage class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowStorage")
For Each objItem in colItems
    Wscript.Echo "Volume: " & objItem.Volume
    Wscript.Echo "Allocated space: " & objItem.AllocatedSpace
    Wscript.Echo "Differential volume: " & objItem.DiffVolume
    Wscript.Echo "Maximum space: " & objItem.MaxSpace
    Wscript.Echo "Used space: " & objItem.UsedSpace
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Shadow Copy Providers

Description
Returns the properties of all the shadow copy providers installed on a computer. For most computers, there will be only the default shadow copy provider included with the operating system.

For more information about the Win32_ShadowProvider class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowProvider")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "CLSID: " & objItem.CLSID
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Type: " & objItem.Type
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo "Version ID: " & objItem.VersionID
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying a Shadow Copy Storage Area

Description
Modifies all the shadow copy storage areas on a computer, setting the maximum amount of reserved space to 500,000,000 bytes.

For more information about the Win32_ShadowStorage class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowStorage")
For Each objItem in colItems
    objItem.MaxSpace = 500000000
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Shadow Copy Settings

Description
Retrieves the shadow copy settings configured on a computer.

For more information about the Win32_ShadowContext class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ShadowContext")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Client accessible: " & objItem.ClientAccessible
    Wscript.Echo "Differential: " & objItem.Differential
    Wscript.Echo "Exposed locally: " & objItem.ExposedLocally
    Wscript.Echo "Exposed remotely: " & objItem.ExposedRemotely
    Wscript.Echo "Hardware assisted: " & objItem.HardwareAssisted
    Wscript.Echo "Imported: " & objItem.Imported
    Wscript.Echo "No auto release: " & objItem.NoAutoRelease
    Wscript.Echo "Not surfaced: " & objItem.NotSurfaced
    Wscript.Echo "No writers: " & objItem.NoWriters
    Wscript.Echo "Persistent: " & objItem.Persistent
    Wscript.Echo "Plex: " & objItem.Plex
    Wscript.Echo "Transportable: " & objItem.Transportable
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Classic COM Class Settings

Description
Returns configuration information for the “classic” COM classes installed on a computer.

For more information about the win32_ClassicCOMClassSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_ClassicCOMClassSetting")
For Each objItem in colItems
    Wscript.Echo "Application ID: " & objItem.AppID
    Wscript.Echo "Component ID: " & objItem.ComponentId
    Wscript.Echo "Control: " & objItem.Control
    Wscript.Echo "Default Icon: " & objItem.DefaultIcon
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Inprocess Server 32: " & objItem.InprocServer32
    Wscript.Echo "Insertable: " & objItem.Insertable
    Wscript.Echo "Java Class: " & objItem.JavaClass
    Wscript.Echo "ProgId: " & objItem.ProgId
    Wscript.Echo "Version Independent ProgId: " & _
        objItem.VersionIndependentProgId
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Classic COM Classes

Description
Retrieves information about all the “classic” COM classes installed on a computer.

For more information about the Win32_ClassicCOMClass used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ClassicCOMClass")
For Each objItem in colItems
    Wscript.Echo "Component ID: " & objItem.ComponentId
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Component Categories

Description
Retrieves information about the COM class component categories (COM classes that share common functionalities) found on a computer.

For more information about the Win32_ComponentCategory class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComponentCategory")
For Each objItem in colItems
    Wscript.Echo "Category ID: " & objItem.CategoryId
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating DCOM Applications

Description
Returns information about all the DCOM (distributed COM) applications installed on a computer.

For more information about the Win32_DCOMAPplication class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DCOMApplication")
For Each objItem in colItems
    Wscript.Echo "Application ID: " & objItem.AppID
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating DCOM Application Settings

Description
Returns information about the configuration of each DCOM (distributed COM) application installed on a computer.

For more information about the Win32_DCOMApplicationSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_DCOMApplicationSetting")
For Each objItem in colItems
    Wscript.Echo "Application ID: " & objItem.AppID
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Enable At Storage Activation: " & _
        objItem.EnableAtStorageActivation
    Wscript.Echo "Local Service: " & objItem.LocalService
    Wscript.Echo "Service Parameters: " & objItem.ServiceParameters
    Wscript.Echo "Use Surrogate: " & objItem.UseSurrogate
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Installed or Advertised Components and Applications

Description
Returns a list of all Windows Installer components installed or advertised on a computer.

For more information about the Win32_ApplicationService class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes, with the WMI Windows Installer Provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ApplicationService")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Start Mode: " & objItem.StartMode
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Installed Software

Description
Returns a list of software that was installed on a computer using Windows Installer.

Supported Platforms

Windows Server 2003 | Yes, with the WMI Windows Installer provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile("c:\scripts\software.tsv", True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & _
    "Description" & vbtab & "Identifying Number" & vbtab & _
    "Install Date" & vbtab & "Install Location" & vbtab & _
    "Install State" & vbtab & "Name" & vbtab & _
    "Package Cache" & vbtab & "SKU Number" & vbtab & "Vendor" & vbtab _
        & "Version"
For Each objSoftware in colSoftware
    objTextFile.WriteLine objSoftware.Caption & vbtab & _
    objSoftware.Description & vbtab & _
    objSoftware.IdentifyingNumber & vbtab & _
    objSoftware.InstallDate2 & vbtab & _
    objSoftware.InstallLocation & vbtab & _
    objSoftware.InstallState & vbtab & _
    objSoftware.Name & vbtab & _
    objSoftware.PackageCache & vbtab & _
    objSoftware.SKUNumber & vbtab & _
    objSoftware.Vendor & vbtab & _
    objSoftware.Version
Next
objTextFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Installed Software Features

Description
Returns a list of features for all the software that was installed on a computer using Windows Installer.

Supported Platforms

Windows Server 2003 | Yes, with the WMI Windows Installer provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFeatures = objWMIService.ExecQuery _
    ("Select * from Win32_SoftwareFeature")
For each objFeature in colfeatures
    Wscript.Echo "Accesses: " & objFeature.Accesses
    Wscript.Echo "Attributes: " & objFeature.Attributes
    Wscript.Echo "Caption: " & objFeature.Caption
    Wscript.Echo "Description: " & objFeature.Description
    Wscript.Echo "Identifying Number: " & objFeature.IdentifyingNumber
    Wscript.Echo "Install Date: " & objFeature.InstallDate
    Wscript.Echo "Install State: " & objFeature.InstallState
    Wscript.Echo "LastUse: " & objFeature.LastUse
    Wscript.Echo "Name: " & objFeature.Name
    Wscript.Echo "ProductName: " & objFeature.ProductName
    Wscript.Echo "Vendor: " & objFeature.Vendor
    Wscript.Echo "Version: " & objFeature.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating ProgIDs

Description
Returns a list of ProgIDs (Programmatic Identifiers) found on a computer.

For more information about the Win32_ProgIDSpecification class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ProgIDSpecification")
For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Check ID: " & objItem.CheckID
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Parent: " & objItem.Parent
    Wscript.Echo "ProgID: " & objItem.ProgID
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Codec Files on a Computer

Description
Uses WMI to return information about all the audio and video codec files installed on a computer.

For more information about the Win32_CodecFile class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CodecFile",,48)
For Each objItem in colItems
    Wscript.Echo "Access Mask: " & objItem.AccessMask
    Wscript.Echo "Archive: " & objItem.Archive
    Wscript.Echo "Caption: " & objItem.Caption
    strCreationDate = WMIDateStringToDate(objItem.CreationDate)
    Wscript.Echo "Creation Date: " & strCreationdate
    Wscript.Echo "Drive: " & objItem.Drive
    Wscript.Echo "Eight Dot Three File Name: " & _
        objItem.EightDotThreeFileName
    Wscript.Echo "Extension: " & objItem.Extension
    Wscript.Echo "File Name: " & objItem.FileName
    Wscript.Echo "File Size: " & objItem.FileSize
    Wscript.Echo "File Type: " & objItem.FileType
    Wscript.Echo "File System Name: " & objItem.FSName
    Wscript.Echo "Group: " & objItem.Group
    Wscript.Echo "Hidden: " & objItem.Hidden
    strInstallDate = WMIDateStringToDate(objItem.InstallDate)
    Wscript.Echo "Last Accessed: " & strLastAccessed
    strLastModified = WMIDateStringToDate(objItem.LastModified)
    Wscript.Echo "Last Modified: " & strLastModified
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Path: " & objItem.Path
    Wscript.Echo "Version: " & objItem.Version
Next

Function WMIDateStringToDate(dtmDate)
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
         Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
         & " " & Mid (dtmDate, 9, 2) & ":" & _
         Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
         13, 2))
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing Software on a Remote Computer

Description
Installs a hypothetical software program (using a Windows Installer package) on a remote computer. Requires delegation for the computer and user accounts involved in the procedure.

Supported Platforms

Windows Server 2003 | Yes, with the Windows Installer WMI provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const wbemImpersonationLevelDelegate = 4
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer _
    ("WebServer", "root\cimv2", "fabrikam\administrator", _
     "password", , "kerberos:WebServer")
objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate
Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install("\\atl-dc-02\scripts\1561_lab.msi",,True)
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing Software on the Local Computer

Description
Installs a hypothetical software program (using a Windows Installer package) on a local computer.

Supported Platforms

Windows Server 2003 | Yes, with the Windows Installer WMI provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("c:\scripts\database.msi", , ALL_USERS)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing Software

Description
Uninstalls a hypothetical software program that was installed using Windows Installer.

Supported Platforms

Windows Server 2003 | Yes, with the WMI Windows Installer provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32_Product Where Name = 'Personnel database'")
For Each objSoftware in colSoftware
    objSoftware.Uninstall()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Information About Binary Files Used by an Application

Description
Returns the name and product code of binary information (such as bitmaps, icons, executable files, and so on) used by a Windows Installer application.

For more information about the Win32_Binary class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes, with the WMI Windows Installer Provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Binary")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Product Code: " & objItem.ProductCode
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Upgrading Software

Description
Upgrades a hypothetical software program that was installed using Windows Installer.

Supported Platforms

Windows Server 2003 | Yes, with the WMI Windows Installer provider installed
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32__Product Where Name = 'Personnel Database'")
For Each objSoftware in colSoftware
    errReturn = objSoftware.Upgrade("c:\scripts\database2.msi")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring System Startup Delay

Description
Configures a computer to wait 10 seconds (instead of the default 30 seconds) before automatically loading the default operating system upon startup.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objStartupCommand in colStartupCommands
    objStartupCommand.SystemStartupDelay = 10
    objStartupCommand.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Computer Startup Commands

Description
Enumerates all startup commands on a computer, including those found in the Startup folder and those found in the Registry.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
    ("Select * from Win32_StartupCommand")
For Each objStartupCommand in colStartupCommands
    Wscript.Echo "Command: " & objStartupCommand.Command
    Wscript.Echo "Description: " & objStartupCommand.Description
    Wscript.Echo "Location: " & objStartupCommand.Location
    Wscript.Echo "Name: " & objStartupCommand.Name
    Wscript.Echo "SettingID: " & objStartupCommand.SettingID
    Wscript.Echo "User: " & objStartupCommand.User
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Computer Startup Options

Description
Returns a list of startup options for a computer, including the startup delay time and other information found in Boot.ini.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colStartupCommands = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objStartupCommand in colStartupCommands
    Wscript.Echo "Reset Boot Enabled: " & _
        objStartupCommand.AutomaticResetBootOption
    Wscript.Echo "Reset Boot Possible: " & _
        objStartupCommand.AutomaticResetCapability
    Wscript.Echo "Boot State: " & objStartupCommand.BootupState
    Wscript.Echo "Startup Delay: " & objStartupCommand.SystemStartupDelay
    For i = 0 to Ubound(objStartupCommand.SystemStartupOptions)
        Wscript.Echo "Startup Options: " & _
            objStartupCommand.SystemStartupOptions(i)
    Next
    Wscript.Echo "Startup Setting: " & _
        objStartupCommand.SystemStartupSetting
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Recovery Configuration Options

Description
Returns a list of settings that indicate the action to be taken by a computer should a stop event (blue screen) occur.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRecoveryOptions = objWMIService.ExecQuery _
    ("Select * from Win32_OSRecoveryConfiguration")
For Each objOption in colRecoveryOptions
    Wscript.Echo "Auto reboot: " & objOption.AutoReboot
    Wscript.Echo "Debug File Path: " & objOption.DebugFilePath
    Wscript.Echo "Debug Info Type: " & objOption.DebugInfoType
    Wscript.Echo "Kernel Dump Only: " & objOption.KernelDumpOnly
    Wscript.Echo "Name: " & objOption.Name
    Wscript.Echo "Overwrite Existing Debug File: " & _
        objOption.OverwriteExistingDebugFile
    Wscript.Echo "Send Administrative Alert: " & objOption.SendAdminAlert
    Wscript.Echo "Write Debug Information: " & objOption.WriteDebugInfo
    Wscript.Echo "Write to System Log: " & objOption.WriteToSystemLog
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Boot Configuration Properties of a Computer

Description
Returns boot configuration information for a computer.

For more information about the Win32_BootConfiguration class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BootConfiguration")
For Each objItem in colItems
    Wscript.Echo "Boot Directory: " & objItem.BootDirectory
    Wscript.Echo "Configuration Path: " & objItem.ConfigurationPath
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Last Drive: " & objItem.LastDrive
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Scratch Directory: " & objItem.ScratchDirectory
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Temp Directory: " & objItem.TempDirectory
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying Recovery Configuration Options

Description
Configures a computer to do a complete memory dump to the file C:\Scripts\memory.dmp should a stop event (blue screen) occur.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const COMPLETE_MEMORY_DUMP = 1
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRecoveryOptions = objWMIService.ExecQuery _
    ("Select * from Win32_OSRecoveryConfiguration")
For Each objOption in colRecoveryOptions
    objOption.DebugInfoType = COMPLETE_MEMORY_DUMP
    objOption.DebugFilePath = "c:\scripts\memory.dmp"
    objOption.OverWriteExistingDebugFile = False
    objOption.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Restarting a Computer

Description
Restarts a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "atl-dc-01"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
        strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Reboot()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Shutting Down the Local Computer

Description
Shuts down the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set colOperatingSystems = GetObject_
    ("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Win32Shutdown(1)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Conducting a System Restore

Description
Performs a system restore on a computer using system restore point No. 20. To perform a system restore using a different system restore point, simply change the value of the constant RESTORE_POINT.

For more information about the Restore method used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const RESTORE_POINT = 20

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Restore(RESTORE_POINT)
Wscript.Echo errResults

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a System Restore Point

Description
Creates a new system restore point on a computer, specifying that the restore point was created prior to installing a new device driver.

For more information about the CreateRestorePoint method used in this class, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

CONST DEVICE_DRIVER_INSTALL = 10
CONST BEGIN_SYSTEM_CHANGE = 100
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.CreateRestorePoint _
    ("Scripted restore", DEVICE_DRIVER_INSTALL, BEGIN_SYSTEM_CHANGE)
Wscript.Echo errResults

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling Full System Restore

Description
Disables system restore on a computer. This is equivalent to selecting the checkbox Turn off System Restore (found by right-clicking My Computer, clicking Properties, and then clicking on the System Restore tab in the resulting dialog box).

For more information about the Disable method used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Disable("")
Wscript.Echo errResults

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Full System Restore

Description
Enables system restore on a computer. This is equivalent to clearing the checkbox Turn off System Restore (found by right-clicking My Computer, clicking Properties, and then clicking on the System Restore tab in the resulting dialog box).

For more information about the Enable method used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.Enable("")
Wscript.Echo errResults

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Getting the Results of the Last System Restore

Description
Returns the results (failed, succeeded, interrupted) of the last system restore performed on a computer.

For more information about the GetLastRestoreStatus method used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestore")
errResults = objItem.GetLastRestoreStatus()

Select Case errResults
    Case 0 strRestoreStatus = "The last restore failed."
    Case 1 strRestoreStatus = "The last restore was successful."
    Case 2 strRestoreStatus = "The last restore was interrupted."
End Select

Wscript.Echo strRestoreStatus

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting System Restore Configuration Values

Description
Modifies the system restore configuration values on a computer, setting the global interval to 100,000 seconds; the life interval to 8,000,000 seconds; and the session interval to 500,000 seconds.

For more information about the SystemRestoreConfig class used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const GLOBAL_INTERVAL_IN_SECONDS = 100000
Const LIFE_INTERVAL_IN_SECONDS = 8000000
Const SESSION_INTERVAL_IN_SECONDS = 500000

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set objItem = objWMIService.Get("SystemRestoreConfig='SR'")
objItem.DiskPercent = 10
objItem.RPGlobalInterval = GLOBAL_INTERVAL_IN_SECONDS
objItem.RPLifeInterval = LIFE_INTERVAL_IN_SECONDS
objItem.RPSessionInterval = SESSION_INTERVAL_IN_SECONDS
objItem.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Viewing All Existing Restore Points

Description
Returns a list of all system restore points stored on a computer, as well as detailed information about each of those restore points.

For more information about the SystemRestore class used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set colItems = objWMIService.ExecQuery("Select * from SystemRestore")
If colItems.Count = 0 Then
    WScript.Echo "No restore point in system."
Else
    For Each objItem in colItems
        Wscript.Echo "Name: " & objItem.Description
        Wscript.Echo "Number: " & objItem.SequenceNumber
        Select Case objItem.RestorePointType
      Case 0 strRestoreType = "Application installation"
            Case 1 strRestoreType = "Application uninstall"
            Case 6 strRestoreType = "Restore"
            Case 7 strRestoreType = "Checkpoint"
            Case 10 strRestoreType = "Device drive installation"
            Case 11 strRestoreType = "First run"
            Case 12 strRestoreType = "Modify settings"
            Case 13 strRestoreType = "Cancelled operation"
            Case 14 strRestoreType = "Backup recovery"
            Case Else strRestoreType = "Unknown"
        End Select
        Wscript.Echo "Restore Point Type: " & strRestoreType

        dtmConvertedDate.Value = objItem.CreationTime
        dtmCreationTime = dtmConvertedDate.GetVarDate
        Wscript.Echo "Time: " & dtmCreationTime

    Next
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Viewing System Restore Configuration Values

Description
Displays the current system restore configuration settings on a computer.

For more information about the SystemRestoreConfig class used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\default")
Set colItems = objWMIService.ExecQuery("Select * from SystemRestoreConfig")
For Each objItem in colItems
    Wscript.Echo "Disk Percent: " & objItem.DiskPercent
    Wscript.Echo "Global Interval (in seconds): " & objItem.RPGlobalInterval
    Wscript.Echo "Life Interval (in seconds): " & objItem.RPLifeInterval
    If objItem.RPSessionInterval = 0 Then
        Wscript.Echo "Session Interval: Feature not enabled."
    Else
        Wscript.Echo "Session Interval (in seconds): " & _
            objItem.RPSessionInterval
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Activating Windows Offline

Description
Uses the offline method to activate Windows. Requires Windows XP or Windows .NET Server, and a valid activation number.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colWindowsProducts = objWMIService.ExecQuery _
    ("Select * from Win32_WindowsProductActivation")
For Each objWindowsProduct in colWindowsProducts
    ObjWindowsProduct.ActivateOffline("1234-1234")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Activating Windows Online

Description
Uses the online method to activate Windows. Requires Windows XP or Windows .NET Server, and an active Internet connection.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colWindowsProducts = objWMIService.ExecQuery _
    ("Select * from Win32_WindowsProductActivation")
For Each objWindowsProduct in colWindowsProducts
    ObjWindowsProduct.ActivateOnline()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Windows Product Activation Status

Description
Returns product activation information for a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colWPA = objWMIService.ExecQuery _
    ("Select * from Win32_WindowsProductActivation")
For Each objWPA in colWPA
    Wscript.Echo "Activation Required: " & objWPA.ActivationRequired
    Wscript.Echo "Description: " & objWPA.Description
    Wscript.Echo "Product ID: " & objWPA.ProductID
    Wscript.Echo "Remaining Evaluation Period: " & _
        objWPA.RemainingEvaluationPeriod
    Wscript.Echo "Remaining Grace Period: " & objWPA.RemainingGracePeriod
    Wscript.Echo "Server Name: " & objWPA.ServerName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Suppressing Windows Activation Notices

Description
Suppresses the Windows Activation reminder notices on a computer. This does not preclude the need to activate the computer; it simply prevents users from seeing the periodic reminders.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" & _
    "!\\" & strComputer & "\root\cimv2")
Set colWPASettings = objWMIService.ExecQuery _
    ("Select * from Win32_WindowsProductActivation")

For Each objWPASetting in colWPASettings
    objWPASetting.SetNotification(0)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Dfs Node

Description
Creates a new Dfs node for a shared folder named Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDfsNode = objWMIService.Get("Win32_DfsNode")
errReturn = objDfsNode.Create _
    ("\\atl-dc-02\Scripts","\\atl-dc-02","Scripts", _
        "New Dfs node for shared scripts.")
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Dfs Nodes

Description
Enumerates all the Dfs nodes on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDfsNodes = objWMIService.ExecQuery _
    ("Select * from Win32_DFSNode")
For each objDfsNode in colDfsNodes
    Wscript.Echo "Caption: " & vbTab &  objDfsNode.Caption
    Wscript.Echo "Description: " & vbTab &  objDfsNode.Description
    Wscript.Echo "Install Date: " & vbTab &  objDfsNode.InstallDate
    Wscript.Echo "Name: " & vbTab &  objDfsNode.Name
    Wscript.Echo "Root: " & vbTab &  objDfsNode.Root
    Wscript.Echo "State: " & vbTab &  objDfsNode.State
    Wscript.Echo "Status: " & vbTab &  objDfsNode.Status
    Wscript.Echo "Timeout: " & vbTab &  objDfsNode.Timeout
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Dfs Targets

Description
Enumerates all the Dfs targets on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDfsTargets = objWMIService.ExecQuery _
    ("Select * from Win32_DFSTarget")
For each objDfsTarget in colDfsTargets
    Wscript.Echo "Caption: " & vbTab &  objDfsTarget.Caption
    Wscript.Echo "Description: " & vbTab &  objDfsTarget.Description
    Wscript.Echo "Install Date: " & vbTab &  objDfsTarget.InstallDate
    Wscript.Echo "Link Name: " & vbTab &  objDfsTarget.LinkName
    Wscript.Echo "Name: " & vbTab &  objDfsTarget.Name
    Wscript.Echo "Server Name: " & vbTab &  objDfsTarget.ServerName
    Wscript.Echo "Share Name: " & vbTab &  objDfsTarget.ShareName
    Wscript.Echo "State: " & vbTab &  objDfsTarget.State
    Wscript.Echo "Status: " & vbTab &  objDfsTarget.Status
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Volume Mount Point

Description
Adds a new volume mount point for the folder W:\Scripts. Note that in the WQL query, you must use two forward slashes rather than one, and you must also include two forward slashes at the end of the folder path. Thus the folder X:\Scripts\WMI would be listed as X:\\Scripts\\WMI\\.

For more information about the AddMountPoint method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Volume Where Name = 'D:\\'")
For Each objItem in colItems
    objItem.AddMountPoint("W:\\Scripts\\")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Analyzing Volume Defragmentation

Description
Analyzes the defragmentation status of all the volumes on a computer. This is equivalent to running defrag.exe with the command-line options -a (analyze) and -v (verbose).

For more information about the DefragAnalysis method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objVolume in colVolumes
    errResult = objVolume.DefragAnalysis(blnRecommended, objReport)
    If errResult = 0 then
        Wscript.Echo "Average file size: " & objReport.AverageFileSize
        Wscript.Echo "Average fragments per file: " & _
            objReport.AverageFragmentsPerFile
        Wscript.Echo "Cluster size: " & objReport.ClusterSize
        Wscript.Echo "Excess folder fragments: " & _
            objReport.ExcessFolderFragments
        Wscript.Echo "File percent fragmentation: " & _
            objReport.FilePercentFragmentation
        Wscript.Echo "Fragmented folders: " & objReport.FragmentedFolders
        Wscript.Echo "Free soace: " & objReport.FreeSpace
        Wscript.Echo "Free space percent: " & objReport.FreeSpacePercent
        Wscript.Echo "Free space percent fragmentation: " & _
            objReport.FreeSpacePercentFragmentation
        Wscript.Echo "MFT percent in use: " & objReport.MFTPercentInUse
        Wscript.Echo "MFT record count: " & objReport.MFTRecordCount
        Wscript.Echo "Page file size: " & objReport.PageFileSize
        Wscript.Echo "Total excess fragments: " & _
            objReport.TotalExcessFragments
        Wscript.Echo "Total files: " & objReport.TotalFiles
        Wscript.Echo "Total folders: " & objReport.TotalFolders
        Wscript.Echo "Total fragmented files: " & _
            objReport.TotalFragmentedFiles
        Wscript.Echo "Total MFT fragments: " & objReport.TotalMFTFragments
        Wscript.Echo "Total MFT size: " & objReport.TotalMFTSize
        Wscript.Echo "Total page file fragments: " & _
            objReport.TotalPageFileFragments
        Wscript.Echo "Total percent fragmentation: " & _
            objReport.TotalPercentFragmentation
        Wscript.Echo "Used space: " & objReport.UsedSpace
        Wscript.Echo "Volume name: " & objReport.VolumeName
        Wscript.Echo "Volume size: " & objReport.VolumeSize
        If blnRecommended = True Then
           Wscript.Echo "This volume should be defragged."
        Else
           Wscript.Echo "This volume does not need to be defragged."
        End If
        Wscript.Echo
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Associating Disk Partitions with Physical Disk Drives

Description
Returns the DeviceID of all the physical disk drives installed on a computer, and indicates the partitions that have been created on those disks.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

ComputerName = "."
Set wmiServices = GetObject _
    ("winmgmts:{impersonationLevel=Impersonate}!//" & ComputerName)
Set wmiDiskDrives = wmiServices.ExecQuery _
    ("SELECT Caption, DeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives
    WScript.Echo wmiDiskDrive.Caption & " (" & wmiDiskDrive.DeviceID & ")"
    strEscapedDeviceID = _
        Replace(wmiDiskDrive.DeviceID, "\", "\\", 1, -1, vbTextCompare)
    Set wmiDiskPartitions = wmiServices.ExecQuery _
        ("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
            strEscapedDeviceID & """} WHERE " & _
                "AssocClass = Win32_DiskDriveToDiskPartition")

    For Each wmiDiskPartition In wmiDiskPartitions
        WScript.Echo vbTab & wmiDiskPartition.DeviceID
        Set wmiLogicalDisks = wmiServices.ExecQuery _
            ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                wmiDiskPartition.DeviceID & """} WHERE " & _
                    "AssocClass = Win32_LogicalDiskToPartition")

        For Each wmiLogicalDisk In wmiLogicalDisks
            WScript.Echo vbTab & vbTab & wmiLogicalDisk.DeviceID
        Next
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Binding to a Specific Disk Drive

Description
Demonstration script that uses the FileSystemObject to return available disk space on a specific disk drive. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDrive = objFSO.GetDrive("C:")
Wscript.Echo "Available space: " & objDrive.AvailableSpace

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing the Drive Letter of a Volume

Description
Changes the drive letter of volume D to Q. If you modify this script to change the drive letter of a volume other than D, note that the volume name in the WQL query must include both the colon (:) and two forward slashes (\\). Thus drive C would look like this: C:\\. When specifying the new drive letter, however, you only have to include the colon (in the sample script, Q:).

For more information about the Win32_Volume class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
    ("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
    objVolume.DriveLetter = "Q:"
    objVolume.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing Volume Names

Description
Changes the volume label for drive C to "Finance Volume."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDrives = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk where DeviceID = 'C:'")
For Each objDrive in colDrives
    objDrive.VolumeName = "Finance Volume"
    objDrive.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Defragmenting a Volume

Description
Defragments volume D on a computer. If you modify this script to defragment a different volume (such as X), note that your WQL query must specify the drive letter followed by a colon and then followed by two forward slashes. Thus volume X would be listed as X:\\.

For more information about the Defrag method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
    ("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
     errResult = objVolume.Defrag()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Dismounting a Volume

Description
Dismounts volume E from the file system. If you modify this script to dismount a different volume (such as X), note that your WQL query must specify the drive letter followed by a colon and then followed by two backslashes. Thus volume X would be listed as X:\\.

The two parameters: 1) force the volume to be dismounted, even if users are currently connected to it; and, 2) place the volume in a no-automount, offline state. This script can be modified by setting either (or both) of these parameters to False.

For more information about the Dismount method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Volume Where Name = 'E:\\'")
For Each objItem in colItems
    objItem.Dismount(True, True)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Ensuring that All Drives are Ready

Description
Demonstration script that uses the FileSystemObject to ensure that all drives are ready (i.e., media is inserted) before echoing the drive letter and available disk space. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
    If objDrive.IsReady = True Then
        Wscript.Echo "Drive letter: " & objDrive.DriveLetter
        Wscript.Echo "Free space: " & objDrive.FreeSpace
    Else
        Wscript.Echo "Drive letter: " & objDrive.DriveLetter
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Available Disk Space

Description
Returns the amount of free space for each hard disk installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const HARD_DISK = 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
For Each objDisk in colDisks
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID
    Wscript.Echo "Free Disk Space: "& vbTab & objDisk.FreeSpace
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating CD-ROM Properties

Description
Returns information about all the CD-ROM drives installed on a computer.

For more information about the Win32_CDROMDrive class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    For Each strCapability in objItem.Capabilities
        Wscript.Echo "Capability: "& strCapability
    Next
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Drive: " & objItem.Drive
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Media Loaded: " & objItem.MediaLoaded
    Wscript.Echo "Media Type: " & objItem.MediaType
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "SCSI Bus: " & objItem.SCSIBus
    Wscript.Echo "SCSI Logical Unit: " & objItem.SCSILogicalUnit
    Wscript.Echo "SCSI Port: " & objItem.SCSIPort
    Wscript.Echo "SCSI Target ID: " & objItem.SCSITargetId
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Partition Properties

Description
Lists the properties for all the disk partitions on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskPartitions = objWMIService.ExecQuery _
    ("Select * from Win32_DiskPartition")
For each objPartition in colDiskPartitions
    Wscript.Echo "Block Size: " & vbTab &  objPartition.BlockSize
    Wscript.Echo "Bootable: " & vbTab &  objPartition.Bootable
    Wscript.Echo "Boot Partition: " & vbTab &  objPartition.BootPartition
    Wscript.Echo "Description: " & vbTab &  objPartition.Description
    Wscript.Echo "Device ID: " & vbTab &  objPartition.DeviceID
    Wscript.Echo "Disk Index: " & vbTab &  objPartition.DiskIndex
    Wscript.Echo "Index: " & vbTab &  objPartition.Index
    Wscript.Echo "Name: " & vbTab &  objPartition.Name
    Wscript.Echo "Number Of Blocks: " & vbTab &  _
        objPartition.NumberOfBlocks
    Wscript.Echo "Primary Partition: " & vbTab &  _
        objPartition.PrimaryPartition
    Wscript.Echo "Size: " & vbTab &  objPartition.Size
    Wscript.Echo "Starting Offset: " & vbTab &  _
        objPartition.StartingOffset
    Wscript.Echo "Type: " & vbTab &  objPartition.Type
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Drive Properties Using FSO

Description
Demonstration script that uses the FileSystemObject to return the properties of all the disk drives installed on a computer. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
    Wscript.Echo "Available space: " & objDrive.AvailableSpace
    Wscript.Echo "Drive letter: " & objDrive.DriveLetter
    Wscript.Echo "Drive type: " & objDrive.DriveType
    Wscript.Echo "File system: " & objDrive.FileSystem
    Wscript.Echo "Free space: " & objDrive.FreeSpace
    Wscript.Echo "Is ready: " & objDrive.IsReady
    Wscript.Echo "Path: " & objDrive.Path
    Wscript.Echo "Root folder: " & objDrive.RootFolder
    Wscript.Echo "Serial number: " & objDrive.SerialNumber
    Wscript.Echo "Share name: " & objDrive.ShareName
    Wscript.Echo "Total size: " & objDrive.TotalSize
    Wscript.Echo "Volume name: " & objDrive.VolumeName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Space by User on the Local Computer

Description
Uses disk quotas to enumerate the amount of disk space currently used by individual users for drive C on the local computer. Requires Windows 2000 or later, and cannot be run against a remote computer (unless you use the WSHController object). To enumerate disk space usage for a different drive, change C:\ in line two to the appropriate drive letter (for example, D:\). Disk quotas must be enabled for this script to work.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True

For Each objUser in colDiskQuotas
    Wscript.Echo "Logon name: " & objUser.LogonName
    Wscript.Echo "Quota used: " & objUser.QuotaUsed
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Floppy Drives

Description
Returns information about all the floppy disk drives installed on a computer.

For more information about the Win32_FloppyDrive class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_FloppyDrive")
For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Logical Disk Drive Properties

Description
Lists the properties for all the logical disk drives on a computer. Includes mapped network drives.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For each objDisk in colDisks
    Wscript.Echo "Compressed: " & vbTab &  objDisk.Compressed
    Wscript.Echo "Description: " & vbTab &  objDisk.Description
    Wscript.Echo "DeviceID: " & vbTab &  objDisk.DeviceID
    Wscript.Echo "DriveType: " & vbTab &  objDisk.DriveType
    Wscript.Echo "FileSystem: " & vbTab &  objDisk.FileSystem
    Wscript.Echo "FreeSpace: " & vbTab &  objDisk.FreeSpace
    Wscript.Echo "MediaType: " & vbTab &  objDisk.MediaType
    Wscript.Echo "Name: " & vbTab &  objDisk.Name
    Wscript.Echo "QuotasDisabled: " & vbTab &  objDisk.QuotasDisabled
    Wscript.Echo "QuotasIncomplete: " & vbTab &  objDisk.QuotasIncomplete
    Wscript.Echo "QuotasRebuilding: " & vbTab &  objDisk.QuotasRebuilding
    Wscript.Echo "Size: " & vbTab &  objDisk.Size
    Wscript.Echo "SupportsDiskQuotas: " & vbTab & _
        objDisk.SupportsDiskQuotas
    Wscript.Echo "SupportsFileBasedCompression: " & vbTab & _
        objDisk.SupportsFileBasedCompression
    Wscript.Echo "SystemName: " & vbTab &  objDisk.SystemName
    Wscript.Echo "VolumeDirty: " & vbTab &  objDisk.VolumeDirty
    Wscript.Echo "VolumeName: " & vbTab &  objDisk.VolumeName
    Wscript.Echo "VolumeSerialNumber: " & vbTab &  _
        objDisk.VolumeSerialNumber
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Physical Disk Properties

Description
Retrieves the properties for all the physical disk drives installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer _
        & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from Win32_DiskDrive")
For each objDiskDrive in colDiskDrives
    Wscript.Echo "Bytes Per Sector: " & vbTab &  _
        objDiskDrive.BytesPerSector
    For i = Lbound(objDiskDrive.Capabilities) to _
        Ubound(objDiskDrive.Capabilities)
        Wscript.Echo "Capabilities: " & vbTab &  _
            objDiskDrive.Capabilities(i)
    Next
    Wscript.Echo "Caption: " & vbTab &  objDiskDrive.Caption
    Wscript.Echo "Device ID: " & vbTab &  objDiskDrive.DeviceID
    Wscript.Echo "Index: " & vbTab &  objDiskDrive.Index
    Wscript.Echo "Interface Type: " & vbTab & objDiskDrive.InterfaceType
    Wscript.Echo "Manufacturer: " & vbTab & objDiskDrive.Manufacturer
    Wscript.Echo "Media Loaded: " & vbTab  & objDiskDrive.MediaLoaded
    Wscript.Echo "Media Type: " & vbTab &  objDiskDrive.MediaType
    Wscript.Echo "Model: " & vbTab &  objDiskDrive.Model
    Wscript.Echo "Name: " & vbTab &  objDiskDrive.Name
    Wscript.Echo "Partitions: " & vbTab & objDiskDrive.Partitions
    Wscript.Echo "PNP DeviceID: " & vbTab &  objDiskDrive.PNPDeviceID
    Wscript.Echo "SCSI Bus: " & vbTab &  objDiskDrive.SCSIBus
    Wscript.Echo "SCSI Logical Unit: " & vbTab &  _
        objDiskDrive.SCSILogicalUnit
    Wscript.Echo "SCSI Port: " & vbTab &  objDiskDrive.SCSIPort
    Wscript.Echo "SCSI TargetId: " & vbTab &  objDiskDrive.SCSITargetId
    Wscript.Echo "Sectors Per Track: " & vbTab &  _
        objDiskDrive.SectorsPerTrack
    Wscript.Echo "Signature: " & vbTab &  objDiskDrive.Signature
    Wscript.Echo "Size: " & vbTab &  objDiskDrive.Size
    Wscript.Echo "Status: " & vbTab &  objDiskDrive.Status
    Wscript.Echo "Total Cylinders: " & vbTab &  _
        objDiskDrive.TotalCylinders
    Wscript.Echo "Total Heads: " & vbTab &  objDiskDrive.TotalHeads
    Wscript.Echo "Total Sectors: " & vbTab &  objDiskDrive.TotalSectors
    Wscript.Echo "Total Tracks: " & vbTab &  objDiskDrive.TotalTracks
    Wscript.Echo "Tracks Per Cylinder: " & vbTab &  _
        objDiskDrive.TracksPerCylinder
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Volume Mount Points

Description
Enumerates all the volume mount points on a computer.

For more information about the Win32_MountPoint class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_MountPoint")
For Each objItem In colItems
  WScript.Echo "Directory: " & objItem.Directory
  WScript.Echo "Volume: " & objItem.Volume
  WScript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Volume Properties

Description
Retrieves the properties of all the volumes installed on a computer.

For more information about the Win32_Volume class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objItem In colItems
    WScript.Echo "Automount: " & objItem.Automount
    WScript.Echo "Block Size: " & objItem.BlockSize
    WScript.Echo "Capacity: " & objItem.Capacity
    WScript.Echo "Caption: " & objItem.Caption
    WScript.Echo "Compressed: " & objItem.Compressed
    WScript.Echo "Device ID: " & objItem.DeviceID
    WScript.Echo "Dirty Bit Set: " & objItem.DirtyBitSet
    WScript.Echo "Drive Letter: " & objItem.DriveLetter
    WScript.Echo "Drive Type: " & objItem.DriveType
    WScript.Echo "File System: " & objItem.FileSystem
    WScript.Echo "Free Space: " & objItem.FreeSpace
    WScript.Echo "Indexing Enabled: " & objItem.IndexingEnabled
    WScript.Echo "Label: " & objItem.Label
    WScript.Echo "Maximum File Name Length: " & objItem.MaximumFileNameLength
    WScript.Echo "Name: " & objItem.Name
    WScript.Echo "Quotas Enabled: " & objItem.QuotasEnabled
    WScript.Echo "Quotas Incomplete: " & objItem.QuotasIncomplete
    WScript.Echo "Quotas Rebuilding: " & objItem.QuotasRebuilding
    WScript.Echo "Serial Number: " & objItem.SerialNumber
    WScript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
    WScript.Echo "Supports File-Based Compression: " & objItem.SupportsFileBasedCompression
    WScript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Formatting a Volume

Description
Formats drive D using the NTFS file system. Drives could also be formatted using the FAT or FAT32 file systems. Note that this method cannot be used to format floppy drives. If you modify this script to format a different volume (such as drive X), also note that your WQL query must specify the drive letter followed by a colon and then followed by two forward slashes. Thus drive X would be listed as X:\\.

For more information about the Format method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
    ("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
    errResult = objVolume.Format("NTFS")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Drive Types

Description
Identifies the drive type (floppy drive, hard drive, CD-ROM, etc.) for each physical drive installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID
    Select Case objDisk.DriveType
        Case 1
            Wscript.Echo "No root directory. Drive type could not be " _
                & "determined."
        Case 2
            Wscript.Echo "DriveType: "& vbTab &  "Removable drive."
        Case 3
            Wscript.Echo "DriveType: "& vbTab &  "Local hard disk."
        Case 4
            Wscript.Echo "DriveType: "& vbTab &  "Network disk."
        Case 5
            Wscript.Echo "DriveType: "& vbTab &  "Compact disk."
        Case 6
            Wscript.Echo "DriveType: "& vbTab &  "RAM disk."
        Case Else
            Wscript.Echo "Drive type could not be determined."
    End Select
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying the AutoChk Timeout Value

Description
Sets the auto-delay time for Autochk.exe to 30 seconds.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colAutoChkSettings = objWMIService.ExecQuery _
    ("Select * from Win32_AutochkSetting")
For Each objAutoChkSetting in colAutoChkSettings
    objAutoChkSetting.UserInputDelay = 30
    objAutoChkSetting.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Logical Disk Drive Performance

Description
Uses cooked performance counters to monitor performance of the logical disk drives installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDisks = objRefresher.AddEnum _
    (objWMIService, "win32_perfformatteddata_perfdisk_logicaldisk"). _
        objectSet
objRefresher.Refresh
For i = 1 to 100
    For Each objDisk in colDisks
        Wscript.Echo "Average Disk Bytes Per Read: " & vbTab &  _
            objDisk.AvgDiskBytesPerRead
        Wscript.Echo "Average Disk Bytes Per Transfer: " & vbTab &  _
            objDisk.AvgDiskBytesPerTransfer
        Wscript.Echo "Average Disk Bytes Per Write: " & vbTab &  _
            objDisk.AvgDiskBytesPerWrite
        Wscript.Echo "Average Disk Queue Length: " & vbTab &  _
            objDisk.AvgDiskQueueLength
        Wscript.Echo "Average Disk Read Queue Length: " & vbTab &  _
            objDisk.AvgDiskReadQueueLength
        Wscript.Echo "Average Disk Seconds Per Read: " & vbTab &  _
            objDisk.AvgDiskSecPerRead
        Wscript.Echo "Average Disk Seconds Per Transfer: " & vbTab &  _
            objDisk.AvgDiskSecPerTransfer
        Wscript.Echo "Average Disk Seconds Per Write: " & vbTab &  _
            objDisk.AvgDiskSecPerWrite
        Wscript.Echo "Average Disk Write Queue Length: " & vbTab &  _
            objDisk.AvgDiskWriteQueueLength
        Wscript.Echo "Current Disk Queue Length: " & vbTab &  _
            objDisk.CurrentDiskQueueLength
        Wscript.Echo "Disk Bytes Per Second: " & vbTab &  _
            objDisk.DiskBytesPerSec
        Wscript.Echo "Disk Read Bytes Per Second: " & vbTab &  _
            objDisk.DiskReadBytesPerSec
        Wscript.Echo "Disk Reads Per Second: " & vbTab &  _
            objDisk.DiskReadsPerSec
        Wscript.Echo "Disk Transfers Per Second: " & vbTab &  _
            objDisk.DiskTransfersPerSec
        Wscript.Echo "Disk Write Bytes Per Second: " & vbTab &  _
            objDisk.DiskWriteBytesPerSec
        Wscript.Echo "Disk Writes Per Second: " & vbTab &  _
            objDisk.DiskWritesPerSec
        Wscript.Echo "Free Megabytes: " & vbTab &  objDisk.FreeMegabytes
        Wscript.Echo "Name: " & vbTab &  objDisk.Name
        Wscript.Echo "Percent Disk Read Time: " & vbTab &  _
            objDisk.PercentDiskReadTime
        Wscript.Echo "Percent Disk Time: " & vbTab &  _
            objDisk.PercentDiskTime
        Wscript.Echo "Percent Disk Write Time: " & vbTab &  _
            objDisk.PercentDiskWriteTime
        Wscript.Echo "Percent Free Space: " & vbTab &  _
            objDisk.PercentFreeSpace
        Wscript.Echo "Percent Idle Time: " & vbTab &  _
            objDisk.PercentIdleTime
        Wscript.Echo "Split IO Per Second: " & vbTab &  _
            objDisk.SplitIOPerSec
        Wscript.Sleep 2000
        objRefresher.Refresh
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Physical Disk Drive Performance

Description
Uses cooked performance counters to monitor performance of the physical disk drives installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDisks = objRefresher.AddEnum _
    (objWMIService, "win32_perfformatteddata_perfdisk_physicaldisk"). _
        objectSet
objRefresher.Refresh
For i = 1 to 100
    For Each objDisk in colDisks
        Wscript.Echo "Average Disk Bytes Per Read: " & vbTab &  _
            objDisk.AvgDiskBytesPerRead
        Wscript.Echo "Average Disk Bytes Per Transfer: " & vbTab &  _
            objDisk.AvgDiskBytesPerTransfer
        Wscript.Echo "Average Disk Bytes Per Write: " & vbTab &  _
            objDisk.AvgDiskBytesPerWrite
        Wscript.Echo "Average Disk Queue Length: " & vbTab &  _
           objDisk.AvgDiskQueueLength
        Wscript.Echo "Average Disk Read Queue Length: " & vbTab &  _
            objDisk.AvgDiskReadQueueLength
        Wscript.Echo "Average Disk Seconds Per Read: " & vbTab &  _
            objDisk.AvgDiskSecPerRead
        Wscript.Echo "Average Disk Seconds Per Transfer: " & vbTab &  _
            objDisk.AvgDiskSecPerTransfer
        Wscript.Echo "Average Disk Seconds Per Write: " & vbTab &  _
            objDisk.AvgDiskSecPerWrite
        Wscript.Echo "Average Disk Write Queue Length: " & vbTab &  _
            objDisk.AvgDiskWriteQueueLength
        Wscript.Echo "Current Disk Queue Length: " & vbTab &  _
            objDisk.CurrentDiskQueueLength
        Wscript.Echo "Disk Bytes Per Second: " & vbTab &  _
            objDisk.DiskBytesPerSec
        Wscript.Echo "Disk Read Bytes Per Second: " & vbTab &  _
            objDisk.DiskReadBytesPerSec
        Wscript.Echo "Disk Reads Per Second: " & vbTab &  _
            objDisk.DiskReadsPerSec
        Wscript.Echo "Disk Transfers Per Second: " & vbTab &  _
            objDisk.DiskTransfersPerSec
        Wscript.Echo "Disk Write Bytes Per Second: " & vbTab &  _
            objDisk.DiskWriteBytesPerSec
        Wscript.Echo "Disk Writes Per Second: " & vbTab &  _
            objDisk.DiskWritesPerSec
        Wscript.Echo "Name: " & vbTab &  objDisk.Name
        Wscript.Echo "Percent Disk Read Time: " & vbTab &  _
            objDisk.PercentDiskReadTime
        Wscript.Echo "Percent Disk Time: " & vbTab &  _
            objDisk.PercentDiskTime
        Wscript.Echo "Percent Disk Write Time: " & vbTab &  _
            objDisk.PercentDiskWriteTime
        Wscript.Echo "Percent Idle Time: " & vbTab &  _
            objDisk.PercentIdleTime
        Wscript.Echo "Split IO Per Second: " & vbTab &  _
            objDisk.SplitIOPerSec
        Wscript.Sleep 2000
        objRefresher.Refresh
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Volume Change Events

Description
Temporary event consumer that issues an alert when local volumes are added to or deleted from a computer. (This class monitors only changes to local drives; it cannot detect the addition/deletion of network volumes.)

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService. _
    ExecNotificationQuery("Select * from Win32_VolumeChangeEvent")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo objLatestEvent.DriveName
    Wscript.Echo objLatestEvent.EventType
    Wscript.Echo objLatestEvent.Time_Created
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Mounting a Volume

Description
Mounts volume Z to the file system. If you modify this script to mount a different volume (such as X), note that the volume name in your WQL query must include the drive letter followed by a colon and then followed by two forward slashes. Thus drive X would be listed as X:\\.

For more information about the Mount method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * From Win32_Volume Where Name = 'Z:\\'")
For Each objItem in colItems
     objItem.Mount()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Preventing AutoChk From Running

Description
Ensures that Autochk.exe will not run against drive C the next time the computer reboots, even if the "dirty bit" has been set on drive C.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDisk = objWMIService.Get("Win32_LogicalDisk")
errReturn = objDisk.ExcludeFromAutoChk(Array("C:"))
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Floppy Controller Information

Description
Retrieves information about all the floppy drive controllers found on a computer.

For more information about the Win32_FloppyController class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_FloppyController")
For Each objItem in colItems
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving IDE Controller Information

Description
Retrieves information about all IDE controllers found on a computer.

For more information about the Win32_IDEController class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_IDEController")
For Each objItem in colItems
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Information About Mapped Network Drives

Description
Retrieves information about mapped network drives. The information returned is similar to that available through the Win32_LogicalDisk class, which retrieves information about the logical disks found on a computer.

For more information about the Win32_MappedLogicalDisk class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_MappedLogicalDisk")
For Each objItem in colItems
    Wscript.Echo "Compressed: " & objItem.Compressed
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "File System: " & objItem.FileSystem
    Wscript.Echo "Free Space: " & objItem.FreeSpace
    Wscript.Echo "Maximum Component Length: " & objItem.MaximumComponentLength
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Provider Name: " & objItem.ProviderName
    Wscript.Echo "Session ID: " & objItem.SessionID
    Wscript.Echo "Size: " & objItem.Size
    Wscript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
    Wscript.Echo "Supports File-Based Compression: " & _
        objItem.SupportsFileBasedCompression
    Wscript.Echo "Volume Name: " & objItem.VolumeName
    Wscript.Echo "Volume Serial Number: " & objItem.VolumeSerialNumber
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving SCSI Controller Information

Description
Returns information about all the SCSI controllers found on a computer.

For more information about the Win32_SCSIController class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_SCSIController")
For Each objItem in colItems
    Wscript.Echo "Availability: " & objItem.Availability
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Driver Name: " & objItem.DriverName
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
    Wscript.Echo "Status Information: " & objItem.StatusInfo
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving USB Controller Information

Description
Returns information about all the USB controllers found on a computer.

For more information about the Win32_USBController class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_USBController")
For Each objItem in colItems
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Protocol Supported: " & objItem.ProtocolSupported
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving USB Hub Information

Description
Returns information about all the USB hubs found on a computer.

For more information about the Win32_USBHub class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_USBHub")
For Each objItem in colItems
    Wscript.Echo "Configuration Manager Error Code: " & _
        objItem.ConfigManagerErrorCode
    Wscript.Echo "Configuration Manager User Configuration: " & _
        objItem.ConfigManagerUserConfig
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning a Disk Drive Collection

Description
Demonstration script that uses the FileSystemObject to return a list of all the disk drives installed on a computer. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
    Wscript.Echo "Drive letter: " & objDrive.DriveLetter
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Running ChkDsk

Description
Runs ChkDks.exe against drive D on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const FIX_ERRORS = True
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDisk = objService.Get("Win32_LogicalDisk.DeviceID='D:'")
errReturn = objDisk.ChkDsk(FIX_ERRORS)
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Scheduling AutoChk

Description
Schedules Autochk.exe to run against drive C the next time the computer reboots.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDisk = objWMIService.Get("Win32_LogicalDisk")
errReturn = objDisk.ScheduleAutoChk(Array("C:"))
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Verifying ChkDsk Volume Status

Description
Indicates whether or not any hard drives on a computer have the "dirty bit" set, and should have Chkdsk.exe run.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const LOCAL_HARD_DISK = 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = LOCAL_HARD_DISK ")
For Each objDisk in colDisks
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID
    Wscript.Echo "DriveType: "& vbTab & objDisk.VolumeDirty
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Disk Quota Entry

Description
Creates a custom disk quota entry for a user named jsmith. This script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
set objUser = colDiskQuotas.AddUser("jsmith")
set objUser = colDiskQuotas.FindUser("jsmith")
objUser.QuotaLimit = 50000000

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Disk Quota Settings

Description
Changes the warning threshold and default quota limits for drive C.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuotaSettings = objWMIService.ExecQuery _
    ("Select * from Win32_QuotaSetting")
For each objQuotaSetting in colQuotaSettings
    objQuotaSetting.DefaultLimit = 10000000
    objQuotaSetting.DefaultWarningLimit = 9000000
    objQuotaSetting.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Disk Quota Entry

Description
Deletes the disk quota entry for a user named jsmith. This script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
set objUser = colDiskQuotas.FindUser("jsmith")
colDiskQuotas.DeleteUser(objUser)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Disk Quotas

Description
Turns on disk quotas for drive C.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENFORCE_QUOTAS = 1
StrComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_QuotaSetting Where VolumePath = 'C:\\'")
For Each objDisk in colDisks
    objDisk.State = ENFORCE_QUOTAS
    objDisk.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Disk Quotas on the Local Computer

Description
Enables disk quotas for drive C on the local computer. Requires Windows 2000 or later, and cannot be run against a remote computer (unless you use the WSHController object). To enable disk quotas for a different drive, change C:\ in line two to the appropriate drive letter (for example, D:\). To disable disk quotas, set the value of the constant ENABLE_QUOTAS to 0. To enable, but not enforce, disk quotas, set this value to 1.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE_QUOTAS = 2
Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
colDiskQuotas.QuotaState = ENABLE_QUOTAS

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Quota Settings

Description
Enumerates the disk quota settings for each drive on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuotaSettings = objWMIService.ExecQuery _
    ("Select * from Win32_QuotaSetting")
For each objQuotaSetting in colQuotaSettings
    Wscript.Echo "DefaultLimit: " & vbTab &  objQuotaSetting.DefaultLimit
    Wscript.Echo "DefaultWarningLimit: " & vbTab &  _
        objQuotaSetting.DefaultWarningLimit
    Wscript.Echo "ExceededNotification: " & vbTab &  _
        objQuotaSetting.ExceededNotification
    Wscript.Echo "State: " & vbTab &  objQuotaSetting.State
    Wscript.Echo "VolumePath: " & vbTab &  objQuotaSetting.VolumePath
    Wscript.Echo "WarningExceededNotification: " & vbTab &  _
        objQuotaSetting.WarningExceededNotification
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Quota Settings on the Local Computer

Description
Enumerates the disk quota settings for drive C on the local computer. Requires Windows 2000 or later, and cannot be run against a remote computer (unless you use the WSHController object). To enumerate disk quota settings for a different drive, change C:\ in line two to the appropriate drive letter (for example, D:\).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True

If colDiskQuotas.QuotaState = 2 Then
    Wscript.Echo "Quota state: Enabled and enforced"
ElseIf colDiskQuotas.QuotaState = 1 Then
    Wscript.Echo "Quota state: Enabled but not enforced"
Else
    Wscript.Echo "Quota state: Disabled"
End If

Wscript.Echo "Default quota limit: " & colDiskQuotas.DefaultQuotaLimit
Wscript.Echo "Default warning limit: " & _
    colDiskQuotas.DefaultQuotaThreshold
Wscript.Echo "Record quota violations in event log: " & _
    colDiskQuotas.LogQuotaLimit
Wscript.Echo "Record warnings in event log: " & _
    colDiskQuotas.LogQuotaThreshold

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Quotas

Description
Enumerates disk quota information (including user name, warning and quota limits, and disk space used) for each disk quota entry on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskQuotas = objWMIService.ExecQuery _
   ("Select * from Win32_DiskQuota")
For each objQuota in colDiskQuotas
    Wscript.Echo "Disk Space Used: " & vbTab &  objQuota.DiskSpaceUsed
    Wscript.Echo "Limit: " & vbTab &  objQuota.Limit
    Wscript.Echo "Quota Volume: " & vbTab &  objQuota.QuotaVolume
    Wscript.Echo "Status: " & vbTab &  objQuota.Status
    Wscript.Echo "User: " & vbTab &  objQuota.User
    Wscript.Echo "Warning Limit: " & vbTab &  objQuota.WarningLimit
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Quotas on the Local Computer

Description
Enumerates the disk quota entries for drive C on the local computer. Requires Windows 2000 or later, and cannot be run against a remote computer (unless you use the WSHController object). To enumerate disk quota entries for a different drive, change C:\ in line two to the appropriate drive letter (for example, D:\).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True

For Each objUser in colDiskQuotas
    Wscript.Echo "Logon name: " & objUser.LogonName
    Wscript.Echo "Quota limit: " & objUser.QuotaLimit
    Wscript.Echo "Quota threshold: " & objUser.QuotaThreshold
    Wscript.Echo "Quota used: " & objUser.QuotaUsed
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Disk Space by User Using Disk Quotas

Description
Uses disk quotas to report the amount of disk space being used by each individual user on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuotas = objWMIService.ExecQuery _
    ("Select * from Win32_DiskQuota")
For each objQuota in colQuotas
    Wscript.Echo "Volume: "& vbTab &  objQuota.QuotaVolume
    Wscript.Echo "User: "& vbTab &  objQuota.User
    Wscript.Echo "Disk Space Used: "& vbTab &  objQuota.DiskSpaceUsed
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying a Disk Quota Entry

Description
Modifies the disk quota warning threshold and disk space limit for a user named jsmith. This script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colDiskQuotas = CreateObject("Microsoft.DiskQuota.1")
colDiskQuotas.Initialize "C:\", True
set objUser = colDiskQuotas.FindUser("jsmith")
objUser.QuotaThreshold = 90000000
objUser.QuotaLimit = 100000000

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating NTFS Properties

Description
Retrieves NTFS file system settings from the registry.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
strRegKey =  objShell.RegRead _
    ("HKLM\System\CurrentControlSet\Control\FileSystem\" _
        & "NtfsDisable8dot3NameCreation")
If IsNull(strRegKey) Then
    Wscript.Echo "No value set for disabling 8.3 file name creation."
ElseIf strRegKey = 1 Then
    WScript.Echo "No 8.3 file names will be created for new files."
ElseIf strRegKey = 0 Then
    Wscript.Echo "8.3 file names will be created for new files."
End If
strRegKey = Null
strRegKey =  objShell.RegRead _
    ("HKLM\System\CurrentControlSet\Control\FileSystem\" _
        & "NtfsAllowExtendedCharacterIn8Dot3Name")
If IsNull(strRegKey) Then
    Wscript.Echo "No value set for allowing extended characters in " _
       & " 8.3 file names."
ElseIf strRegKey = 1 Then
    WScript.Echo "Extended characters are permitted in 8.3 file names."
ElseIf strRegKey = 0 Then
    Wscript.Echo "Extended characters not permitted in 8.3 file names."
End If
strRegKey = Null
strRegKey =  objShell.RegRead _
    ("HKLM\System\CurrentControlSet\Control\FileSystem\" _
        & "NtfsMftZoneReservation")
If IsNull(strRegKey) Then
    Wscript.Echo "No value set for reserving the MFT zone."
ElseIf strRegKey = 1 Then
    WScript.Echo _
        "One-eighth of the disk has been reserved for the MFT zone."
ElseIf strRegKey = 2 Then
    Wscript.Echo "One-fourth of the disk reserved for the MFT zone."
ElseIf strRegKey = 3 Then
    Wscript.Echo "Three-eighths of the disk reserved for the MFT zone."
ElseIf strRegKey = 4 Then
    Wscript.Echo "One half of the disk reserved for the MFT zone."
End If
strRegKey = Null
strRegKey =  objShell.RegRead _
    ("HKLM\System\CurrentControlSet\Control\FileSystem\" _
        & "NtfsDisableLastAccessUpdate")
If IsNull(strRegKey) Then
    Wscript.Echo "No value set for disabling the last access update " _
        & "for files and folder."
ElseIf strRegKey = 1 Then
    WScript.Echo "The last access timestamp will not be updated on files " _
        & "and folders."
ElseIf strRegKey = 0 Then
    Wscript.Echo "The last access timestamp updated on files and " _
         & "folders."
End If
strRegKey = Null
strRegKey =  objShell.RegRead _
    ("HKLM\System\CurrentControlSet\Control\FileSystem\Win31FileSystem")
If IsNull(strRegKey) Then
    Wscript.Echo "No value set for using long file names and " _
        & "timestamps."
ElseIf strRegKey = 1 Then
    WScript.Echo "Long file names and extended timestamps are used."
ElseIf strRegKey = 0 Then
    Wscript.Echo "Long file names and extended timestamps are not used."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the File System Type

Identify the File System Type

Description
Returns the type of file system (FAT, NTFS, FAT32, etc.) used on each drive in a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For Each objDisk in colDisks
    Wscript.Echo "DeviceID: "& vbTab &  objDisk.DeviceID
    Wscript.Echo "File System: "& vbTab & objDisk.FileSystem
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying File System Properties

Description
Disables the updating of the last access time for files and folders.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | No

Script Code

Set objShell = WScript.CreateObject("WScript.Shell")
strRegKey =  objShell.RegWrite _
    ("HKLM\System\CurrentControlSet\Control\FileSystem\" _
        & "NtfsDisableLastAccessUpdate" , 1, "REG_DWORD")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring NTFS File Cache Performance

Description
Uses cooked performance counters to monitor the performance of the NTFS file cache.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colCache = objRefresher.AddEnum _
    (objWMIService, "win32_PerfFormattedData_PerfOS_Cache").ObjectSet
objRefresher.Refresh
For i = 1 to 100
    For Each objCache in colCache
        Wscript.Echo "Async Copy Reads Per Second" & vbTab & _
            objCache.AsyncCopyReadsPerSec
        Wscript.Echo "Async Data Maps Per Second" & vbTab & _
            objCache.AsyncDataMapsPerSec
        Wscript.Echo "AsyncFastReadsPerSecond" & vbTab & _
            objCache.AsyncFastReadsPerSec
        Wscript.Echo "Async MDL Reads Per Second" & vbTab & _
            objCache.AsyncMDLReadsPerSec
        Wscript.Echo "Async Pin Reads Per Second" & vbTab & _
            objCache.AsyncPinReadsPerSec
        Wscript.Echo "Caption" & vbTab & objCache.Caption
        Wscript.Echo "Copy Read Hits Percent " & vbTab & _
            objCache.CopyReadHitsPercent
        Wscript.Echo "Copy Reads Per Second" & vbTab & _
            objCache.CopyReadsPerSec
        Wscript.Echo "Data Flushes Per Second" & vbTab & _
            objCache.DataFlushesPerSec
        Wscript.Echo "Data Flush Pages PerSecond" & vbTab & _
            objCache.DataFlushPagesPerSec
        Wscript.Echo "Data Map Hits Percent " & vbTab &  _
            objCache.DataMapHitsPercent
        Wscript.Echo "Data Map Pins Per Second" & vbTab & _
            objCache.DataMapPinsPerSec
        Wscript.Echo "Data Maps Per Second" & vbTab & _
            objCache.DataMapsPerSec
        Wscript.Echo "Description" & vbTab & objCache.Description
        Wscript.Echo "Fast Read Not Possibles Per Second" & vbTab & _
            objCache.FastReadNotPossiblesPerSec
        Wscript.Echo "Fast Read Resource Misses Per Second" & vbTab & _
            objCache.FastReadResourceMissesPerSec
        Wscript.Echo "Fast Reads Per Second" & vbTab & _
            objCache.FastReadsPerSec
        Wscript.Echo "Lazy Write Flushes Per Second" & vbTab & _
            objCache.LazyWriteFlushesPerSec
        Wscript.Echo "Lazy Write Pages Per Second" & vbTab & _
            objCache.LazyWritePagesPerSec
        Wscript.Echo "MDL Read Hits Percent " & vbTab & _
            objCache.MDLReadHitsPercent
        Wscript.Echo "MDL Reads Per Second" & vbTab & _
            objCache.MDLReadsPerSec
        Wscript.Echo "Name" & vbTab & objCache.Name
        Wscript.Echo "Pin Read Hits Percent" & vbTab & _
            objCache.PinReadHitsPercent
        Wscript.Echo "Pin Reads Per Second" & vbTab & _
            objCache.PinReadsPerSec
        Wscript.Echo "Read Aheads Per Second" & vbTab & _
            objCache.ReadAheadsPerSec
        Wscript.Echo "Sync Copy Reads Per Second" & vbTab & _
            objCache.SyncCopyReadsPerSec
        Wscript.Echo "Sync Data Maps Per Second" & vbTab & _
            objCache.SyncDataMapsPerSec
        Wscript.Echo "Sync Fast Reads Per Second" & vbTab & _
            objCache.SyncFastReadsPerSec
        Wscript.Echo "Sync MDL Reads Per Second" & vbTab & _
            objCache.SyncMDLReadsPerSec
        Wscript.Echo "Sync Pin Reads Per Second" & vbTab & _
            objCache.SyncPinReadsPerSec
        Wscript.Sleep 2000
        objRefresher.Refresh
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding an Indexing Service Catalog

Description
Adds an Indexing Service catalog named Script Catalog (with a catalog location of C:\Scripts) to the local computer.

For more information about the methods used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.Stop()
Set objCatalog = objAdminIS.AddCatalog("Script Catalog","c:\scripts")
objAdminIS.Start()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding an Indexing Service Scope

Description
Adds a scope named Script Scope (with the path C:\Scripts) to an Indexing Service catalog named Script Catalog on the local computer.

For more information about the methods and properties used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
Set objCatalog = objAdminIS.GetCatalogByName("Script Catalog")
Set objScope = objCatalog.AddScope("c:\scripts\Indexing Server", False)
objScope.Alias = "Script scope"
objScope.Path = "c:\scripts"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Indexing Service to Autostart

Description
Configures the Indexing Service on the local computer to automatically start each time the computer starts. To configure the Indexing Service for manual start, set the parameter passed to the EnableCI method to False rather than True. Manual start is the default setting for the Indexing Service.

For more information about the EnableCI method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.EnableCI(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Indexing Service Catalogs

Description
Returns information about all the Indexing Service catalogs available on the local computer.

For more information about the methods used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objCatalog = objAdminIS.FindFirstCatalog()
If (objCatalog) Then
    Set objCatAdm = objAdminIS.GetCatalog()
    Wscript.Echo "Catalog location: " & objCatAdm.CatalogLocation
    Wscript.Echo "Catalog name: " & objCatAdm.CatalogName
    If (objAdminIS.IsRunning) Then
        Wscript.Echo "Is stopped: " & objCatAdm.IsCatalogStopped
        Wscript.Echo "Is paused: " & objCatAdm.IsCatalogPaused
        Wscript.Echo "Is running: " & objCatAdm.IsCatalogRunning
        Wscript.Echo "Delayed filter count: " & objCatAdm.DelayedFilterCount
        Wscript.Echo "Documents to filter: " & objCatAdm.DocumentsToFilter
        Wscript.Echo "Filtered document count: " & objCatAdm.FilteredDocumentCount
        Wscript.Echo "Fresh test count: " & objCatAdm.FreshTestCount
        Wscript.Echo "Index size: " & objCatAdm.IndexSize
        Wscript.Echo "Percent merge complete: " & objCatAdm.PctMergeComplete
        Wscript.Echo "Pending scan count: " & objCatAdm.PendingScanCount
        Wscript.Echo "Persistent index count: " & objCatAdm.PersistentIndexCount
        Wscript.Echo "Query count: " & objCatAdm.QueryCount
        Wscript.Echo "State info: " & objCatAdm.StateInfo
        Wscript.Echo "Total document count: " & objCatAdm.TotalDocumentCount
        Wscript.Echo "Unique key count: " & objCatAdm.UniqueKeyCount
        Wscript.Echo "Word list count: " & objCatAdm.WordListCount
    End If
End If

Do
    objCatalog = objAdminIS.FindNextCatalog()
    If (objCatalog) Then
        Set objCatAdm = objAdminIS.GetCatalog()
        Wscript.Echo "Catalog location: " & objCatAdm.CatalogLocation
        Wscript.Echo "Catalog name: " & objCatAdm.CatalogName
    If (objAdminIS.IsRunning) Then
        Wscript.Echo "Is stopped: " & objCatAdm.IsCatalogStopped
        Wscript.Echo "Is paused: " & objCatAdm.IsCatalogPaused
        Wscript.Echo "Is running: " & objCatAdm.IsCatalogRunning
        Wscript.Echo "Delayed filter count: " & objCatAdm.DelayedFilterCount
        Wscript.Echo "Documents to filter: " & objCatAdm.DocumentsToFilter
        Wscript.Echo "Filtered document count: " & objCatAdm.FilteredDocumentCount
        Wscript.Echo "Fresh test count: " & objCatAdm.FreshTestCount
        Wscript.Echo "Index size: " & objCatAdm.IndexSize
        Wscript.Echo "Percent merge complete: " & objCatAdm.PctMergeComplete
        Wscript.Echo "Pending scan count: " & objCatAdm.PendingScanCount
        Wscript.Echo "Persistent index count: " & objCatAdm.PersistentIndexCount
        Wscript.Echo "Query count: " & objCatAdm.QueryCount
        Wscript.Echo "State info: " & objCatAdm.StateInfo
        Wscript.Echo "Total document count: " & objCatAdm.TotalDocumentCount
        Wscript.Echo "Unique key count: " & objCatAdm.UniqueKeyCount
        Wscript.Echo "Word list count: " & objCatAdm.WordListCount
        End If
    Else
        Exit Do
   End If
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Indexing Service Scopes

Description
Returns information about all the Indexing Service scopes found on the local computer.

For more information about the methods and properties used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objCatalog = objAdminIS.FindFirstCatalog()
If (objCatalog) Then
    Set objCatAdm = objAdminIS.GetCatalog()
    Set objScopeAdm = objCatAdm.GetScope()
    Wscript.Echo "Alias: " & objScopeAdm.Alias
    Wscript.Echo "Exclude scope: " & objScopeAdm.ExcludeScope
    Wscript.Echo "Logon: " & objScopeAdm.Logon
    Wscript.Echo "Path: " & objScopeAdm.Path
    Wscript.Echo "Virtual scope: " & objScopeAdm.VirtualScope
End If

Do
    objCatalog = objAdminIS.FindNextCatalog()
    If (objCatalog) Then
        Set objCatAdm = objAdminIS.GetCatalog()
        Set objScopeAdm = objCatAdm.GetScope()
        Wscript.Echo "Alias: " & objScopeAdm.Alias
        Wscript.Echo "Exclude scope: " & objScopeAdm.ExcludeScope
        Wscript.Echo "Logon: " & objScopeAdm.Logon
        Wscript.Echo "Path: " & objScopeAdm.Path
        Wscript.Echo "Virtual scope: " & objScopeAdm.VirtualScope
    Else
        Exit Do
    End If
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the Indexing Service State

Description
Returns information about the current state of the Indexing Service on the local computer.

For more information about the methods used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
Wscript.Echo "Is running: " & objAdminIS.IsRunning
Wscript.Echo "Is paused: " & objAdminIS.IsPaused
Wscript.Echo "Computer name: " & objAdminIS.MachineName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pausing the Indexing Service

Description
Pauses the Indexing Service on the local computer.

For more information about the Pause method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.Pause()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Querying the Indexing Service for File Names

Description
Returns a list of all the files included in the Indexing Service catalog named Script Catalog. This script is designed to run on the local computer.

For more information about searching for files using Indexing Service, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = "provider=msidxs;"
objConnection.Properties("Data Source") = "Script Catalog"
objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

strQuery = "Select Filename from Scope()"

Set objRecordSet = objConnection.Execute(strQuery)

Do While Not objRecordSet.EOF
    Wscript.Echo objRecordSet("Filename")
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing an Indexing Service Catalog

Description
Removes an Indexing Service catalog named Script Catalog from the local computer.

For more information about the RemoveCatalog method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.Stop()
errResult = objAdminIS.RemoveCatalog("Script Catalog", True)
objAdminIS.Start()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing an Indexing Service Scope

Description
Removes the Indexing Service scope C:\Scripts from the Indexing Service catalog named Script Catalog. This script is designed to run on the local computer.

For more information about the methods used in this script, click here for the GetCatalogByName method and here for the RemoveScope method.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
Set objCatalog = objAdminIS.GetCatalogByName("Script Catalog")
objCatalog.RemoveScope("c:\scripts")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resuming the Indexing Service

Description
Resumes the Indexing Service on the local computer.

For more information about the Continue method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.Continue()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Searching by Using the Indexing Service

Description
Returns the file name and file size for all files recorded in the Script Catalog Indexing Service catalog that contain the term Win32_NetworkAdapterConfiguration.

For more information about searching for files within an Indexing Service catalog, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = "provider=msidxs;"
objConnection.Properties("Data Source") = "Script Catalog"
objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

strQuery = "Select Filename, Size, Contents from Scope() Where " _
    & "Contains('Win32_NetworkAdapterConfiguration')"

Set objRecordSet = objConnection.Execute(strQuery)

Do While Not objRecordSet.EOF
    Wscript.Echo objRecordSet("Filename"), objRecordSet("Size")
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Starting the Indexing Service

Description
Starts the Indexing Service on the local computer.

For more information about the Start method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.Start()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Stopping the Indexing Service

Description
Stops the Indexing Service on the local computer.

For more information about the Stop method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objAdminIS = CreateObject("Microsoft.ISAdm")
objAdminIS.Stop()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using a Free Text Search with the Indexing Service

Description
Uses a free text search to return the file name and file size for all files in the Indexing Service catalog Script Catalog that include the term Win32_NetworkAdapterConfiguration.

For more information about searching for files using the Indexing Service, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = "provider=msidxs;"
objConnection.Properties("Data Source") = "Script Catalog"
objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

strQuery = "Select Filename, Size, Contents from Scope() Where " _
    & "Freetext('Win32_NetworkAdapterConfiguration')"

Set objRecordSet = objConnection.Execute(strQuery)

Do While Not objRecordSet.EOF
    Wscript.Echo objRecordSet("Filename"), objRecordSet("Size")
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using a Predefined Indexing Service Query

Description
Uses the predefined query #AllProps to return the file name, file size, and author of all the files included in the Indexing Service catalog Script Catalog on the local computer.

For more information about searching for files using Indexing Service, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = "provider=msidxs;"
objConnection.Properties("Data Source") = "Script Catalog"
objConnection.Open

Set objCommand = CreateObject("ADODB.Command")

strQuery = "Create View #AllProps as Select * from Scope()"

Set objRecordSet = objConnection.Execute("Select * from Extended_FileInfo")

Do While Not objRecordSet.EOF
    Wscript.Echo objRecordSet("Filename") & ", " & objRecordSet("Size") & _
        ", " & objRecordSet("DocAuthor")
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Page File Properties

Description
Sets the initial size of a page file to 300 megabytes, and the maximum size to 600 megabytes.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPageFiles = objWMIService.ExecQuery _
    ("Select * from Win32_PageFileSetting")
For Each objPageFile in colPageFiles
    objPageFile.InitialSize = 300
    objPageFile.MaximumSize = 600
    objPageFile.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Page File Properties

Description
Enumerates the properties of all the page files on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPageFiles = objWMIService.ExecQuery _
    ("Select * from Win32_PageFile")
For each objPageFile in colPageFiles
    Wscript.Echo "CreationDate: " & vbTab &  objPageFile.CreationDate
    Wscript.Echo "Description: " & vbTab &  objPageFile.Description
    Wscript.Echo "Drive: " & vbTab &  objPageFile.Drive
    Wscript.Echo "FileName: " & vbTab &  objPageFile.FileName
    Wscript.Echo "FileSize: " & vbTab &  objPageFile.FileSize
    Wscript.Echo "InitialSize: " & vbTab &  objPageFile.InitialSize
    Wscript.Echo "InstallDate: " & vbTab &  objPageFile.InstallDate
    Wscript.Echo "MaximumSize: " & vbTab &  objPageFile.MaximumSize
    Wscript.Echo "Name: " & vbTab &  objPageFile.Name
    Wscript.Echo "Path: " & vbTab &  objPageFile.Path
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Page File Use

Description
Retrieves page file usage statistics.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPageFiles = objWMIService.ExecQuery _
    ("Select * from Win32_PageFileUsage")
For each objPageFile in colPageFiles
    Wscript.Echo "AllocatedBaseSize: "& vbTab &  objPageFile.AllocatedBaseSize
    Wscript.Echo "CurrentUsage: "& vbTab &  objPageFile.CurrentUsage
    Wscript.Echo "Description: "& vbTab &  objPageFile.Description
    Wscript.Echo "InstallDate: "& vbTab &  objPageFile.InstallDate
    Wscript.Echo "Name: "& vbTab &  objPageFile.Name
    Wscript.Echo "PeakUsage: "& vbTab &  objPageFile.PeakUsage
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Sending Email from a Script

Description
Demonstration script that uses CDO to send email from a computer where the SMTP Service has been installed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "monitor1@fabrikam.com"
objEmail.To = "admin1@fabrikam.com"
objEmail.Subject = "Atl-dc-01 down"
objEmail.Textbody = "Atl-dc-01 is no longer accessible over the network."
objEmail.Send

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Sending Email without Installing the SMTP Service

Description
Demonstration script that uses CDO to send email from a computer where the SMTP Service has not been installed. Replace the name smarthost with the name of your SMTP server..

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Set objEmail = CreateObject("CDO.Message")
objEmail.From = "admin1@fabrikam.com"
objEmail.To = "admin2@fabrikam.com"
objEmail.Subject = "Server down"
objEmail.Textbody = "Server1 is no longer accessible over the network."
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
        "smarthost"
objEmail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a New Record to a Database

Description
Demonstration script that retrieves sound card information for a computer, and then saves that information to an ADO database with the DSN "Inventory."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic
Set colSoundCards = GetObject("winmgmts:").ExecQuery _
    ("Select * from Win32_SoundDevice")
For Each objSoundCard in colSoundCards
    objRecordset.AddNew
    objRecordset("ComputerName") = objSoundCard.SystemName
    objRecordset("Manufacturer") = objSoundCard.Manufacturer
    objRecordset("ProductName") = objSoundCard.ProductName
    objRecordset.Update
Next
objRecordset.Close
objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing a Database Table

Description
Demonstration script that deletes all the records in a table named Hardware from an ADO database with the DSN "Inventory."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "Delete * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic
objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Connecting to an ADO Database

Description
Demonstration script that connects to an ADO database with the DSN "Inventory."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic
objRecordset.Close
objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Record from a Recordset

Description
Demonstration script that deletes the record for a computer named WebServer from an ADO database with the DSN "Inventory."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic
strSearchCriteria = "ComputerName = 'WebServer'"
objRecordSet.Find strSearchCriteria
objRecordset.Delete
objRecordset.Close
objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Finding a Record in a Recordset

Description
Searches an ADO database with a DSN of "Inventory" looking for a specific computer record.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic
strSearchCriteria = "ComputerName = 'WebServer'"
objRecordSet.Find strSearchCriteria
If objRecordset.EOF Then
    Wscript.Echo "Record cannot be found."
Else
    Wscript.Echo "Record found."
End If
objRecordset.Close
objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Updating Records in a Recordset

Description
Demonstration script that updates sound card information for a computer named Webserver. Requires an ADO Database with a DSN of "Inventory."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Inventory;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
    adOpenStatic, adLockOptimistic
strSearchCriteria = "ComputerName = 'WebServer'"
objRecordSet.Find strSearchCriteria
Set colSoundCards = GetObject("winmgmts:").ExecQuery _
    ("Select * from Win32_SoundDevice")
For Each objSoundCard in colSoundCards
    objRecordset("ComputerName") = objSoundCard.SystemName
    objRecordset("Manufacturer") = objSoundCard.Manufacturer
    objRecordset("ProductName") = objSoundCard.ProductName
    objRecordset.Update
Next
objRecordset.Close
objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Asynchronously Enumerating Files

Description
Uses an asynchronous query to enumerate all the files on a computer. This is primarily a demonstration script; if actually run, it could take an hour or more to complete, depending on the number of files on the computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const POPUP_DURATION = 120
Const OK_BUTTON = 0
Set objWSHShell = Wscript.CreateObject("Wscript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
objWMIService.ExecQueryAsync objSink, "Select * from CIM_DataFile"
objPopup = objWshShell.Popup("Starting event retrieval", _
    POPUP_DURATION, "Event Retrieval", OK_BUTTON)
Sub SINK_OnObjectReady(objEvent, objAsyncContext)
    Wscript.Echo objEvent.Name
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing File Extensions

Description
Changes the file extension for all the .log files in the C:\Scripts folder to .txt.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_Directory.Name='c:\Scripts'} Where " _
        & "ResultClass = CIM_DataFile")
For Each objFile In FileList
    If objFile.Extension = "log" Then
        strNewName = objFile.Drive & objFile.Path & _
            objFile.FileName & "." & "txt"
        errResult = objFile.Rename(strNewName)
        Wscript.Echo errResult
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying a File

Description
Demonstration script that uses the FileSystemObject to copy a file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\FSO\ScriptLog.txt" , "D:\Archive\", OverwriteExisting

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying a Set of Files

Description
Demonstration script that uses the FileSystemObject to copy all the .txt files in a folder to a new location.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\FSO\*.txt" , "D:\Archive\" , OverwriteExisting

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a File

Description
Demonstration script that uses the FileSystemObject to delete a file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\FSO\ScriptLog.txt")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting All Files in a Folder

Description
Demonstration script that deletes all the .txt files in a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const DeleteReadOnly = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\FSO\*.txt"), DeleteReadOnly

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating a Specific Set of Files

Description
Returns a list of all the files larger than 1,000,000 bytes.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
    ExecQuery("Select * from CIM_DataFile where FileSize > 1000000")
For Each objFile in colFiles
    Wscript.Echo objFile.Name & " -- " & objFile.FileSize
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All the Files in a Folder

Description
Returns a list of all the files in the Scripts folder. If the computer has more than one scripts folder (for example, C:\Scripts and D:\Scripts), files will be returned from each of these folders.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
    ExecQuery("Select * from CIM_DataFile where Path = '\\Scripts\\'")
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All the Files on a Computer

Description
Enumerates all the files on a computer. This is primarily a demonstration script; if actually run, it could take an hour or more to complete, depending on the number of files on the computer. Depending on the number of files and on available memory, this script could fail before finishing.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_Datafile")
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating File Attributes

Description
Demonstration script that uses the FileSystemObject to enumerate the attributes of a file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\FSO\ScriptLog.txt")
If objFile.Attributes AND 0 Then
    Wscript.Echo "No attributes set."
End If
If objFile.Attributes AND 1 Then
    Wscript.Echo "Read-only."
End If
If objFile.Attributes AND 2 Then
    Wscript.Echo "Hidden file."
End If
If objFile.Attributes AND 4 Then
    Wscript.Echo "System file."
End If
If objFile.Attributes AND 32 Then
    Wscript.Echo "Archive bit set."
End If
If objFile.Attributes AND 64 Then
    Wscript.Echo "Link or shortcut."
End If
If objFile.Attributes AND 2048 Then
    Wscript.Echo "Compressed file."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating File Properties

Description
Demonstration script that uses the FileSystemObject to enumerate the properties of a file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\windows\system32\scrrun.dll")
Wscript.Echo "Date created: " & objFile.DateCreated
Wscript.Echo "Date last accessed: " & objFile.DateLastAccessed
Wscript.Echo "Date last modified: " & objFile.DateLastModified
Wscript.Echo "Drive: " & objFile.Drive
Wscript.Echo "Name: " & objFile.Name
Wscript.Echo "Parent folder: " & objFile.ParentFolder
Wscript.Echo "Path: " & objFile.Path
Wscript.Echo "Short name: " & objFile.ShortName
Wscript.Echo "Short path: " & objFile.ShortPath
Wscript.Echo "Size: " & objFile.Size
Wscript.Echo "Type: " & objFile.Type

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying File Attributes

Description
Demonstration script that checks to see if a file is read-only and, if it is not, marks it as read-only. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\FSO\TestScript.vbs")
If objFile.Attributes = objFile.Attributes AND 1 Then
    objFile.Attributes = objFile.Attributes XOR 1
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring File Creation

Description
Temporary event consumer that issues an alert any time a file is created in the C:\Scripts folder. Best when run under Cscript.exe.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""c:\\\\scripts""'")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring File Deletion

Description
Temporary event consumer that issues an alert any time a file is deleted from the C:\Scripts folder. Best when run under Cscript.exe.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceDeletionEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name=""c:\\\\scripts""'")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring File Modification

Description
Temporary event consumer that issues an alert any time the file C:\Scripts\Index.vbs is modified. Best when run under Cscript.exe.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceModificationEvent WITHIN 10 WHERE " _
        & "TargetInstance ISA 'CIM_DataFile' and " _
            & "TargetInstance.Name='c:\\scripts\\index.vbs'")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo "File: " & objLatestEvent.TargetInstance.Name
    Wscript.Echo "New size: " & objLatestEvent.TargetInstance.FileSize
    Wscript.Echo "Old size: " & objLatestEvent.PreviousInstance.FileSize
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a File

Description
Demonstration script that uses the FileSystermObject to move a file from one location to another. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\FSO\ScriptLog.log" , "D:\Archive"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a Set of Files

Description
Demonstration script that uses the FileSystemObject to move all the .txt files in a folder to a new location. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\FSO\*.txt" , "D:\Archive\"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving Files

Description
Moves all the Windows Media (.wma) files to the folder C:\Media Archive.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
    ExecQuery("Select * from CIM_DataFile where Extension = 'wma'")
For Each objFile in colFiles
    strCopy = "C:\Media Archive\" & objFile.FileName _
        & "." & objFile.Extension
    objFile.Copy(strCopy)
    objFile.Delete
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Parsing a Path Name

Description
Demonstration script that uses the FileSystemObject to return pathname information for a while, including file name, file extension, complete file path, etc. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("ScriptLog.txt")
Wscript.Echo "Absolute path: " & objFSO.GetAbsolutePathName(objFile)
Wscript.Echo "Parent folder: " & objFSO.GetParentFolderName(objFile)
Wscript.Echo "File name: " & objFSO.GetFileName(objFile)
Wscript.Echo "Base name: " & objFSO.GetBaseName(objFile)
Wscript.Echo "Extension name: " & objFSO.GetExtensionName(objFile)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Performing Actions on Files

Description
Uses the Shell object to print all the files in the C:\Logs folder.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

TargetFolder = "C:\Logs"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder)
Set colItems = objFolder.Items
For i = 0 to colItems.Count - 1
    colItems.Item(i).InvokeVerbEx("Print")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming a File

Description
Demonstration script that uses the FileSystemObject to rename a file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\FSO\ScriptLog.txt" , "C:\FSO\BackupLog.txt"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming Files

Description
Renames the file C:\Scripts\Toggle_Service.vbs to C:\Scripts\Toggle_Service.old.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from Cim_Datafile where Name = " _
        & "'c:\\scripts\\toggle_service.vbs'")
For Each objFile in colFiles
    errResult = objFile.Rename("c:\scripts\toggle_service.old")
    Wscript.Echo errResult
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Detailed Summary Information for a File

Description
Uses the Shell's Application object to retrieve detailed summary information including name, size, owner, and file attributes) for all the files in a folder.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("C:\Scripts")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim arrHeaders(13)
For i = 0 to 13
    arrHeaders(i) = objFolder.GetDetailsOf (objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
    For i = 0 to 13
        If i <> 9 then
            Wscript.echo arrHeaders(i) _
                & ": " & objFolder.GetDetailsOf (strFileName, i)
        End If
    Next
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Extended File Properties

Description
Uses the Shell object to return extended properties for all the files in the folder C:\Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Dim arrHeaders(34)
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("C:\Scripts")
For i = 0 to 33
    arrHeaders(i) = objFolder.GetDetailsOf(objFolder.Items, i)
Next
For Each strFileName in objFolder.Items
    For i = 0 to 33
        Wscript.echo i & vbtab & arrHeaders(i) _
            & ": " & objFolder.GetDetailsOf(strFileName, i)
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving File Properties

Description
Lists the properties for the file C:\Scripts\Adsi.vbs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_Datafile Where name = 'c:\\Scripts\\Adsi.vbs'")
For Each objFile in colFiles
    Wscript.Echo "Access mask: " & objFile.AccessMask
    Wscript.Echo "Archive: " & objFile.Archive
    Wscript.Echo "Compressed: " & objFile.Compressed
    Wscript.Echo "Compression method: " & objFile.CompressionMethod
    Wscript.Echo "Creation date: " & objFile.CreationDate
    Wscript.Echo "Computer system name: " & objFile.CSName
    Wscript.Echo "Drive: " & objFile.Drive
    Wscript.Echo "8.3 file name: " & objFile.EightDotThreeFileName
    Wscript.Echo "Encrypted: " & objFile.Encrypted
    Wscript.Echo "Encryption method: " & objFile.EncryptionMethod
    Wscript.Echo "Extension: " & objFile.Extension
    Wscript.Echo "File name: " & objFile.FileName
    Wscript.Echo "File size: " & objFile.FileSize
    Wscript.Echo "File type: " & objFile.FileType
    Wscript.Echo "File system name: " & objFile.FSName
    Wscript.Echo "Hidden: " & objFile.Hidden
    Wscript.Echo "Last accessed: " & objFile.LastAccessed
    Wscript.Echo "Last modified: " & objFile.LastModified
    Wscript.Echo "Manufacturer: " & objFile.Manufacturer
    Wscript.Echo "Name: " & objFile.Name
    Wscript.Echo "Path: " & objFile.Path
    Wscript.Echo "Readable: " & objFile.Readable
    Wscript.Echo "System: " & objFile.System
    Wscript.Echo "Version: " & objFile.Version
    Wscript.Echo "Writeable: " & objFile.Writeable
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving File Version Information

Description
Demonstration script that uses the FileSystemObject to retrieve the file version for a .dll file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Wscript.Echo objFSO.GetFileVersion("c:\windows\system32\scrrun.dll")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Summary Information for a File

Description
Uses the Shell's Application object to retrieve the file name for all the files in a folder.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const FILE_NAME = 0
Set objShell = CreateObject ("Shell.Application")
Set objFolder = objShell.Namespace ("C:\Scripts")
For Each strFileName in objFolder.Items
    Wscript.Echo "File name: " & objFolder.GetDetailsOf _
        (strFileName, FILE_NAME)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using Wildcards in File Queries

Description
Returns a list of all the files whose name beings with a tilde (~).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile where FileName Like '%~%'")
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Verifying that a File Exists

Description
Demonstration script that uses the FileSystemObject to verify that a file exists. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
    Set objFolder = objFSO.GetFile("C:\FSO\ScriptLog.txt")
Else
    Wscript.Echo "File does not exist."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing Folder Attributes

Description
Demonstration script that uses the FileSystemObject to check if a folder is hidden and, if it is not, hides it. Script must be run on the local computer. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
If objFolder.Attributes = objFolder.Attributes AND 2 Then
    objFolder.Attributes = objFolder.Attributes XOR 2
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Compressing Folders

Description
Compresses the folder C:\Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults = objFolder.Compress
    Wscript.Echo errResults
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying a Folder

Description
Demonstration script that uses the FileSystemObject to copy a folder to a new location. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "C:\Scripts" , "C:\FSO" , OverWriteFiles

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying Folders Using the Shell Object

Description
Uses the Shell object to copy the folder C:\Scripts to D:\Archives. Displays the Copying Files progress dialog as the folder is being copied.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const FOF_CREATEPROGRESSDLG = &H0&
ParentFolder = "D:\Archive"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.CopyHere "C:\Scripts", FOF_CREATEPROGRESSDLG

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying Folders Using WMI

Description
Uses WMI to copy the folder C:\Scripts to D:\Archive.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery( _
    "Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults  = objFolder.Copy("D:\Archive")
    Wscript.Echo errResults
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Folder

Description
Demonstration script that uses the FileSystemObject to create a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("C:\FSO")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating New Folders

Description
Uses the Shell object to create a new folder named C:\Archive.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

ParentFolder = "C:\"
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.NameSpace(ParentFolder)
objFolder.NewFolder "Archive"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Folder

Description
Demonstration script that uses the FileSystemObject to delete a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder("C:\FSO")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Folders

Description
Deletes the folder C:\Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where Name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults = objFolder.Delete
    Wscript.Echo errResults
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating a Specific Set of Folders

Description
Returns a list of all the hidden folders on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from Win32_Directory Where Hidden = True")
For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All the Folders on a Computer

Description
Returns a list of all the folders on a computer. This can take 15 minutes or more to complete, depending on the number of folders on the computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery("Select * from Win32_Directory")
For Each objFolder in colFolders
    Wscript.Echo objFolder.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Folder Attributes

Description
Demonstration script that uses the FileSystemObject to enumerate the attributes of a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
If objFolder.Attributes AND 2 Then
    Wscript.Echo "Hidden folder."
End If
If objFolder.Attributes AND 4 Then
    Wscript.Echo "System folder."
End If
If objFolder.Attributes AND 16 Then
    Wscript.Echo "Folder."
End If
If objFolder.Attributes AND 32 Then
    Wscript.Echo "Archive bit set."
End If
If objFolder.Attributes AND 2048 Then
    Wscript.Echo "Compressed folder."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Folder Properties

Description
Demonstration script that uses the FileSystemObject to enumerate the properties of a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Scripts")
Wscript.Echo "Date created: " & objFolder.DateCreated
Wscript.Echo "Date last accessed: " & objFolder.DateLastAccessed
Wscript.Echo "Date last modified: " & objFolder.DateLastModified
Wscript.Echo "Drive: " & objFolder.Drive
Wscript.Echo "Is root folder: " & objFolder.IsRootFolder
Wscript.Echo "Name: " & objFolder.Name
Wscript.Echo "Parent folder: " & objFolder.ParentFolder
Wscript.Echo "Path: " & objFolder.Path
Wscript.Echo "Short name: " & objFolder.ShortName
Wscript.Echo "Short path: " & objFolder.ShortPath
Wscript.Echo "Size: " & objFolder.Size
Wscript.Echo "Type: " & objFolder.Type

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Folders Using Dates

Description
Lists all the folders on a computer that were created after 3/1/2002.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const LOCAL_TIME = True
Set dtmTargetDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
dtmTargetDate.SetVarDate "3/1/2002", LOCAL_TIME
strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory Where " _
        & "CreationDate > '" & dtmTargetDate & "'")
For each objFolder in colFolders
    dtmConvertedDate.Value = objFolder.CreationDate
    Wscript.Echo objFolder.Name & VbTab & _
        dtmConvertedDate.GetVarDate(LOCAL_TIME)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Subfolders in a Folder

Description
Demonstration script that uses the FileSystemObject to return the folder name and size for all the subfolders in a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\FSO")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
    Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Subfolders of a Folder

Description
Uses a WMI Associators of query to list all the subfolders of the folder C:\Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSubfolders = objWMIService.ExecQuery _
    ("Associators of {Win32_Directory.Name='c:\scripts'} " _
        & "Where AssocClass = Win32_Subdirectory " _
            & "ResultRole = PartComponent")
For Each objFolder in colSubfolders
    Wscript.Echo objFolder.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Finding Folders by Date

Description
Finds all the folders created after March 1, 2002. To modify this script, you must modify the following items in the value assigned to the variable dtmTargetDate:

· 2002 -- Change this to the target year (for example, 1999).

· 03 -- Change this to the target month (01 for January, 02 for February … 12 for December).

· 01 -- Change this to the target day (01 for the first day of the month, 02 for the second, etc.).

· -420 -- To assure the correct results, change this to the offset between your time zone and Greenwich Mean Time. If you do not know the offset, use the script Determining Time Zone Offset from Greenwich Mean Time.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
dtmTargetDate = "20020301000000.000000-420"
strComputer = "."

Set objWMIService = GetObject _
    ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory Where CreationDate > '" & _
        dtmtargetDate & "'")

For Each objFolder in colFolders
    Wscript.Echo objFolder.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Shell Object Verbs

Description
Returns a list of Shell object verbs (context menu items) for the Recycle Bin.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes

Script Code

Const RECYCLE_BIN = &Ha&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(RECYCLE_BIN)
Set objFolderItem = objFolder.Self
Set colVerbs = objFolderItem.Verbs
For i = 0 to colVerbs.Count - 1
    Wscript.Echo colVerbs.Item(i)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a Folder

Description
Demonstration script that uses the FileSystermObject to move a folder from one location to another. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\Scripts" , "M:\helpdesk\management"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving Folders Using the Shell Object

Description
Uses the Shell object to move the folder C:\Scripts to D:\Archives. Displays the Copying Files progress dialog as the folder is being moved.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script installed

Script Code

Const FOF_CREATEPROGRESSDLG = &H0&
TargetFolder = "D:\Archive"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(TargetFolder)
objFolder.MoveHere "C:\Scripts", FOF_CREATEPROGRESSDLG

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving Folders Using WMI

Description
Uses WMI to move the folder C:\Scripts to C:\Admins\Documents\Archive\VBScript.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults = objFolder.Rename("C:\Admins\Documents\Archive\VBScript")
    Wscript.Echo errResults
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming a Folder

Description
Demonstration script that uses the FileSystemObject to rename a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFolder "C:\FSO\Samples" , "C:\FSO\Scripts"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming Folders

Description
Renames the folder C:\Scripts to C:\Repository.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults = objFolder.Rename("C:\Script Repository")
    Wscript.Echo errResults
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Folder Properties

Description
Lists the properties of the folder C:\Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService. _
    ExecQuery("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    Wscript.Echo "Archive: " & objFolder.Archive
    Wscript.Echo "Caption: " & objFolder.Caption
    Wscript.Echo "Compressed: " & objFolder.Compressed
    Wscript.Echo "Compression method: " & objFolder.CompressionMethod
    Wscript.Echo "Creation date: " & objFolder.CreationDate
    Wscript.Echo "Encrypted: " & objFolder.Encrypted
    Wscript.Echo "Encryption method: " & objFolder.EncryptionMethod
    Wscript.Echo "Hidden: " & objFolder.Hidden
    Wscript.Echo "In use count: " & objFolder.InUseCount
    Wscript.Echo "Last accessed: " & objFolder.LastAccessed
    Wscript.Echo "Last modified: " & objFolder.LastModified
    Wscript.Echo "Name: " & objFolder.Name
    Wscript.Echo "Path: " & objFolder.Path
    Wscript.Echo "Readable: " & objFolder.Readable
    Wscript.Echo "System: " & objFolder.System
    Wscript.Echo "Writeable: " & objFolder.Writeable
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Uncompressing Folders

Description
Uncompresses the folder C:\Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where name = 'c:\\Scripts'")
For Each objFolder in colFolders
    errResults = objFolder.Uncompress
    Wscript.Echo errResults
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using Recursion to Enumerate Subfolders

Description
Demonstration script that uses the FileSystemObject to recursively list all the subfolders (and their subfolders) within a folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Scripts")
Sub ShowSubFolders(Folder)
    For Each Subfolder in Folder.SubFolders
        Wscript.Echo Subfolder.Path
        ShowSubFolders Subfolder
    Next
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using the Browse for Folder Dialog Box

Description
Uses the Shell object to display the Browse for Folder dialog box. After a folder has been selected, the script reports whether or not the folder is read-only.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
objPath = Replace(objPath, "\", "\\")
strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where name = '" & objPath & "'")
For Each objFile in colFiles
    Wscript.Echo "Readable: " & objFile.Readable
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using Wildcards in a Folder Query

Description
Returns a list of all the folders whose path begins with C:\S.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
    ("Select * from Win32_Directory where Name Like '%c:\\S%'")
For Each objFolder in colFolders
    Wscript.Echo "Name: " & objFolder.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Verifying that a Folder Exists

Description
Demonstration script that uses the FileSystemObject to verify that a folder exists. If the folder does exist, the script binds to that folder. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("C:\FSO") Then
    Set objFolder = objFSO.GetFolder("C:\FSO")
Else
    Wscript.Echo "Folder does not exist.”
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Network Share

Description
Creates a shared folder named FinanceShare, setting the maximum number of simultaneous connections to 25, and adding a share description.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create _
    ("C:\Finance", "FinanceShare", FILE_SHARE, _
        MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Network Share

Description
Stops sharing a shared folder named FinanceShare. This does not delete the folder from the local hard drive, but simply stops making it available over the network.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
    ("Select * from Win32_Share Where Name = 'FinanceShare'")
For Each objShare in colShares
    objShare.Delete
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Published Folder

Description
Deletes a published folder named FinanceShare from Active Directory. This does not delete the share itself, it simply removes it from Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objContainer = GetObject("LDAP://CN=FinanceShare, " _
    & "OU=Finance, DC=fabrikam, DC=com")
objContainer.DeleteObject (0)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Network Shares

Description
Lists all the shared folders on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share")
For each objShare in colShares
    Wscript.Echo "AllowMaximum: " & vbTab &  objShare.AllowMaximum
    Wscript.Echo "Caption: " & vbTab &  objShare.Caption
    Wscript.Echo "MaximumAllowed: " & vbTab &  objShare.MaximumAllowed
    Wscript.Echo "Name: " & vbTab &  objShare.Name
    Wscript.Echo "Path: " & vbTab &  objShare.Path
    Wscript.Echo "Type: " & vbTab &  objShare.Type
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Published Shares

Description
Enumerates all the shared folders that have been published in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from " _
    & "'LDAP://DC=Fabrikam,DC=com' where objectClass='volume'"
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
    Wscript.Echo "UNC Name: " & objRecordSet.Fields("uNCName").Value
    Wscript.Echo "Managed By: " & objRecordSet.Fields("ManagedBy").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Mapping All Network Shares to Local Folders

Description
Uses a WMI Associators of query to return the local path of a network share named Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
    ("Select * From Win32_Share")
For Each objShare in colShares
    Set colAssociations = objWMIService.ExecQuery _
        ("Associators of {Win32_Share.Name='" & objShare.Name & "'} " _
            & " Where AssocClass=Win32_ShareToDirectory")
    For Each objFolder in colAssociations
        Wscript.Echo objShare.Name & vbTab & objFolder.Name
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Mapping a Network Share to a Local Folder

Description
Uses a WMI Associators of query to return the local path of all the network shares on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
    ("Associators of {Win32_Share.Name='Scripts'} Where " _
        & "AssocClass=Win32_ShareToDirectory")
For Each objFolder in colShares
    Wscript.Echo objFolder.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying a Network Share

Description
Accesses a shared folder named FinanceShare, changes the maximum number of simultaneous connections to 50, and provides a new share description.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
    ("Select * from Win32_Share Where Name = 'FinanceShare'")
For Each objShare in colShares
    errReturn = objShare.SetShareInfo(50, _
        "Public share for HR administrators and the Finance Group.")
Next
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Publishing a Shared Folder

Description
Publishes a shared folder in Active Directory, assigning the folder a description and three keywords.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objComputer = GetObject _
    ("LDAP://OU=Finance, DC=fabrikam, DC=com")
Set objShare = objComputer.Create("volume", "CN=FinanceShare")
objShare.Put "uNCName", "\\atl-dc-02\FinanceShare"
objShare.Put "Description", "Public share for users in the Finance group."
objShare.Put "Keywords", Array("finance", "fiscal", "monetary")
objShare.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Searching for Published Folders

Description
Searches Active Directory for any shared folders that have the keyword "finance."

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select Name, unCName, ManagedBy from "
    & "'LDAP://DC=Reskit,DC=com'" _
        & " where objectClass='volume' and Keywords = 'finance*'"
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo "Share Name: " & objRecordSet.Fields("Name").Value
    Wscript.Echo "UNC Name: " & objRecordSet.Fields("uNCName").Value
    Wscript.Echo "Managed By: " & objRecordSet.Fields("ManagedBy").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Support URL to an Event Log Entry

Description
Writes an event to the Application event log that includes a support URL.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const EVENT_FAILED = 1
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_FAILED, _
    "Payroll application could not be installed." _
    & "Additional information is available from http://www.fabrikam.com."

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding WMI Data to an Event Log Entry

Description
Writes an event that includes additional information such as user name and the amount of free disk space on the computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

Const EVENT_FAILED = 2
Set objShell = Wscript.CreateObject("Wscript.Shell")
Set objNetwork = Wscript.CreateObject("Wscript.Network")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from win32_perfformatteddata_perfdisk_logicaldisk")
For each objDisk in colDiskDrives
    strDriveSpace = objDisk.Name & " " & objDisk.FreeMegabytes _
        & VbCrLf
Next
strEventDescription = "Payroll application could not be installed on " _
    & objNetwork.UserDomain & "\" & objNetwork.ComputerName _
        & " by user " & objNetwork.UserName & _
            ". Free space on each drive is: " & strDriveSpace
objShell.LogEvent EVENT_FAILED, strEventDescription

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Asynchronous Event Log Querying

Description
Uses an asynchronous query to retrieve all the events recorded in all the event logs. This approach is faster than retrieving a large number of events using a synchronous query.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

Const POPUP_DURATION = 10
Const OK_BUTTON = 0
Set objWSHShell = Wscript.CreateObject("Wscript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objSink = WScript.CreateObject("WbemScripting.SWbemSink","SINK_")
objWMIService.InstancesOfAsync objSink, "Win32_NTLogEvent"
Error = objWshShell.Popup("Starting event retrieval", POPUP_DURATION, _
    "Event Retrieval", OK_BUTTON)
Sub SINK_OnCompleted(iHResult, objErrorObject, objAsyncContext)
    WScript.Echo "Asynchronous operation is done."
End Sub
Sub SINK_OnObjectReady(objEvent, objAsyncContext)
    Wscript.Echo "Category: " & objEvent.Category
    Wscript.Echo "Computer Name: " & objEvent.ComputerName
    Wscript.Echo "Event Code: " & objEvent.EventCode
    Wscript.Echo "Message: " & objEvent.Message
    Wscript.Echo "Record Number: " & objEvent.RecordNumber
    Wscript.Echo "Source Name: " & objEvent.SourceName
    Wscript.Echo "Time Written: " & objEvent.TimeWritten
    Wscript.Echo "Event Type: " & objEvent.Type
    Wscript.Echo "User: " & objEvent.User
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Backing Up and Clearing an Event Log

Description
Backs up and clears the Application event log.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Backup)}!\\" & _
        strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='Application'")
For Each objLogfile in colLogFiles
    errBackupLog = objLogFile.BackupEventLog("c:\scripts\application.evt")
    If errBackupLog <> 0 Then
        Wscript.Echo "The Application event log could not be backed up."
    Else
        objLogFile.ClearEventLog()
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Backing Up and Clearing Large Event Logs

Description
Backs up and clears am event log if the log file size is larger than 20 megabytes.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate, (Backup, Security)}!\\" _
        & strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile")
For each objLogfile in colLogFiles
    If objLogFile.FileSize > 100000 Then
       strBackupLog = objLogFile.BackupEventLog _
           ("c:\scripts\" & objLogFile.LogFileName & ".evt")
       objLogFile.ClearEventLog()
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Event Log Properties

Description
Sets the maximum size of all event logs to 250 megabytes, and enables the log to overwrite any events older than 14 days.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Security)}!\\" & _
        strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile")
For each objLogfile in colLogFiles
    strLogFileName = objLogfile.Name
    Set wmiSWbemObject = GetObject _
        ("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:" _
            & "Win32_NTEventlogFile.Name='" & strLogFileName & "'")
    wmiSWbemObject.MaxFileSize = 2500000000
    wmiSWbemObject.OverwriteOutdated = 14
    wmiSWbemObject.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying Event Log Events to a Database

Description
Retrieves events from all the event logs and records these in a database with the DSN Name EventLogs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=EventLogs;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM EventTable" , objConn, 3, 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRetrievedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent")
For Each objEvent in colRetrievedEvents
    objRS.AddNew
    objRS("Category") = objEvent.Category
    objRS("ComputerName") = objEvent.ComputerName
    objRS("EventCode") = objEvent.EventCode
    objRS("Message") = objEvent.Message
    objRS("RecordNumber") = objEvent.RecordNumber
    objRS("SourceName") = objEvent.SourceName
    objRS("TimeWritten") = objEvent.TimeWritten
    objRS("Type") = objEvent.Type
    objRS("User") = objEvent.User
    objRS.Update
Next
objRS.Close
objConn.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying the Previous Day's Event Log Events to a Database

Copying the Previous Day’s Event Log Events to a Database

Description
Retrieves events from all the event logs that were recorded on the previous day, and writes these records to a database with the DSN Name EventLogs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=EventLogs;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM EventTable" , objConn, 3, 3
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = Date - 1
dtmEndDate.SetVarDate Date, True
dtmStartDate.SetVarDate DateToCheck, True
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
        & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For each objEvent in colEvents
    objRS.AddNew
    objRS("Category") = objEvent.Category
    objRS("ComputerName") = objEvent.ComputerName
    objRS("EventCode") = objEvent.EventCode
    objRS("Message") = objEvent.Message
    objRS("RecordNumber") = objEvent.RecordNumber
    objRS("SourceName") = objEvent.SourceName
    objRS("TimeWritten") = objEvent.TimeWritten
    objRS("Type") = objEvent.Type
    objRS("User") = objEvent.User
    objRS.Update
Next
objRS.Close
objConn.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Custom Event Log

Description
Creates a custom event log named Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | No

Script Code

Const NO_VALUE = Empty
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.RegWrite _
    "HKLM\System\CurrentControlSet\Services\EventLog\Scripts\", NO_VALUE

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating Unique File Names for Event Log Backups

Description
Backs up and clears the Application event log, generating a unique file name for each backup based on the current date.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Backup)}!\\" & _
        strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='Application'")
For Each objLogfile in colLogFiles
    objLogFile.BackupEventLog("c:\scripts\" & strBackupName & _
        "_application.evt")
    objLogFile.ClearEventLog()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Querying a Specific Event Log

Description
Retrieves all the events from the System event log.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, except for the EventType property
Windows NT 4.0 | Yes, with WMI installed, and except for the EventType property
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")
For Each objEvent in colLoggedEvents
    Wscript.Echo "Category: " & objEvent.Category
    Wscript.Echo "Computer Name: " & objEvent.ComputerName
    Wscript.Echo "Event Code: " & objEvent.EventCode
    Wscript.Echo "Message: " & objEvent.Message
    Wscript.Echo "Record Number: " & objEvent.RecordNumber
    Wscript.Echo "Source Name: " & objEvent.SourceName
    Wscript.Echo "Time Written: " & objEvent.TimeWritten
    Wscript.Echo "Event Type: " & objEvent.Type
    Wscript.Echo "User: " & objEvent.User
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Querying an Event Log for Stop Events

Description
Queries the System event log for any events written in regards to a stop event (blue screen).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'System'" _
        & " and SourceName = 'SaveDump'")
For Each objEvent in colLoggedEvents
    Wscript.Echo "Event date: " & objEvent.TimeGenerated
    Wscript.Echo "Description: " & objEvent.Message
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving All Events from an Event Log

Description
Retrieves all the events from all the event logs on a computer. Note: This is primarily a demonstration script. It can take several hours, or more, to run, depending on the number of events recorded in your event logs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, except for the EventType property
Windows NT 4.0 | Yes, with WMI installed, and except for the EventType property
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'Application'")
For Each objEvent in colLoggedEvents
    Wscript.Echo "Category: " & objEvent.Category
    Wscript.Echo "Computer Name: " & objEvent.ComputerName
    Wscript.Echo "Event Code: " & objEvent.EventCode
    Wscript.Echo "Message: " & objEvent.Message
    Wscript.Echo "Record Number: " & objEvent.RecordNumber
    Wscript.Echo "Source Name: " & objEvent.SourceName
    Wscript.Echo "Time Written: " & objEvent.TimeWritten
    Wscript.Echo "Event Type: " & objEvent.Type
    Wscript.Echo "User: " & objEvent.User
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Event Log Properties

Description
Retrieves a list of properties for all the event logs on a computer, except the Security event log.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objInstalledLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile")
For each objLogfile in objInstalledLogFiles
    Wscript.Echo "Name: " &  objLogfile.LogFileName
    Wscript.Echo "Maximum Size: " &  objLogfile.MaxFileSize
    If objLogfile.OverWriteOutdated > 365 Then
        Wscript.Echo "Overwrite Outdated Records: Never." & VbCrLf
    ElseIf objLogfile.OverWriteOutdated = 0 Then
        Wscript.Echo "Overwrite Outdated Records: As needed." & VbCrLf
    Else
        Wscript.Echo "Overwrite Outdated Records After: " &  _
            objLogfile.OverWriteOutdated & " days" & VbCrLf
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Events For One Day From An Event Log

Description
Retrieves all the events recorded on a specific date from all the event logs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const CONVERT_TO_LOCAL_TIME = True
Set dtmStartDate = CreateObject("WbemScripting.SWbemDateTime")
Set dtmEndDate = CreateObject("WbemScripting.SWbemDateTime")
DateToCheck = CDate("2/18/2002")
dtmStartDate.SetVarDate DateToCheck, CONVERT_TO_LOCAL_TIME
dtmEndDate.SetVarDate DateToCheck + 1, CONVERT_TO_LOCAL_TIME
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where TimeWritten >= '" _
        & dtmStartDate & "' and TimeWritten < '" & dtmEndDate & "'")
For each objEvent in colEvents
    Wscript.Echo "Category: " & objEvent.Category
    Wscript.Echo "Computer Name: " & objEvent.ComputerName
    Wscript.Echo "Event Code: " & objEvent.EventCode
    Wscript.Echo "Message: " & objEvent.Message
    Wscript.Echo "Record Number: " & objEvent.RecordNumber
    Wscript.Echo "Source Name: " & objEvent.SourceName
    Wscript.Echo "Time Written: " & objEvent.TimeWritten
    Wscript.Echo "Event Type: " & objEvent.Type
    Wscript.Echo "User: " & objEvent.User
    Wscript.Echo objEvent.LogFile
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Security Log Properties

Description
Retrieves properties for the Security event log.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Security)}!\\" & _
        strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='Security'")
For Each objLogFile in colLogFiles
    Wscript.Echo objLogFile.NumberOfRecords
    Wscript.Echo "Maximum Size: " &  objLogfile.MaxFileSize
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Specific Events from an Event Log

Description
Retrieves all events with an event code of 6008 from the System event log.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLoggedEvents = objWMIService.ExecQuery _
        ("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
            & "EventCode = '6008'")
Wscript.Echo "Improper shutdowns: " & colLoggedEvents.Count

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving System Event Log Properties

Description
Reports the number of events currently recorded in the System event log.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colLogFiles = objWMIService.ExecQuery _
    ("Select * from Win32_NTEventLogFile where LogFileName='System'")
For Each objLogFile in colLogFiles
    Wscript.Echo objLogFile.NumberOfRecords
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing Events to a Remote Event Log

Description
Writes an event to the Application event log on a remote computer named PrimaryServer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
    "Payroll application successfully installed." , "\\PrimaryServer"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing Events to the Local Event Log

Description
Writes an event to the Application event log on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const EVENT_SUCCESS = 0
Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
    "Payroll application successfully installed."

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing to a Custom Event Log Using EventCreate

Description
Uses the EventCreate.exe utility to write an event to a custom event log named Scripts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set WshShell = WScript.CreateObject("WScript.Shell")
strCommand = "eventcreate /T Error /ID 100 /L Scripts /D " & _
    Chr(34) & "Test event." & Chr(34)
WshShell.Run strcommand

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Parsing a Comma Separated Values Log

Description
Extracts the information in the DHCP Server log to individual fields and records.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Windows\System32\DHCP\" _
    & "DhcpSrvLog-Mon.log", ForReading)
Do While objTextFile.AtEndOfStream <> True
    If inStr(objtextFile.Readline, ",") Then
        arrDHCPRecord = split(objTextFile.Readline, ",")
        wscript.echo "Event ID: " & arrDHCPRecord(0)
        wscript.echo "Date: " & arrDHCPRecord(1)
        wscript.echo "Time: " & arrDHCPRecord(2)
        wscript.echo "Description: " & arrDHCPRecord(3)
        wscript.echo "IP Address: " & arrDHCPRecord(4)
        wscript.echo "Host Name: " & arrDHCPRecord(5)
        wscript.echo "MAC Address: " & arrDHCPRecord(6)
    Else
        objTextFile.Skipline
    End If
    i = i + 1
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Parsing a Fixed Width Column Log

Description
Extracts the information in the NetSetup log to individual fields and records.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Windows\Debug\Netsetup.log", _
    ForReading)
Do While objTextFile.AtEndOfStream <> True
    strLinetoParse = objTextFile.ReadLine
    dtmEventDate = Mid(strLinetoParse, 1, 6)
    dtmEventTime = Mid(strLinetoParse, 7, 9)
    strEventDescription = Mid(strLinetoParse, 16)
    Wscript.Echo "Date: " & dtmEventDate
    Wscript.Echo "Time: " & dtmEventTime
    Wscript.Echo "Description: " & strEventDescription & VbCrLf
Loop
objFSO.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Trust Relationship Properties

Description
Configures trust relationship refresh and validation properties.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\MicrosoftActiveDirectory")
Set colTrustList = objWMIService.ExecQuery _
    ("Select * from Microsoft_TrustProvider")
For Each objTrust in colTrustList
    objTrust.TrustListLifetime = 25
    objTrust.TrustStatusLifetime = 10
    objTrust.TrustCheckLevel = 1
    objTrust.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Active Directory Database Replication Partners

Description
Returns a list of Active Directory replication partners for a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\MicrosoftActiveDirectory")
Set colReplicationOperations = objWMIService.ExecQuery _
    ("Select * from MSAD_ReplNeighbor")
For each objReplicationJob in colReplicationOperations
    Wscript.Echo objReplicationJob.Domain
    Wscript.Echo objReplicationJob.NamingContextDN
    Wscript.Echo objReplicationJob.SourceDsaDN
    Wscript.Echo objReplicationJob.LastSyncResult
    Wscript.Echo objReplicationJob.NumConsecutiveSyncFailures
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Domain Information for Trust Partners

Description
Returns local domain information.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\MicrosoftACtiveDirectory")
Set colDomainInfo = objWMIService.ExecQuery _
    ("Select * from Microsoft_LocalDOmainInfo")
For each objDomain in colDomainInfo
    Wscript.Echo objDomain.DNSName
    Wscript.Echo objDomain.FlatName
    Wscript.Echo objDomain.SID
    Wscript.Echo objDomain.TreeName
    Wscript.Echo objDomain.DCName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Trust Relationships

Description
Enumerates trust relationships.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\MicrosoftActiveDirectory")
Set colTrustList = objWMIService.ExecQuery _
    ("Select * from Microsoft_DomainTrustStatus")
For each objTrust in colTrustList
    Wscript.Echo objTrust.TrustedDomain
    Wscript.Echo objTrust.TrustDirection
    Wscript.Echo objTrust.TrustType
    Wscript.Echo objTrust.TrustAttributes
    Wscript.Echo objTrust.TrustedDCName
    Wscript.Echo objTrust.TrustStatus
    Wscript.Echo objTrust.TrustIsOK
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing Active Directory Database Performance Counters

Description
Installs the Active Database performance counters on a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Shell.Application")
objFSO.CreateFolder ("C:\Performance")
Set objCopyFile = objFSO.GetFile("C:\windows\system32\esentprf.dll ")
objCopyFile.Copy ("C:\performance\esentprf.dll ")
WshShell.RegWrite _
    "HKLM\System\CurrentControlSet\Services\Esent\Performance\Open", _
        "OpenPerformanceData", "REG_SZ"
WshShell.RegWrite _
    "HKLM\System\CurrentControlSet\Services\Esent\Performance\Collect", _
        "CollectPerformanceData", "REG_SZ"
WshShell.RegWrite _
    "HKLM\System\CurrentControlSet\Services\Esent\Performance\Close", _
        "ClosePerformanceData", "REG_SZ"
WshShell.RegWrite _
    "HKLM\System\CurrentControlSet\Services\Esent\Performance\Library", _
        "C:\Performance\Esentprf.dll", "REG_SZ"
strCommandText = "%comspec% /c lodctr.exe c:\windows\system32\esentprf.ini"
WshShell.Run strCommandText

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Active Directory Database Performance

Description
Uses cooked performance counters to monitor the performance of the Active Directory database on a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDatabases = objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_Esent_Database " _
        & "Where Name = 'NT Directory'")
For Each objADDatabase in colDatabases
    Wscript.Echo objADDatabase.DatabaseCachePercentHit
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Active Directory Replication

Description
Returns a list of pending replication jobs on a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\MicrosoftActiveDirectory")
Set colReplicationOperations = objWMIService.ExecQuery _
        ("Select * from MSAD_ReplPendingOp")
If colReplicationOperations.Count = 0 Then
    Wscript.Echo "There are no replication jobs pending."
    Wscript.Quit
Else
    For each objReplicationJob in colReplicationOperations
        Wscript.Echo objReplicationJob.SerialNumber
        Wscript.Echo objReplicationJob.TimeEnqueued
        Wscript.Echo objReplicationJob.DsaDN
        Wscript.Echo objReplicationJob.DsaAddress
        Wscript.Echo objReplicationJob.NamingContextDn
    Next
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Domain Controller Performance

Description
Monitors the performance of an Active Directory domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDatabases = objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_NTDS_NTDS")
For Each objADDatabase in colDatabases
    Wscript.Echo objADDatabase.DSThreadsInUse
    Wscript.Echo objADDatabase.LDAPBindTime
    Wscript.Echo objADDatabase.LDAPClientSessions
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring FRS Replication

Description
Uses cooked performance counters to monitor File Replication Service performance on a domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFRSSet = objWMIService.ExecQuery _
 ("Select * from Win32_PerfFormattedData_FileReplicaConn_FileReplicaConn")
For Each objFRSInstance in colFRSSet
    Wscript.Echo objFRSInstance.RemoteChangeOrdersReceived
    Wscript.Echo objFRSInstance.RemoteChangeOrdersSent
    Wscript.Echo objFRSInstance.PacketsSent
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Event Logs

Description
Creates a temporary event consumer that monitors event logs for events with an event ID of 533.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate, (Security)}!\\" & _
        strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("Select * from __instancecreationevent where " _
        & "TargetInstance isa 'Win32_NTLogEvent' " _
            & "and TargetInstance.EventCode = '533' ")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
        strAlertToSend = objLatestEvent.TargetInstance.User _
            & " attempted to access DatabaseServer."
        Wscript.Echo strAlertToSend
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Baseline Performance Monitoring

Description
Uses cooked performance counters and the SWbemRefresher object to monitor three performance counters on a computer, and save that data to a text file.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ForAppending = 8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objMemory = objRefresher.AddEnum _
  (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
Set objDiskSpace = objRefresher.AddEnum _
  (objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet
Set objQueueLength = objRefresher.AddEnum _
  (objWMIService, "Win32_PerfFormattedData_PerfNet_ServerWorkQueues").objectSet
objRefresher.Refresh
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile _
  ("c:\scripts\performance.csv", ForAppending, True)
For I = 1 to 10
  For each intAvailableBytes in objMemory
      objLogFile.Write(intAvailableBytes.AvailableMBytes) & ","
  Next
  For each intQueueLength in objDiskSpace
      objLogFile.Write(intQueueLength.CurrentDiskQueueLength) & ","
  Next
  For each intServerQueueLength in objQueueLength
      objLogFile.Write(intServerQueueLength.QueueLength) & ","
  Next
  objLogFile.Write VbCrLf
  Wscript.Sleep 10000
  objRefresher.Refresh
Next
objLogFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining System Uptime

Description
Calculates system uptime; that is, the number of hours a computer has been running since its last restart.

For more information about the Win32_OperatingSystem class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOS in colOperatingSystems
    dtmBootup = objOS.LastBootUpTime
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
    dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
    Wscript.Echo dtmSystemUptime
Next

Function WMIDateStringToDate(dtmBootup)
    WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
             Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
                 & " " & Mid (dtmBootup, 9, 2) & ":" & _
                     Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup, _
                         13, 2))
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Available Disk Space

Description
Issues an alert if free disk space for any hard drive on a computer falls below 100 megabytes.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const LOCAL_HARD_DISK = 3
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredDisks = objWMIService.ExecNotificationQuery _
    ("Select * from __instancemodificationevent within 30 where " _
        & "TargetInstance isa 'Win32_LogicalDisk'")
i = 0
Do While i = 0
    Set objDiskChange = colMonitoredDisks.NextEvent
    If objDiskChange.TargetInstance.DriveType = LOCAL_HARD_DISK Then
        If objDiskChange.TargetInstance.Size < 100000000 Then
            Wscript.Echo "Hard disk space is below 100000000 bytes."
        End If
    End If
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Available Memory

Description
Issues an alert if available memory on a computer falls below 4 megabytes.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set objMemory = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
objRefresher.Refresh
Do
    For each intAvailableBytes in objMemory
        If intAvailableBytes.AvailableMBytes < 4 Then
            Wscript.Echo "Available memory has fallen below 4 megabytes."
        End If
    Next
    objRefresher.Refresh
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Changes in Computer Power Status

Description
Issues an alert if a computer changes power state (for example, enters or leaves suspend mode).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set colMonitoredEvents = GetObject("winmgmts:")._
    ExecNotificationQuery("Select * from Win32_PowerManagementEvent")
Do
    Set strLatestEvent = colMonitoredEvents.NextEvent
    Wscript.Echo strLatestEvent.EventType
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Changes in Service Status

Description
Temporary event consumer that issues an alert any time a service changes status (for example, an active service that is paused or stopped).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService. _
    ExecNotificationQuery("Select * from __instancemodificationevent " _
        & "within 30 where TargetInstance isa 'Win32_Service'")
i = 0
Do While i = 0
    Set objService = colServices.NextEvent
    If objService.TargetInstance.State <> _
        objService.PreviousInstance.State Then
        Wscript.Echo objService.TargetInstance.Name _
            &  " is " & objService.TargetInstance.State _
                & ". The service previously was " & _
                    objService.PreviousInstance.State & "."
    End If
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Computer Availability

Description
Uses the Win32_PingStatus class to verify that a computer is accessible over the network.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery _
    ("Select * from Win32_PingStatus Where Address = '192.168.1.37'")
For each objComputer in colPingedComputers
    If objComputer.StatusCode = 0 Then
        Wscript.Echo "Remote computer responded."
    Else
        Wscript.Echo "Remote computer did not respond."
   End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Disk Bytes Per Second

Description
Uses cooked performance counters to monitor disk bytes per second on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDiskDrives = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet
objRefresher.Refresh
For i = 1 to 500
    For Each objDiskDrive in colDiskDrives
    Wscript.Echo "Drive name: " & objDiskDrive.Name
    Wscript.Echo "Disk bytes per second: " & objDiskDrive.DiskBytesPerSec
    Wscript.Sleep 2000
    objRefresher.Refresh
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Disk Drive Free Space

Description
Uses cooked performance counters to retrieve free disk space on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk where " _
        & "Name <> '_Total'")
For Each objDiskDrive in colDiskDrives
    Wscript.Echo "Drive Name: " & objDiskDrive.Name
    Wscript.Echo "Free Space: " & objDiskDrive.FreeMegabytes
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Processor Use

Description
Uses cooked performance counters to monitor processor use on a computer. Triggers an alert if processor use exceeds 90 percent on 10 successive measurements (measured at 6-second intervals).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objProcessor = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet
intThresholdViolations = 0
objRefresher.Refresh
Do
    For each intProcessorUse in objProcessor
        If intProcessorUse.PercentProcessorTime > 90 Then
            intThresholdViolations = intThresholdViolations + 1
                If intThresholdViolations = 10 Then
                    intThresholdViolations = 0
                    Wscript.Echo "Processor usage threshold exceeded."
                End If
        Else
            intThresholdViolations = 0
        End If
    Next
    Wscript.Sleep 6000
    objRefresher.Refresh
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Process Availability

Description
Identifies whether or not a hypothetical process Database.exe is running.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Database.exe'")
If colProcesses.Count = 0 Then
    Wscript.Echo "Database.exe is not running."
Else
    Wscript.Echo "Database.exe is running."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Process Creation

Description
Temporary event consumer that issues an alert each time a new process is created.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("select * from __instancecreationevent " _
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    Wscript.Echo objLatestProcess.TargetInstance.Name
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Process Deletion

Description
Temporary event consumer that issues an alert each time a process terminates.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("select * from __instancedeletionevent " _
            & "within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    Wscript.Echo objLatestProcess.TargetInstance.Name
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Processor Use by Process

Description
Reports processor use time, in seconds, for each process running on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process")
For Each objProcess in colProcesses
    sngProcessTime = ( CSng(objProcess.KernelModeTime) + _
            CSng(objProcess.UserModeTime)) / 10000000
    Wscript.echo objProcess.name & VbTab & sngProcessTime
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Process Performance

Description
Reports statistics such as thread count and working set size for all processes running on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process")
For Each objProcess in colProcessList
    Wscript.Echo "Process: " & objProcess.Name
    Wscript.Echo "Process ID: " & objProcess.ProcessID
    Wscript.Echo "Thread Count: " & objProcess.ThreadCount
    Wscript.Echo "Page File Size: " & objProcess.PageFileUsage
    Wscript.Echo "Page Faults: " & objProcess.PageFaults
    Wscript.Echo "Working Set Size: " & objProcess.WorkingSetSize
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Permanent Event Consumer

Description
Creates a permanent event consumer for monitoring changes in service status.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
Set objConsumerType = objWMIService.get("SMTPEventConsumer")
Set objConsumer = objConsumerType.SpawnInstance_
objConsumer.Name = "Service Monitor Consumer"
objConsumer.Message = "A service has changed state."
objConsumer.SMTPServer = "mailserver.fabrikam.com"
objConsumer.Subject = "Service state change"
objConsumer.ToLine = "administrator@fabrikam.com"
objConsumer.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Permanent Event Filter

Description
Creates a permanent event filter for monitoring changes in service status.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default")
strFilterQuery = "Select * from __InstanceModificationEvent within 3 " & _
    "where TargetInstance isa 'Win32_Service'"
Set objFilterClass = objWMIService.get("__EventFilter")
Set objFilter = objFilterClass.SpawnInstance_
objFilter.Name = "Service Monitor Filter"
objFilter.QueryLanguage = "wql"
objFilter.Query = strFilterQuery
objFilter.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an Active Directory Site

Description
Creates an Active Directory site and sets the site link for the new site.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSiteRDN      = "cn=Ga-Atl-Sales"
strSiteLinkRDN  = "cn=DEFAULTIPSITELINK"
strSiteLinkType = "IP"                      ' Valid values: "IP" or "SMTP"

Const ADS_PROPERTY_APPEND = 3

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")
strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC

Set objSitesContainer = GetObject(strSitesContainer)

Set objSite = objSitesContainer.Create("site", strSiteRDN)
objSite.SetInfo

Set objLicensingSiteSettings = objSite.Create("licensingSiteSettings", _
    "cn=Licensing Site Settings")
objLicensingSiteSettings.SetInfo

Set objNtdsSiteSettings = objSite.Create("nTDSSiteSettings", _
     "cn=NTDS Site Settings")
objNtdsSiteSettings.SetInfo

Set objServersContainer = objSite.Create("serversContainer", "cn=Servers")
objServersContainer.SetInfo

strSiteLinkPath = "LDAP://" & strSiteLinkRDN & ",cn=" & strSiteLinkType & _
    ",cn=Inter-Site Transports,cn=Sites," & strConfigurationNC

Set objSiteLink = GetObject(strSiteLinkPath)
objSiteLink.PutEx ADS_PROPERTY_APPEND, "siteList", _
                  Array(objSite.Get("distinguishedName"))
objSiteLink.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an Active Directory Site Link

Description
Creates an Active Directory site link.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSite1Name    = "Ga-Atl-Sales"
strSite2Name    = "Wa-Red-Sales"
strSiteLinkRDN  = "cn=[" & strSite1Name & "][" & strSite2Name & "]"
intCost         = 100
intReplInterval = 60
strDescription  = "[" & strSite1Name & "][" & strSite2Name & "]"

Const ADS_PROPERTY_UPDATE = 2

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSite1DN = "cn=" & strSite1Name & ",cn=Sites," & strConfigurationNC
strSite2DN = "cn=" & strSite2Name & ",cn=Sites," & strConfigurationNC

Set objInterSiteTransports = GetObject("LDAP://" & _
    "cn=IP,cn=Inter-Site Transports,cn=Sites," & strConfigurationNC)

Set objSiteLink = objInterSiteTransports.Create("siteLink", strSiteLinkRDN)
objSiteLink.Put "cost",         intCost
objSiteLink.Put "replInterval", intReplInterval
objSiteLink.Put "description",  strDescription

objSiteLink.PutEx ADS_PROPERTY_UPDATE, "siteList", _
                  Array(strSite1DN, strSite2DN)
objSiteLink.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an Active Directory Subnet

Description
Creates an Active Directory subnet.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSubnetRDN     = "cn=192.168.1.0/26"
strSiteObjectRDN = "cn=Ga-Atl-Sales"
strDescription   = "192.168.1.0/255.255.255.192"
strLocation      = "USA/GA/Atlanta"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSiteObjectDN = strSiteObjectRDN & ",cn=Sites," & strConfigurationNC

strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)

Set objSubnet = objSubnetsContainer.Create("subnet", strSubnetRDN)
objSubnet.Put "siteObject",  strSiteObjectDN
objSubnet.Put "description", strDescription

objSubnet.Put "location",    strLocation
objSubnet.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting an Active Directory Subnet

Description
Deletes an Active Directory subnet.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSubnetCN = "cn=192.168.1.0/26"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)
objSubnetsContainer.Delete "subnet", strSubnetCN

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining if a Domain Controller is in a Site

Description
Checks if a domain controller is in a specific Active Directory site.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strDcName = "atl-dc-01"
strSiteName = "ga-atl-sales"

Set objADSysInfo = CreateObject("ADSystemInfo")
strDcSiteName = objADSysInfo.GetDCSiteName(strDcName)

If UCase(strSiteName) = UCase(strDcSiteName) Then
    WScript.Echo "TRUE: " & strDcName & " is in site " & strSiteName
Else
    WScript.Echo "FALSE: " & strDcName & " is NOT in site " & strSiteName
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Protocols Over Which a Bridgehead Server Replicates

Description
Reads the bridgeheadTransportList from a domain controller in a site.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

Set objServer = GetObject _
    ("LDAP://CN=SEA-DC-01,CN=Servers,CN=Default-First-Site-Name,"  & _
        " CN=Sites,CN=Configuration,DC=fabrikam,DC=com")

dnBHTList = objServer.GetEx("bridgeheadTransportList")

WScript.Echo "Bridge Head Transport List:"
WScript.Echo "This multi-valued attribute lists the protocol" & _
    "transports over which this BridgeHead Server replicates"
For Each dnValue in dnBHTList
    WScript.Echo dnValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All Domain Controllers

Description
Returns a list of all the domain controllers in the fabrikam.com domain.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection

objCommand.CommandText = _
    "Select distinguishedName from 'LDAP://cn=Configuration,DC=fabrikam,DC=com' " _
        & "where objectClass='nTDSDSA'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo "Computer Name: " & objRecordSet.Fields("distinguishedName").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying Your Domain Controller

Description
Returns the name of the domain controller that was used to authenticate the current user of a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objDomain = getObject("LDAP://rootDse")
objDC = objDomain.Get("dnsHostName")
Wscript.Echo objDC

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing Active Directory Connections

Description
Lists Active Directory connections (nTDSConnection objects) for a specified domain controller.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strDcRDN   = "cn=atl-dc-01"
strSiteRDN = "cn=Ga-Atl-Sales"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strNtdsSettingsPath = "LDAP://cn=NTDS Settings," & strDcRDN & _
    ",cn=Servers," & strSiteRDN & ",cn=Sites," & strConfigurationNC

Set objNtdsSettings = GetObject(strNtdsSettingsPath)

objNtdsSettings.Filter = Array("nTDSConnection")

WScript.Echo strDcRDN & " NTDS Connection Objects" & vbCrLf & _
    String(Len(strDcRDN) + 24, "=")

For Each objConnection In objNtdsSettings
    WScript.Echo "Name:      " & objConnection.Name
    WScript.Echo "Enabled:   " & objConnection.enabledConnection
    WScript.Echo "From:      " & Split(objConnection.fromServer, ",")(1)
    WScript.Echo "Options:   " & objConnection.Options
    WScript.Echo "Transport: " & Split(objConnection.transportType, ",")(0)
    WScript.Echo "Naming Contexts"
    WScript.Echo "---------------"
    For Each objDNWithBin In objConnection.GetEx("ms-DS-ReplicatesNCReason")
        Wscript.Echo objDNWithBin.DNString
    Next
    WScript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing Active Directory Sites

Description
Lists Active Directory sites.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
Set objSitesContainer = GetObject(strSitesContainer)

objSitesContainer.Filter = Array("site")

For Each objSite In objSitesContainer
    WScript.Echo objSite.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing Servers in an Active Directory Site

Description
Lists servers in a specified Active Directory site.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSiteRDN = "cn=Ga-Atl-Sales"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strServersPath = "LDAP://cn=Servers," & strSiteRDN & ",cn=Sites," & _
    strConfigurationNC

Set objServersContainer = GetObject(strServersPath)

For Each objServer In objServersContainer
    WScript.Echo objServer.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing the Subnets in all Active Directory Sites

Description
Lists subnets in all Active Directory sites. STDOUT is formatted as a comma-separated values file to accommodate redirecting to a file format compatible with Excel.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSubnetsContainer = "LDAP://cn=Subnets,cn=Sites," & strConfigurationNC

Set objSubnetsContainer = GetObject(strSubnetsContainer)

objSubnetsContainer.Filter = Array("subnet")

Set objHash = CreateObject("Scripting.Dictionary")

For Each objSubnet In objSubnetsContainer
    objSubnet.GetInfoEx Array("siteObject"), 0
    strSiteObjectDN = objSubnet.Get("siteObject")
    strSiteObjectName = Split(Split(strSiteObjectDN, ",")(0), "=")(1)

    If objHash.Exists(strSiteObjectName) Then
        objHash(strSiteObjectName) = objHash(strSiteObjectName) & "," & _
            Split(objSubnet.Name, "=")(1)
    Else
        objHash.Add strSiteObjectName, Split(objSubnet.Name, "=")(1)
    End If
Next

For Each strKey In objHash.Keys
    WScript.Echo strKey & "," & objHash(strKey)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing the Subnets in an Active Directory Site

Description
Lists subnets in a specified Active Directory site.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSiteRDN = "cn=Ga-Atl-Sales"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitePath = "LDAP://" & strSiteRDN & ",cn=Sites," & strConfigurationNC

Set objSite = GetObject(strSitePath)

objSite.GetInfoEx Array("siteObjectBL"), 0
arrSiteObjectBL = objSite.GetEx("siteObjectBL")

WScript.Echo strSiteRDN & " Subnets" & vbCrLf & _
    String(Len(strSiteRDN) + 8, "-")

For Each strSiteObjectBL In arrSiteObjectBL
    WScript.Echo Split(Split(strSiteObjectBL, ",")(0), "=")(1)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a Domain Controller to a New Active Directory Site

Description
Moves a domain controller from one Active Directory site (strSourceSiteRDN) to another Active Directory site (strTargetSiteRDN).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strSourceSiteRDN = "cn=Default-First-Site-Name"
strTargetSiteRDN = "cn=Ga-Atl-Sales"
strDcRDN         = "cn=atl-dc-01"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strDcPath = "LDAP://" & strDcRDN & ",cn=Servers," & strSourceSiteRDN & _
    ",cn=Sites," & strConfigurationNC

strTargetSitePath = "LDAP://cn=Servers," & strTargetSiteRDN & _
    ",cn=Sites," & strConfigurationNC

Set objTargetSite = GetObject(strTargetSitePath)
objTargetSite.MoveHere strDcPath, strDcRDN

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming an Active Directory Site

Description
Renames an Active Directory site.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strOldSiteRDN = "cn=Default-First-Site-Name"
strNewSiteRDN = "cn=Ga-Atl-Sales"

Set objRootDSE = GetObject("LDAP://RootDSE")
strConfigurationNC = objRootDSE.Get("configurationNamingContext")

strSitesContainer = "LDAP://cn=Sites," & strConfigurationNC
strOldSitePath = "LDAP://" & strOldSiteRDN & ",cn=Sites," & strConfigurationNC

Set objSitesContainer = GetObject(strSitesContainer)
objSitesContainer.MoveHere strOldSitePath, strNewSiteRDN

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Domain Controller Site Name

Description
Reports the site name for a specified domain controller (or computer).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strDcName = "atl-dc-01"
Set objADSysInfo = CreateObject("ADSystemInfo")
strDcSiteName = objADSysInfo.GetDCSiteName(strDcName)
WScript.Echo "DC Site Name: " & strDcSiteName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Site Name for the Local Computer

Description
Reports the site name for the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objADSysInfo = CreateObject("ADSystemInfo")
WScript.Echo "Current site name: " & objADSysInfo.SiteName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using WMI to Retrieve Domain Information

Description
Retrieves information about domains discovered on the network.

For more information about the Win32_NTDomain class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTDomain")
For Each objItem in colItems
    Wscript.Echo "Client Site Name: " & objItem.ClientSiteName
    Wscript.Echo "DC Site Name: " & objItem.DcSiteName
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Dns Forest Name: " & objItem.DnsForestName
    Wscript.Echo "Domain Controller Address: " & objItem.DomainControllerAddress
    Wscript.Echo "Domain Controller Address Type: " & _
        objItem.DomainControllerAddressType
    Wscript.Echo "Domain Controller Name: " & objItem.DomainControllerName
    Wscript.Echo "Domain Guid: " & objItem.DomainGuid
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "DS Directory Service Flag: " & objItem.DSDirectoryServiceFlag
    Wscript.Echo "DS DNS Controller Flag: " & objItem.DSDnsControllerFlag
    Wscript.Echo "DS DNS Domain Flag: " & objItem.DSDnsDomainFlag
    Wscript.Echo "DS DNS Forest Flag: " & objItem.DSDnsForestFlag
    Wscript.Echo "DS Global Catalog Flag: " & objItem.DSGlobalCatalogFlag
    Wscript.Echo "DS Kerberos Distribution Center Flag: " & _
        objItem.DSKerberosDistributionCenterFlag
    Wscript.Echo "DS Primary Domain Controller Flag: " & _
        objItem.DSPrimaryDomainControllerFlag
    Wscript.Echo "DS Time Service Flag: " & objItem.DSTimeServiceFlag
    Wscript.Echo "DS Writable Flag: " & objItem.DSWritableFlag
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Primary Owner Contact: " & objItem.PrimaryOwnerContact
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring a Static IP Address

Description
Sets the IP address of a computer to 192.168.1.141, and sets the IP gateway to 192.168.1.100.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)

For Each objNetAdapter in colNetAdapters
    errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
    errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    If errEnable = 0 Then
        WScript.Echo "The IP address has been changed."
    Else
        WScript.Echo "The IP address could not be changed."
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring ARP Queries to Use EtherSNAP

Description
Configures the network adapters on a computer to use 802.3 SNAP encoding for Ethernet packets.

For more information about the SetArpUseEtherSNAP method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetArpUseEtherSNAP(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring ARP Queries to Use Source Routing

Description
Configures TCP/IP to always use source routing on all Token Ring networks.

For more information about the SetArpAlwaysSourceRoute method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetArpAlwaysSourceRoute(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Dynamic DNS Registration for a Network Adapter

Description
Configures dynamic DNS registration for a network adapter.

For more information about the SetDynamicDNSRegistration method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next

Const FULL_DNS_REGISTRATION = True
Const DOMAIN_DNS_REGISTRATION = False

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    objNetCard.SetDynamicDNSRegistration _
        FULL_DNS_REGISTRATION, DOMAIN_DNS_REGISTRATION
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring NetBIOS Use on a Network Adapter

Description
Enables NetBIOS for a network adapter. To enable NetBIOS via DHCP, pass the value 0 to the SetTCPIPNetBIOS method (rather than the value 1). Pass the value 2 to disable NetBIOS.

For more information about the SetTCPIPNetBIOS method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    objNetCard.SetTCPIPNetBIOS(1)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the DNS Domain for a Network Adapter

Description
Sets the DNS domain for a TCP/IP-bound network adapter.

For more information about the SetDNSDomain method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    Wscript.Echo objNetCard.SetDNSDomain("fabrikam.com")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the DNS Server Search Order for a Network Adapter

Description
Configures a TCP/IP-bound network adapter to use two DNS servers: 192.168.1.100 and 192.168.1.200. Note that even if a computer only uses one DNS server, the IP address of that server must still be passed to the SetDNSServerSearchOrder method as an array (in that case, an array with only one element).

For more information about the SetDNSServerSearchOrder method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    arrDNSServers = Array("192.168.1.100", "192.168.1.200")
    objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the DNS Suffix Search Order for All Network Adapters

Description
Configure a computer to use two DNS suffixes -- hr.fabrikam.com and research.fabrikam.com -- when performing DNS searches. Note that even if a computer uses only a single DNS suffix, this value must still be passed to the SetDNSSuffixSearchOrder method as an array (in that case, an array with a single element).

For more information about the SerDNSSuffixSearchOrder method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
arrDNSSuffixes = Array("hr.fabrikam.com", "research.fabrikam.com")
objNetworkSettings.SetDNSSuffixSearchOrder(arrDNSSuffixes)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Forward Buffer Memory for All Network Adapters

Description
Configures the forward buffer memory for all network adapters on a computer. Values should be supplied in multiples of 256.

For more information about the SetForwardBufferMemory method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetForwardBufferMemory(74240)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Gateways for a Network Adapter

Description
Configures two gateways -- 102.168.1.100 and 192.168.1.200 -- for a network adapter. Note that even if only one gateway is specified, the IP address for that gateway must be passed as part of an array (in that case, an array with only a single element).

For more information about the SetGateways method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    arrGateways = Array("192.168.1.100", "192.168.1.200")
    objNetCard.SetGateways(arrGateways)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the IGMP Level for All Network Adapters

Description
Disables IGMP multicasting on a computer. To enable IP multicasting, pass the value 1 to the SetIGMPLevel method. Pass the value 2 to allow both IP and IGMP multicasting.

For more information about the SetIGMPLevel method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIGMPLevel(0)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Number of Allowed Forward Packets

Description
Configures the number of forward packets allocated to the router packet queue. Valid values range from 1 to 0xFFFFFFFE.

For more information about the SetNumForwardPackets method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetNumForwardPackets(1)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the IP Connection Metric for a Network Adapter

Description
Sets the IP connection metric for a network adapter to 100. Connection metrics can range from 1 to 9,999, with a default value of 1.

For more information about the SetIPConnectionMetric method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    objNetCard.SetIPConnectionMetric(100)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the IPX Frame Type

Description
Configures the IPX network number and frame type for a network adapter. In this case, the frame type is set to AUTO (value of 255). Because the frame type is set to AUTO, the network number must be set to 0. Note that both the network number and the frame types must be passed as arrays, even if there is only a single element (for example, one frame type).

For more information about the SetIPXFrameTypeNetworkPairs method used in this script (including a list of allowable frame types and their values), click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next

Const AUTO = 255
Const NETWORK_NUMBER = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    arrNetworkNumber = Array(NETWORK_NUMBER)
    arrFrameTypes = Array(AUTO)
    objNetCard.SetIPXFrameTypeNetworkPairs arrNetworkNumber, arrFrameTypes
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the IPX Virtual Network Number

Description
Sets the IPX internal network number of a computer to network number 5.

For more information about the SetIPXVirtualNetworkNumber method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIPXVirtualNetworkNumber(5)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Keep Alive Interval for all Network Adapters

Description
Configures the keep alive interval for all network adapters on a computer to 300,00 milliseconds (5 minutes).

For more information about the SetKeepAliveInterval method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetKeepAliveInterval(300000)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the MTU for all Network Adapters

Description
Configures the maximum transmission unit for all network adapters installed in a computer. Valid values range from a minimum of 68 bytes to the maximum number of bytes supported by the network.

For more information about the SetMTU method used in this script, click here.

Supported Platforms

Windows Server 2003 | No
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetMTU(68)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the WINS Server for a Network Adapter

Description
Sets the primary and secondary WINS server for a TCP/IP-bound network adapter.

For more information about the SetWINSServer method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    strPrimaryServer = "192.168.1.100"
    strSecondaryServer = "192.168.1.200"
    objNetCard.SetWINSServer strPrimaryServer, strSecondaryServer
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Zero-Broadcast Use for All Network Adapters

Description
Configures a computer to use zero-broadcasts (0.0.0.0) rather than one-broadcasts (255.255.255.255). Zero-broadcasts are the default used on systems derived from BSD implementations.

For more information about the SetIPUseZeroBroadcast method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetIPUseZeroBroadcast(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining a Computer's IP Address

Description
Returns the IP address for each IP-enabled network adapter installed in a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
    ("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
            WScript.Echo IPConfig.IPAddress(i)
        Next
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Dead Gateway Detection for All Network Adapters

Description
Configures all network adapters on a computer to automatically detect dead gateways.

For more information about the SetDeadGWDetect method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetDeadGWDetect(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling DHCP

Description
Enables the DHCP client service on a computer. The computer will then use DHCP to obtain an IP address rather than use a static IP address.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each objNetAdapter In colNetAdapters
    errEnable = objNetAdapter.EnableDHCP()
    If errEnable = 0 Then
        Wscript.Echo "DHCP has been enabled."
    Else
        Wscript.Echo "DHCP could not be enabled."
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling DNS on All Network Adapters

Description
Enables DNS for all network adapters on a computer, configuring the host name to fabrikam1 and designating hr.fabrikam.com and research.fabrikam.com as DNS search order suffixes.

For more information about the EnableDNS method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
strHostName = "fabrikam1"
arrDNSSuffixes = Array("hr.fabrikam.com", "research.fabrikam.com")
objNetworkSettings.EnableDNS strHostName, , , arrDNSSuffixes

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling IPFilter Security on All Network Adapters

Description
Enables IP filter security for all the network adapters installed in a computer.

For more information about the EnableIPFilterSec method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.EnableIPFilterSec(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling IPSec on a Network Adapter

Description
Enables IP security for a network adapter. In this script, all TCP and UDP ports as well as all IP protocols are allowed; hence the value 0 is passed to the EnableIPSec method in each case. If only specific ports or protocols are allowed, these should be passed in the form of arrays.

For more information about the EnableIPSec method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next

Const ALLOW_ALL = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    arrPermittedTCPPorts = Array(ALLOW_ALL)
    arrPermittedUDPPorts = Array(ALLOW_ALL)
    arrPermittedIPProtocols = Array(ALLOW_ALL)
    objNetCard.EnableIPSec _
        arrPermittedTCPPorts, arrPermittedUDPPorts, arrPermittedIPProtocols
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling WINS for All Network Adapters

Description
Enables WINS on all the network adapters installed in a computer.

For more information about the EnableWINS method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next

Const DNS_ENABLED_FOR_WINS_RESOLUTION = True
Const USE_LMHOST_FILE = False
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
errResult = objNetworkSettings.EnableWINS _
    (DNS_ENABLED_FOR_WINS_RESOLUTION, USE_LMHOST_FILE)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling PMTU Discovery on all Network Adapters

Description
Enables a computer to automatically discover the maximum transmission unit on a network. To disable auto-discovery of the maximum transmission unit, pass the value False to the SetPMTUDiscovery method.

For more information about the SetPMTUDiscovery method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetPMTUDiscovery(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Network Adapter Properties

Description
Enumerates property values for all the network adapters installed on a computer.

For more information about the Win32_NetworkAdapter class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48)
For Each objItem in colItems
    Wscript.Echo "Adapter Type: " & objItem.AdapterType

    Select Case objItem.AdapterTypeID
        Case 0 strAdapterType = "Ethernet 802.3"
        Case 1 strAdapterType = "Token Ring 802.5"
        Case 2 strAdapterType = "Fiber Distributed Data Interface (FDDI)"
        Case 3 strAdapterType = "Wide Area Network (WAN)"
        Case 4 strAdapterType = "LocalTalk"
        Case 5 strAdapterType = "Ethernet using DIX header format"
        Case 6 strAdapterType = "ARCNET"
        Case 7 strAdapterType = "ARCNET (878.2)"
        Case 8 strAdapterType = "ATM"
        Case 9 strAdapterType = "Wireless"
        Case 10 strAdapterType = "Infrared Wireless"
        Case 11 strAdapterType = "Bpc"
        Case 12 strAdapterType = "CoWan"
        Case 13 strAdapterType = "1394"
    End Select

    Wscript.Echo "Adapter Type Id: " & strAdapterType
    Wscript.Echo "AutoSense: " & objItem.AutoSense
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Index: " & objItem.Index
    Wscript.Echo "MAC Address: " & objItem.MACAddress
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Maximum Number Controlled: " & objItem.MaxNumberControlled
    Wscript.Echo "Maximum Speed: " & objItem.MaxSpeed
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Net Connection ID: " & objItem.NetConnectionID
    Wscript.Echo "Net Connection Status: " & objItem.NetConnectionStatus
    For Each strNetworkAddress in objItem.NetworkAddresses
        Wscript.Echo "NetworkAddress: " & strNetworkAddress
    Next
    Wscript.Echo "Permanent Address: " & objItem.PermanentAddress
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
    Wscript.Echo "Product Name: " & objItem.ProductName
    Wscript.Echo "Service Name: " & objItem.ServiceName
    Wscript.Echo "Speed: " & objItem.Speed
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Network Adapter Configuration Properties

Description
Enumerates configuration information for all the network adapters installed on a computer.

For more information about the Win32_NetworkAdapterConfiguration class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
    Wscript.Echo "ARP Always Source Route: " & objItem.ArpAlwaysSourceRoute
    Wscript.Echo "ARP Use EtherSNAP: " & objItem.ArpUseEtherSNAP
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Database Path: " & objItem.DatabasePath
    Wscript.Echo "Dead GW Detection Enabled: " & objItem.DeadGWDetectEnabled
    Wscript.Echo "Default IP Gateway: " & objItem.DefaultIPGateway
    Wscript.Echo "Default TOS: " & objItem.DefaultTOS
    Wscript.Echo "Default TTL: " & objItem.DefaultTTL
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "DHCP Enabled: " & objItem.DHCPEnabled
    Wscript.Echo "DHCP Lease Expires: " & objItem.DHCPLeaseExpires
    Wscript.Echo "DHCP Lease Obtained: " & objItem.DHCPLeaseObtained
    Wscript.Echo "DHCP Server: " & objItem.DHCPServer
    Wscript.Echo "DNS Domain: " & objItem.DNSDomain
    Wscript.Echo "DNS Domain Suffix Search Order: " & _
        objItem.DNSDomainSuffixSearchOrder
    Wscript.Echo "DNS Enabled For WINS Resolution: " & _
        objItem.DNSEnabledForWINSResolution
    Wscript.Echo "DNS Host Name: " & objItem.DNSHostName
    Wscript.Echo "DNS Server Search Order: " & objItem.DNSServerSearchOrder
    Wscript.Echo "Domain DNS Registration Enabled: " & _
        objItem.DomainDNSRegistrationEnabled
    Wscript.Echo "Forward Buffer Memory: " & objItem.ForwardBufferMemory
    Wscript.Echo "Full DNS Registration Enabled: " & _
        objItem.FullDNSRegistrationEnabled
    Wscript.Echo "Gateway Cost Metric: " & objItem.GatewayCostMetric
    Wscript.Echo "IGMP Level: " & objItem.IGMPLevel
    Wscript.Echo "Index: " & objItem.Index
    Wscript.Echo "IP Address: " & objItem.IPAddress
    Wscript.Echo "IP Connection Metric: " & objItem.IPConnectionMetric
    Wscript.Echo "IP Enabled: " & objItem.IPEnabled
    Wscript.Echo "IP Filter Security Enabled: " & _
        objItem.IPFilterSecurityEnabled
    Wscript.Echo "IP Port Security Enabled: " & _
        objItem.IPPortSecurityEnabled
    Wscript.Echo "IPSec Permit IP Protocols: " & _
        objItem.IPSecPermitIPProtocols
    Wscript.Echo "IPSec Permit TCP Ports: " & objItem.IPSecPermitTCPPorts
    Wscript.Echo "IPSec Permit UDP Ports: " & objItem.IPSecPermitUDPPorts
    Wscript.Echo "IP Subnet: " & objItem.IPSubnet
    Wscript.Echo "IP Use Zero Broadcast: " & objItem.IPUseZeroBroadcast
    Wscript.Echo "IPX Address: " & objItem.IPXAddress
    Wscript.Echo "IPX Enabled: " & objItem.IPXEnabled
    Wscript.Echo "IPX Frame Type: " & objItem.IPXFrameType
    Wscript.Echo "IPX Media Type: " & objItem.IPXMediaType
    Wscript.Echo "IPX Network Number: " & objItem.IPXNetworkNumber
    Wscript.Echo "IPX Virtual Net Number: " & objItem.IPXVirtualNetNumber
    Wscript.Echo "Keep Alive Interval: " & objItem.KeepAliveInterval
    Wscript.Echo "Keep Alive Time: " & objItem.KeepAliveTime
    Wscript.Echo "MAC Address: " & objItem.MACAddress
    Wscript.Echo "MTU: " & objItem.MTU
    Wscript.Echo "Number of Forward Packets: " & objItem.NumForwardPackets
    Wscript.Echo "PMTUBH Detect Enabled: " & objItem.PMTUBHDetectEnabled
    Wscript.Echo "PMTU Discovery Enabled: " & objItem.PMTUDiscoveryEnabled
    Wscript.Echo "Service Name: " & objItem.ServiceName
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "TCPIP Netbios Options: " & objItem.TcpipNetbiosOptions
    Wscript.Echo "TCP Maximum Connect Retransmissions: " & _
        objItem.TcpMaxConnectRetransmissions
    Wscript.Echo "TCP Maximum Data Retransmissions: " & _
        objItem.TcpMaxDataRetransmissions
    Wscript.Echo "TCP NumC onnections: " & objItem.TcpNumConnections
    Wscript.Echo "TCP Use RFC1122 Urgent Pointer: " & _
        objItem.TcpUseRFC1122UrgentPointer
    Wscript.Echo "TCP Window Size: " & objItem.TcpWindowSize
    Wscript.Echo "WINS Enable LMHosts Lookup: " & _
        objItem.WINSEnableLMHostsLookup
    Wscript.Echo "WINS Host Lookup File: " & objItem.WINSHostLookupFile
    Wscript.Echo "WINS Primary Server: " & objItem.WINSPrimaryServer
    Wscript.Echo "WINS Scope ID: " & objItem.WINSScopeID
    Wscript.Echo "WINS Secondary Server: " & objItem.WINSSecondaryServer
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Network Client Information

Description
Returns information about all the network clients installed on a computer.

For more information about the Win32_NetworkClient class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkClient")
For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Network Login Profiles

Description
Returns network login information for all the users of a computer.

For more information about the Win32_NetworkLoginProfile class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkLoginProfile")
For Each objItem in colItems
    dtmWMIDate = objItem.AccountExpires
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Account Expires: " & strReturn
    Wscript.Echo "Authorization Flags: " & objItem.AuthorizationFlags
    Wscript.Echo "Bad Password Count: " & objItem.BadPasswordCount
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "CodePage: " & objItem.CodePage
    Wscript.Echo "Comment: " & objItem.Comment
    Wscript.Echo "Country Code: " & objItem.CountryCode
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Flags: " & objItem.Flags
    Wscript.Echo "Full Name: " & objItem.FullName
    Wscript.Echo "Home Directory: " & objItem.HomeDirectory
    Wscript.Echo "Home Directory Drive: " & objItem.HomeDirectoryDrive
    dtmWMIDate = objItem.LastLogoff
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Last Logoff: " & strReturn
    dtmWMIDate = objItem.LastLogon
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Last Logon: " & strReturn
    Wscript.Echo "Logon Hours: " & objItem.LogonHours
    Wscript.Echo "Logon Server: " & objItem.LogonServer
    Wscript.Echo "Maximum Storage: " & objItem.MaximumStorage
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Number Of Logons: " & objItem.NumberOfLogons
    Wscript.Echo "Password Age: " & objItem.PasswordAge
    dtmWMIDate = objItem.PasswordExpires
    strReturn = WMIDateStringToDate(dtmWMIDate)
    Wscript.Echo "Password Expires: " & strReturn
    Wscript.Echo "Primary Group ID: " & objItem.PrimaryGroupId
    Wscript.Echo "Privileges: " & objItem.Privileges
    Wscript.Echo "Profile: " & objItem.Profile
    Wscript.Echo "Script Path: " & objItem.ScriptPath
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Units Per Week: " & objItem.UnitsPerWeek
    Wscript.Echo "User Comment: " & objItem.UserComment
    Wscript.Echo "User Id: " & objItem.UserId
    Wscript.Echo "User Type: " & objItem.UserType
    Wscript.Echo "Workstations: " & objItem.Workstations
    Wscript.Echo
Next

Function WMIDateStringToDate(dtmWMIDate)
    If Not IsNull(dtmWMIDate) Then
    WMIDateStringToDate = CDate(Mid(dtmWMIDate, 5, 2) & "/" & _
         Mid(dtmWMIDate, 7, 2) & "/" & Left(dtmWMIDate, 4) _
             & " " & Mid (dtmWMIDate, 9, 2) & ":" & _
                 Mid(dtmWMIDate, 11, 2) & ":" & Mid(dtmWMIDate, _
                     13, 2))
    End If
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Network Protocols on a Computer

Description
Uses WMI to return information about all the network protocols installed on a computer.

For more information about the Win32_NetworkProtocol class use din this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkProtocol")
For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Connectionless Service: " & objItem.ConnectionlessService
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Guarantees Delivery: " & objItem.GuaranteesDelivery
    Wscript.Echo "Guarantees Sequencing: " & objItem.GuaranteesSequencing
    strInstallDate = WMIDateStringToDate(objItem.InstallDate)
    Wscript.Echo "Install Date: " & strInstallDate
    Wscript.Echo "Maximum Address Size: " & objItem.MaximumAddressSize
    Wscript.Echo "Maximum Message Size: " & objItem.MaximumMessageSize
    Wscript.Echo "Message Oriented: " & objItem.MessageOriented
    Wscript.Echo "Minimum Address Size: " & objItem.MinimumAddressSize
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Pseudo Stream Oriented: " & objItem.PseudoStreamOriented
    Wscript.Echo "Supports Broadcasting: " & objItem.SupportsBroadcasting
    Wscript.Echo "Supports Connect Data: " & objItem.SupportsConnectData
    Wscript.Echo "Supports Disconnect Data: " & objItem.SupportsDisconnectData
    Wscript.Echo "Supports Encryption: " & objItem.SupportsEncryption
    Wscript.Echo "Supports Expedited Data: " & objItem.SupportsExpeditedData
    Wscript.Echo "Supports Fragmentation: " & objItem.SupportsFragmentation
    Wscript.Echo "Supports Graceful Closing: " & _
        objItem.SupportsGracefulClosing
    Wscript.Echo "Supports Guaranteed Bandwidth: " & _
        objItem.SupportsGuaranteedBandwidth
    Wscript.Echo "Supports Multicasting: " & objItem.SupportsMulticasting
    Wscript.Echo "Supports Quality of Service: " & _
        objItem.SupportsQualityofService
Next

Function WMIDateStringToDate(dtmDate)
    WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
         Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
         & " " & Mid (dtmDate, 9, 2) & ":" & _
         Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate, _
         13, 2))
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pinging Multiple Computers

Description
Uses the Win32_PingStatus class to ping 4 computers and identify the computers that could not be reached over the network. This script was contributed by Maxim Stepin of Microsoft.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strMachines = "atl-dc-01;atl-win2k-01;atl-nt4-01;atl-dc-02"
aMachines = split(strMachines, ";")

For Each machine in aMachines
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
        ExecQuery("select * from Win32_PingStatus where address = '"_
            & machine & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
            WScript.Echo("machine " & machine & " is not reachable")
        End If
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Releasing All DHCP Leases

Description
Releases all the DHCP leases currently in use on a computer.

For more information about the ReleaseDHCPLeaseAll method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.ReleaseDHCPLeaseAll()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Releasing the DHCP Lease for a Network Adapter

Description
Releases the DHCP leases for all TCP/IP-bound network adapters on a computer.

For more information about the ReleaseDHCPLease method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    objNetCard.ReleaseDHCPLease()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renewing All DHCP Leases

Description
Renews all the DHCP leases currently in use on a computer.

For more information about the RenewDHCPLeaseAll method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.RenewDHCPLeaseAll()

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renewing the DHCP Lease for a Network Adapter

Description
Renews the DHCP lease for each TCP/IP-bound network adapter in a computer.

For more information about the RenewDHCPLease method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objNetCard in colNetCards
    objNetCard.RenewDHCPLease()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving IP4 Route Table Information

Description
Returns information about the IP route tables configured on a computer.

For more information about the Win32_IP4RouteTable class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_IP4RouteTable")
For Each objItem in colItems
    Wscript.Echo "Age: " & objItem.Age
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Destination: " & objItem.Destination
    Wscript.Echo "Information: " & objItem.Information
    Wscript.Echo "Interface Index: " & objItem.InterfaceIndex
    Wscript.Echo "Mask: " & objItem.Mask
    Wscript.Echo "Metric 1: " & objItem.Metric1
    Wscript.Echo "Metric 2: " & objItem.Metric2
    Wscript.Echo "Metric 3: " & objItem.Metric3
    Wscript.Echo "Metric 4: " & objItem.Metric4
    Wscript.Echo "Metric 5: " & objItem.Metric5
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Next Hop: " & objItem.NextHop
    Wscript.Echo "Protocol: " & objItem.Protocol
    Wscript.Echo "Type: " & objItem.Type
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Proxy Server Information

Description
Returns information about the Internet proxy server used by a computer.

For more information about the Win32_Proxy class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Proxy")
For Each objItem in colItems
    Wscript.Echo "Proxy Port Number: " & objItem.ProxyPortNumber
    Wscript.Echo "Proxy Server: " & objItem.ProxyServer
    Wscript.Echo "Server Name: " & objItem.ServerName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning IP Configuration Data

Description
WMI script that returns configuration data similar to that returned by Ipconfig.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

n = 1
WScript.Echo

For Each objAdapter in colAdapters
   WScript.Echo "Network Adapter " & n
   WScript.Echo "================="
   WScript.Echo "  Description: " & objAdapter.Description

   WScript.Echo "  Physical (MAC) address: " & objAdapter.MACAddress
   WScript.Echo "  Host name:              " & objAdapter.DNSHostName

   If Not IsNull(objAdapter.IPAddress) Then
      For i = 0 To UBound(objAdapter.IPAddress)
         WScript.Echo "  IP address:             " & objAdapter.IPAddress(i)
      Next
   End If

   If Not IsNull(objAdapter.IPSubnet) Then
      For i = 0 To UBound(objAdapter.IPSubnet)
         WScript.Echo "  Subnet:                 " & objAdapter.IPSubnet(i)
      Next
   End If

   If Not IsNull(objAdapter.DefaultIPGateway) Then
      For i = 0 To UBound(objAdapter.DefaultIPGateway)
         WScript.Echo "  Default gateway:        " & _
             objAdapter.DefaultIPGateway(i)
      Next
   End If

   WScript.Echo
   WScript.Echo "  DNS"
   WScript.Echo "  ---"
   WScript.Echo "    DNS servers in search order:"

   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
         WScript.Echo "      " & objAdapter.DNSServerSearchOrder(i)
      Next
   End If

   WScript.Echo "    DNS domain: " & objAdapter.DNSDomain

   If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
         WScript.Echo "    DNS suffix search list: " & _
             objAdapter.DNSDomainSuffixSearchOrder(i)
      Next
   End If

   WScript.Echo
   WScript.Echo "  DHCP"
   WScript.Echo "  ----"
   WScript.Echo "    DHCP enabled:        " & objAdapter.DHCPEnabled
   WScript.Echo "    DHCP server:         " & objAdapter.DHCPServer

   If Not IsNull(objAdapter.DHCPLeaseObtained) Then
      utcLeaseObtained = objAdapter.DHCPLeaseObtained
      strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
   Else
      strLeaseObtained = ""
   End If
   WScript.Echo "    DHCP lease obtained: " & strLeaseObtained

   If Not IsNull(objAdapter.DHCPLeaseExpires) Then
      utcLeaseExpires = objAdapter.DHCPLeaseExpires
      strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
   Else
      strLeaseExpires = ""
   End If
   WScript.Echo "    DHCP lease expires:  " & strLeaseExpires

   WScript.Echo
   WScript.Echo "  WINS"
   WScript.Echo "  ----"
   WScript.Echo "    Primary WINS server:   " & objAdapter.WINSPrimaryServer
   WScript.Echo "    Secondary WINS server: " & objAdapter.WINSSecondaryServer
   WScript.Echo

   n = n + 1

Next

Function WMIDateStringToDate(utcDate)
   WMIDateStringToDate = CDate(Mid(utcDate, 5, 2)  & "/" & _
                               Mid(utcDate, 7, 2)  & "/" & _
                               Left(utcDate, 4)    & " " & _
                               Mid (utcDate, 9, 2) & ":" & _
                               Mid(utcDate, 11, 2) & ":" & _
                               Mid(utcDate, 13, 2))
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting Keep Alive Time for All Network Adapters

Description
Configures the keep alive time for all network adapters on a computer to 300,000 milliseconds (5 minutes).

For more information about the SetKeepAliveTime method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetKeepAliveTime(300000)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting PMTUBH Detection on All Network Adapters

Description
Enables the auto-discovery of black hole routers while determining the maximum transmission unit on a network. To disable auto-discovery of black hole routers, pass the value False to the SetPMTUBHDetect method.

For more information about the SetPMTUBHDetect method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetPMTUBHDetect(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Allowed Number of TCP Connections

Description
Sets the maximum allowed number of simultaneously-opened TCP connections on a computer to 10.

For more information about the SetTCPNumConnections method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetTCPNumConnections(10)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Maximum Allowed TCP Connection Retransmissions

Description
Configures the number of times TCP will retransmit a connection attempt before abandoning the effort. Valid values range from 0 to 0xFFFFFFFF.

For more information about the SetTCPMaxConnectRetransmissions method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetTCPMaxConnectRetransmissions(10)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Database Path for all Network Adapters

Description
Sets the path to the standard Internet database files (HOSTS, LMHOSTS, NETWORKS, PROTOCOLS) used by the Windows Sockets interface.

For more information about the SetDatabasePath method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetDatabasePath("c:\windows\system32\drivers\etc")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Default Time-to-Live for All Network Adapters

Description
Sets the default time-to-live value in the header of outgoing IP packets to 64 this represents the number of routers an IP packet can pass through before being discarded). Valid TTL values range from 1 to 255, with a default value of 32.

For more information about the SetDefaultTTL method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetDefaultTTL(64)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Maximum Allowed TCP Data Retransmissions

Description
Configures the number of times TCP will attempt to retransmit an individual data segment before abandoning the effort. Valid values range from 0 to 0xFFFFFFFF.

For more information about the SetTCPMaxDataRetransmissions method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetTCPMaxDataRetransmissions(10)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the TCP Window Size for All Network Adapters

Description
Sets the TCP window size for all network adapters on a computer. Valid windows sizes range from 0 to 65,535 bytes.

For more information about the SetTCPWindowSize method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetTCPWindowSize(65535)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting Urgent Pointer Use for All Network Adapters

Description
Configures a computer to use the RFC 1122 specification for urgent data rather than the mode used by Berkeley Software Design (BSD) derived systems. To use the BSD mode instead, pass the value False to the SetTcpRFC1122UrgentPointer method.

For more information about the SetTcpUseRFC1122UrgentPointer method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objNetworkSettings = objWMIService.Get("Win32_NetworkAdapterConfiguration")
objNetworkSettings.SetTcpUseRFC1122UrgentPointer(True)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Aging All DNS Records

Description
Enables aging of all records (except name server and start of authority records) in the DNS zone accounting.fabrikam.com.

For more information about the AgeAllRecords method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    errResult = objItem.AgeAllRecords(,1)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing the DNS Zone Type

Description
Changes the DNS zone type of the zone accounting.fabrikam.com to a primary DNS zone.

For more information about the ChangeZoneType method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

intPrimaryZone = 1

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    errResult = objItem.ChangeZoneType(intPrimaryZone, true)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing the DNS Server Cache

Description
Clears the DNS server cache of resource records.

For more information about the ClearCache method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * From MicrosoftDNS_Cache")
For Each objItem in colItems
    objItem.ClearCache()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mail Agent for Domain (MD) DNS Record

Description
Creates a mail agent for domain (MD) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "workstation5.fabrikam.com"
intRecordClass = 1
intTTL = 600
strMailAgent = "mailagent.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MDType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, strMailAgent)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mail Forwarding Agent (MF) DNS Record

Description
Creates a mail forwarding agent (MF) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
strMailForwarder = "mailforwarder.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MFType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, _
        intTTL, strMailForwarder)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mail Group (MG) DNS Record

Description
Creates a mail group (MG) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "admin.fabrikam.com"
intRecordClass = 1
intTTL = 600
strMailbox = "netadmins.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MGType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, strMailbox)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mail Information (MI) DNS Record

Description
Creates a mail information (MI) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "administrator.fabrikam.com"
intRecordClass = 1
intTTL = 600
strAdminMailbox = "dnsadmin.fabrikam.com"
strErrorMailbox = "support.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MInfoType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, _
        strAdminMailbox, strErrorMailbox)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mail Exchanger (MX) DNS Record

Description
Creates a mail exchanger (MX) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
intPreference = 0
strMailExchanger = "mailexchanger.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MXType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, _
        intPreference, strMailExchanger)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mailbox (MB) DNS Record

Description
Creates a mailbox (MB) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
strMailboxHost = "admin.mailserver.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MBType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, _
        intTTL, strMailboxHost)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Mailbox Rename (MR) DNS Record

Description
Creates a mailbox rename (MR) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "old-mailbox.fabrikam.com"
intRecordClass = 1
intTTL = 600
strMailbox = "newmailbox.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_MRType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, strMailbox)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Name Server DNS Record

Description
Creates a name server (NS) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
strNSHost = "nameserver.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_NSType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, strNSHost)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Primary DNS Zone

Description
Creates a primary DNS zone named accounting.fabrikam.com on a DNS server.

For more information about the CreateZone method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strZoneName = "accounting.fabrikam.com"
intPrimaryZone = 1

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_Zone")
errResult = objItem.CreateZone(strZoneName, intPrimaryZone)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Responsible Person (RP) DNS Record

Description
Creates a responsible person (RP) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
strRPMAilbox = "admin.fabrikam.com"
strText = "Network Administrator, (555) 555-1219"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_RPType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, _
        intTTL, strRPMailbox, strText)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Route Through (RT) DNS Record

Description
Creates a route through (RT) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
intPreference = 1
strRouter = "router.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_RTType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, _
        intTTL, intPreference, strRouter)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Text (TXT) DNS Record

Description
Creates a text (TXT) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-dc-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
strText = "This domain is reserved for employees of Fabrikam."

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_TXTType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, strText)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Well-Known Services (WKS) DNS Record

Description
Creates a well-known services (WKS) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "ftp.fabrikam.com"
intRecordClass = 1
intTTL = 600
strIPAddress = "192.168.1.150"
strProtocol = "TCP"
strServices = "FTP"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_WKSType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, _
        strIPAddress, strProtocol, strServices)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an Andrew File System Database Server DNS Record

Description
Creates an Andrew File System Database Server (AFSDB) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atl-srv-01.fabrikam.com"
intRecordClass = 1
intTTL = 600
intSubtype = 1
strServerName = "afs.fabrikam.com"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_AFSDBType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, _
        intSubType, strServerName)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an ATM Address to Name (ATMA) DNS Record

Description
Creates an ATM address to name (ATMA) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "atm.fabrikam.com"
intRecordClass = 1
intTTL = 600
intFormat = 1
strATMAddress = "47.0079.00010200000000000000.00a03e000002.00"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_ATMAType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, _
        intFormat, strATMAddress)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an IPv6 Address (AAAA) DNS Record

Description
Creates an IPv6 address record (AAAA) on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "ipv6.fabrikam.com"
intRecordClass = 1
intTTL = 600
strIPv6Address = "4321:0:1:2:3:4:567:89ab"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_AAAAType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, _
        intTTL, strIPv6Address)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Andrew File System Database Server DNS Records

Description
Returns information about the Andrew File System database server (AFSDB) resource records on a DNS server.

For more information about the MicrosoftDNS_AFSDBType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = _
    GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_AFSDBType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Server Name: " & objItem.ServerName
    Wscript.Echo "Subtype: " & objItem.Subtype
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating ATM Address to Name (ATMA) DNS Records

Description
Returns information about the ATM address to name (ATMA) records on a DNS server.

For more information about the MicrosoftDNS_ATMAType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_ATMAType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "ATM Address: " & objItem.ATMAddress
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Format: " & objItem.Format
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Host Address (A) DNS Records

Description
Returns information about the host address (A) resource records on a DNS server.

For more information about the MicrosoftDNS_AType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_AType")
For Each objItem in colItems
    Wscript.Echo "IP Address: " & objItem.IPAddress
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Canonical Name (CNAME) DNS Records

Description
Returns information about the canonical name (CNAME) records on a DNS server.

For more information about the MicrosoftDNS_CNAMEType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = _
    GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_CNAMEType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Primary Name: " & objItem.PrimaryName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating DNS Zones

Description
Returns information about all the DNS zones on a DNS server.

For more information about the MicrosoftDNS_Zone class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_Zone")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Zone Type: " & objItem.ZoneType
    Wscript.Echo "Aging: " & objItem.Aging
    Wscript.Echo "Allow Update: " & objItem.AllowUpdate
    Wscript.Echo "Autocreated: " & objItem.AutoCreated
    Wscript.Echo "Available For Scavenge Time: " & _
        objItem.AvailForScavengeTime
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "Data File: " & objItem.DataFile
    Wscript.Echo "Disable WINS Record Replication: " & _
        objItem.DisableWINSRecordReplication
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Directory Service-Integrated: " & objItem.DsIntegrated
    Wscript.Echo "Forwarder Slave: " & objItem.ForwarderSlave
    Wscript.Echo "Forwarder Timeout: " & objItem.ForwarderTimeout
    Wscript.Echo "Last Successful SOA Check: " & _
        objItem.LastSuccessfulSoaCheck
    Wscript.Echo "LastSuccessful Xfr: " & objItem.LastSuccessfulXfr
    Wscript.Echo "Local Master Servers: " & objItem.LocalMasterServers
    Wscript.Echo "Master Servers: " & objItem.MasterServers
    Wscript.Echo "No-Refresh Interval: " & objItem.NoRefreshInterval
    Wscript.Echo "Notify: " & objItem.Notify
    Wscript.Echo "Notify Servers: " & objItem.NotifyServers
    Wscript.Echo "Paused: " & objItem.Paused
    Wscript.Echo "Refresh Interval: " & objItem.RefreshInterval
    Wscript.Echo "Reverse: " & objItem.Reverse
    Wscript.Echo "Scavenge Servers: " & objItem.ScavengeServers
    Wscript.Echo "Secondary Servers: " & objItem.SecondaryServers
    Wscript.Echo "Secure Secondaries: " & objItem.SecureSecondaries
    Wscript.Echo "Shutdown: " & objItem.Shutdown
    Wscript.Echo "UseWins: " & objItem.UseWins
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Host Information (HINFO) DNS Records

Description
Returns data about the host information (HINFO) records on a DNS server.

For more information about the MicrosoftDNS_HINFOType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_HINFOType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "CPU: " & objItem.CPU
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Operating System: " & objItem.OS
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating IPv6 Address (AAAA) DNS Records

Description
Returns information about all the IPv6 address (AAAA) resource records on a DNS server.

For more information about the MicrosoftDNS_AAAAType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_AAAAType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "IPv6 Address: " & objItem.IPv6Address
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating ISDN DNS Records

Description
Returns information about the ISDN resource records on a DNS server.

For more information about the MicrosoftDNS_ISDNType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_ISDNType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Serve Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "ISDN Number: " & objItem.ISDNNumber
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "SubAddress: " & objItem.SubAddress
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating KEY DNS Records

Description
Returns information about the KEY resource records on a DNS server.

For more information about the MicrosoftDNS_KEYType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_KEYType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Algorithm: " & objItem.Algorithm
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Flags: " & objItem.Flags
    Wscript.Echo "Protocol: " & objItem.Protocol
    Wscript.Echo "Public Key: " & objItem.PublicKey
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mail Agent (MD) DNS Records

Description
Returns information about the mail agent for domain (MD) records on a DNS server.

For more information about the MicrosoftDNS_MDType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MDType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "MD Host: " & objItem.MDHost
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mail Forwarding Agent (MF) DNS Records

Description
Returns information about the mail forwarding agent (MF) records on a DNS server.

For more information about the MicrosoftDNS_MFType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MFType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "MF Host: " & objItem.MFHost
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mail Group (MG) DNS Records

Description
Returns information about the mail group (MG) resource records on a DNS server.

For more information about the MicrosoftDNS_MGType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MGType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "MG Mailbox: " & objItem.MGMailbox
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mail Information (MINFO) DNS Records

Description
Returns data about the mail information (MINFO) records on a DNS server.

For more information about the MicrosoftDNS_MINFO class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MINFOType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Error Mailbox: " & objItem.ErrorMailbox
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Responsible Mailbox: " & objItem.ResponsibleMailbox
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mailbox (MB) DNS Records

Description
Returns information about all the mailbox (MB) records on a DNS server.

For more information about the MicrosoftDNS_MBType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MBType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "MB Host: " & objItem.MBHost
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mailbox Rename (MR) DNS Records

Description
Returns information about the mailbox rename (MR) records on a DNS server.

For more information about the MicrosoftDNS_MRType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MRType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS ServerName: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "MR Mailbox: " & objItem.MRMailbox
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Mail Exchanger (MX) DNS Records

Description
Returns information about the mail exchanger (MX) records on a DNS server.

For more information about the MicrosoftDNS_MXType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_MXType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS sServer Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Mail Exchange: " & objItem.MailExchange
    Wscript.Echo "Preference: " & objItem.Preference
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Name Server (NS) DNS Records

Description
Returns information about the name server (NS) records on a DNS server.

For more information about the MicrosoftDNS_NSType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_NSType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "NS Host: " & objItem.NSHost
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Next (NXT) DNS Records

Description
Returns information about the next (NXT) resource records on a DNS server.

For more information about the MicrosoftDNS_NXTType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_NXTType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Next Domain Name: " & objItem.NextDomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo "Types: " & objItem.Types
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Responsible Person (RP) DNS Records

Enumerating Pointer (PTR) DNS Records

Description
Returns information about all the pointer (PTR) records on a DNS server.

For more information about the MicrosoftDNS_PTRType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_PTRType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
   Wscript.Echo "PTR Domain Name: " & objItem.PTRDomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Responsible Person (RP) DNS Records

Description
Returns information about the responsible person (RP) records on a DNS server.

For more information about the MicrosoftDNS_RPType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_RPType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS sServer Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "RP Mailbox: " & objItem.RPMailbox
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo "TXT Domain Name: " & objItem.TXTDomainName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Route Through (RT) DNS Records

Description
Returns information about the route through (RT) records on a DNS server.

For more information about the MicrosoftDNS_RTType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_RTType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Intermediate Host: " & objItem.IntermediateHost
    Wscript.Echo "Preference: " & objItem.Preference
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Service (SRV) DNS Records

Description
Returns information about all the service (SRV) records on a DNS server.

For more information about the MicrosoftDNS_SRVType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_SRVType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Port: " & objItem.Port
    Wscript.Echo "Priority: " & objItem.Priority
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo "Weight: " & objItem.Weight
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Signature (SIG) DNS Records

Description
Returns information about all the signature (SIG) resource records on a DNS server.

For more information about the MicrosoftDNS_SIGType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_SIGType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Algorithm: " & objItem.Algorithm
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Key Tag: " & objItem.KeyTag
    Wscript.Echo "Labels: " & objItem.Labels
    Wscript.Echo "Original Time-to-Live: " & objItem.OriginalTTL
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Signature: " & objItem.Signature
    Wscript.Echo "Signature Expiration: " & objItem.SignatureExpiration
    Wscript.Echo "Signature Inception: " & objItem.SignatureInception
    Wscript.Echo "Signer Name: " & objItem.SignerName
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo "Type Covered: " & objItem.TypeCovered
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Start of Authority (SOA) DNS Records

Description
Returns information about all the start of authority (SOA) records on a DNS server.

For more information about the MicrosoftDNS_SOAType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_SOAType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Expire Limit: " & objItem.ExpireLimit
    Wscript.Echo "Minimum Time-to-Live: " & objItem.MinimumTTL
    Wscript.Echo "Primary Server: " & objItem.PrimaryServer
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Refresh Interval: " & objItem.RefreshInterval
    Wscript.Echo "Responsible Party: " & objItem.ResponsibleParty
    Wscript.Echo "Retry Delay: " & objItem.RetryDelay
    Wscript.Echo "Serial Number: " & objItem.SerialNumber
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Text (TXT) DNS Records

Description
Returns information about all the text (TXT) records on a DNS server.

For more information about the MicrosoftDNS_TXTType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_TXTType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "Descriptive Text: " & objItem.DescriptiveText
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Well-Known Services (WKS) DNS Records

Description
Returns information about all the well-known services (WKS) records on a DNS server.

For more information about the MicrosoftDNS_WKSType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_WKSType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Internet Address: " & objItem.InternetAddress
    Wscript.Echo "IP Protocol: " & objItem.IPProtocol
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Services: " & objItem.Services
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating WINS Reverse Lookup DNS Records

Description
Returns information about all the Windows Internet Name Service (WINS) reverse lookup records on a DNS server.

For more information about the MicrosoftDNS_WINSRType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_WINSRType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Cache Timeout: " & objItem.CacheTimeout
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Lookup Timeout: " & objItem.LookupTimeout
    Wscript.Echo "Mapping Flag: " & objItem.MappingFlag
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Result Domain: " & objItem.ResultDomain
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating WINS DNS Records

Description
Returns information about all the Windows Internet Name Service (WINS) records on a DNS server.

For more information about the MicrosoftDNS_WINSType class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_WINSType")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Cache Timeout: " & objItem.CacheTimeout
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "Lookup Timeout: " & objItem.LookupTimeout
    Wscript.Echo "Mapping Flag: " & objItem.MappingFlag
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live : " & objItem.TTL
    Wscript.Echo "WINS Servers: " & objItem.WinsServers
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating X.25 DNS Records

Description
Returns information about all the X.25 records on a DNS server.

For more information about the MicrosoftDNS_X25Type class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_X25Type")
For Each objItem in colItems
    Wscript.Echo "Owner Name: " & objItem.OwnerName
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "Domain Name: " & objItem.DomainName
    Wscript.Echo "PSDN Address: " & objItem.PSDNAddress
    Wscript.Echo "Record Class: " & objItem.RecordClass
    Wscript.Echo "Record Data: " & objItem.RecordData
    Wscript.Echo "Text Representation: " & objItem.TextRepresentation
    Wscript.Echo "Timestamp: " & objItem.Timestamp
    Wscript.Echo "Time-to-Live: " & objItem.TTL
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Forcing a Refresh of a DNS Zone

Description
Forces the refresh of the secondary DNS zone accounting.fabrikam.com from its master zone.

For more information about the ForceRefresh method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    objItem.ForceRefresh()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pausing a DNS Zone

Description
Pauses the DNS zone accounting.fabrikam.com.

For more information about the PauseZone method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    objItem.PauseZone()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reloading a DNS Zone

Description
Reloads the DNS zone fabrikam.com from its database.

For more information about the ReloadZone method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'fabrikam.com'")
For Each objItem in colItems
    objItem.ReloadZone()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resuming DNS Zone

Description
Resumes the DNS zone accounting.fabrikam.com.

For more information about the ResumeZone method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    objItem.ResumeZone()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving DNS Domain Properties

Description
Returns information about the domains in a DNS hierarchy.

For more information about the MicrosoftDNS_Domain class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_Domain")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving DNS Server Cache Properties

Description
Returns information about the DNS cache on a DNS server.

For more information about the MicrosoftDNS_Cache class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_Cache")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DNSServerName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving DNS Server Properties

Description
Returns detailed information about a DNS server.

For more information about the MicrosoftDNS_Server class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_Server")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Address Answer Limit: " & objItem.AddressAnswerLimit
    Wscript.Echo "Allow Update: " & objItem.AllowUpdate
    Wscript.Echo "Autocache Update: " & objItem.AutoCacheUpdate
    Wscript.Echo "Autoconfig File Zones: " & objItem.AutoConfigFileZones
    Wscript.Echo "Bind Secondaries: " & objItem.BindSecondaries
    Wscript.Echo "Boot Method: " & objItem.BootMethod
    Wscript.Echo "Default Aging State: " & objItem.DefaultAgingState
    Wscript.Echo "Default No-Refresh Interval: " & _
        objItem.DefaultNoRefreshInterval
    Wscript.Echo "Default Refresh Interval: " & objItem.DefaultRefreshInterval
    Wscript.Echo "Disable AutoReverse Zones: " & _
        objItem.DisableAutoReverseZones
    Wscript.Echo "Disjoint Nets: " & objItem.DisjointNets
    Wscript.Echo "Directory Service Available: " & objItem.DsAvailable
    Wscript.Echo "Directory Service Polling Interval: " & _
        objItem.DsPollingInterval
    Wscript.Echo "Directory Service Tombstone Interval: " & _
        objItem.DsTombstoneInterval
    Wscript.Echo "EDNS Cache Timeout: " & objItem.EDnsCacheTimeout
    Wscript.Echo "Enable Directory Partitions: " & _
        objItem.EnableDirectoryPartitions
    Wscript.Echo "Enable DNSSec: " & objItem.EnableDnsSec
    Wscript.Echo "Enable EDNS Probes: " & objItem.EnableEDnsProbes
    Wscript.Echo "Event Log Level: " & objItem.EventLogLevel
    Wscript.Echo "Forward Delegations: " & objItem.ForwardDelegations
    Wscript.Echo "Forwarders: " & objItem.Forwarders
    Wscript.Echo "Forwarding Timeout: " & objItem.ForwardingTimeout
    Wscript.Echo "Is Slave: " & objItem.IsSlave
    Wscript.Echo "Listen Addresses: " & objItem.ListenAddresses
    Wscript.Echo "Local Net Priority: " & objItem.LocalNetPriority
    Wscript.Echo "Logfile Maximum Size: " & objItem.LogFileMaxSize
    Wscript.Echo "Logfile Path: " & objItem.LogFilePath
    Wscript.Echo "Log IPFilter List: " & objItem.LogIPFilterList
    Wscript.Echo "Log Level: " & objItem.LogLevel
    Wscript.Echo "Loose Wildcarding: " & objItem.LooseWildcarding
    Wscript.Echo "Maximum Cache Time-to-Live: " & objItem.MaxCacheTTL
    Wscript.Echo "Maximum Negative Cache Time-to-Live: " & _
        objItem.MaxNegativeCacheTTL
    Wscript.Echo "Name Check Flag: " & objItem.NameCheckFlag
    Wscript.Echo "No Recursion: " & objItem.NoRecursion
    Wscript.Echo "Recursion Retry: " & objItem.RecursionRetry
    Wscript.Echo "Recursion Timeout: " & objItem.RecursionTimeout
    Wscript.Echo "RoundRobin: " & objItem.RoundRobin
    Wscript.Echo "Rpc Protocol: " & objItem.RpcProtocol
    Wscript.Echo "Scavenging Interval: " & objItem.ScavengingInterval
    Wscript.Echo "Secure Responses: " & objItem.SecureResponses
    Wscript.Echo "Send Port: " & objItem.SendPort
    For Each strAddress in objItem.ServerAddresses
        Wscript.Echo "Server Address: " & strAddress
    Next
    Wscript.Echo "Started: " & objItem.Started
    Wscript.Echo "Start Mode: " & objItem.StartMode
    Wscript.Echo "Strict File Parsing: " & objItem.StrictFileParsing
    Wscript.Echo "Update Options: " & objItem.UpdateOptions
    Wscript.Echo "Version: " & objItem.Version
    Wscript.Echo "Write Authority NS: " & objItem.WriteAuthorityNS
    Wscript.Echo "Xfr Connect Timeout: " & objItem.XfrConnectTimeout
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving DNS Server Root Hints Properties

Description
Returns information about the root hints stored in the cache file on a DNS server.

For more information about the MicrosoftDNS_RootHints class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_RootHints")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Container Name: " & objItem.ContainerName
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving DNS Server Statistics

Description
Returns statistics collected on a DNS server.

For more information about the MicrosoftDNS_Statistics class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_Statistic")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Collection Name: " & objItem.CollectionName
    Wscript.Echo "Collection ID: " & objItem.CollectionId
    Wscript.Echo "DNS Server Name: " & objItem.DnsServerName
    Wscript.Echo "String Value: " & objItem.StringValue
    Wscript.Echo "Value: " & objItem.Value
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Start DNS Server Scavenging

Description
Instructs a DNS server to begin scavenging stale records in the appropriate DNS zones.

For more information about the StartScavenging method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * From MicrosoftDNS_Server")
For Each objItem in colItems
    objItem.StartScavenging()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Start the DNS Server Service

Description
Starts the DNS server service on a computer.

For more information about the StartService method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * From MicrosoftDNS_Server")
For Each objItem in colItems
    objItem.StartService()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Stop the DNS Server Service

Description
Stops the DNS server service.

For more information about the StopService method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * From MicrosoftDNS_Server")
For Each objItem in colItems
    objItem.StopService()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Update a DNS Zone

Description
Forces an update of the DNS zone accounting.fabrikam.com from Active Directory.

For more information about the UpdateFromDS method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    objItem.UpdateFromDS()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Write Back DNS Server Root Hints

Description
Writes the root hints back to the cache file on a DNS server.

For more information about the WriteBackRootHintDatafile method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery("Select * From MicrosoftDNS_RootHints")
For Each objItem in colItems
    objItem.WriteBackRootHintDatafile()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing Back a DNS Zone

Description
Saves zone data for the DNS zone accounting.fabrikam.com to the appropriate zone file.

For more information about the WriteBackZone method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set colItems = objWMIService.ExecQuery _
    ("Select * from MicrosoftDNS_Zone Where Name = 'accounting.fabrikam.com'")
For Each objItem in colItems
    objItem.WriteBackZone()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Home Networking Firewall Logging Settings

Description
Disables the logging on dropped packets with Internet Connection Firewall. To enable logging of dropped packets, simply set the value of the property LogDroppedPackets to True.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery _
    ("Select * from HNet_FirewallLoggingSettings")
For Each objItem in colItems
    objItem.LogDroppedPackets = False
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Home Networking Firewall Settings

Description
Disables the ability of the Internet Connection Firewall to allow inbound echo requests. To enable the ability to allow inbound echo requests, simply set the value of the property AlllowInboundEchoRequest to True.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery("Select * from HNet_FwIcmpSettings")
For Each objItem in colItems
    objItem.AllowInboundEchoRequest = False
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking Connections

Description
Returns the properties of each Internet Connection Firewall connection.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery("Select * from HNet_Connection")
For Each objItem in colItems
    Wscript.Echo "GUID: " & objItem.GUID
    Wscript.Echo "Is LAN Connection: " & objItem.IsLANConnection
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Phone Book Path: " & objItem.PhoneBookPath
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking Firewall Logging Settings

Description
Enumerates the configuration settings for Internet Connection Firewall logging.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery _
    ("Select * from HNet_FirewallLoggingSettings")
For Each objItem in colItems
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "Log Connections: " & objItem.LogConnections
    Wscript.Echo "Log Dropped Packets: " & objItem.LogDroppedPackets
    Wscript.Echo "Max File Size: " & objItem.MaxFileSize
    Wscript.Echo "Path: " & objItem.Path
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking Firewall Settings

Description
Enumerates the inbound and outbound configuration settings for Internet Connection Firewall.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery("Select * from HNet_FwIcmpSettings")
For Each objItem in colItems
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Allow Inbound Echo request: " & _
        objItem.AllowInboundEchoRequest
    Wscript.Echo "Allow Inbound Mask Requestt: " & _
        objItem.AllowInboundMaskRequest
    Wscript.Echo "Allow Inbound Router Request: " & _
        objItem.AllowInboundRouterRequest
    Wscript.Echo "Allow Inbound Timestamp Request: " & _
        objItem.AllowInboundTimestampRequest
    Wscript.Echo "Allow Outbound Destination Unreachable: " & _
        objItem.AllowOutboundDestinationUnreachable
    Wscript.Echo "Allow Outbound Parameter Problem: " & _
        objItem.AllowOutboundParameterProblem
    Wscript.Echo "Allow Outbound Source Quench: " & _
        objItem.AllowOutboundSourceQuench
    Wscript.Echo "Allow Outbound Time Exceeded: " & _
        objItem.AllowOutboundTimeExceeded
    Wscript.Echo "Allow redirect: " & objItem.AllowRedirect
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking ICMP Settings

Description
Enumerates the ICMP settings for Internet Connection Firewall.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery _
    ("Select * from HNet_ConnectionICMPSetting")
For Each objItem in colItems
    Wscript.Echo "Connection: " & objItem.Connection
    Wscript.Echo "ICMP Settings: " & objItem.ICMPSettings
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking ICS Settings

Description
Reports whether the Internet Connection Firewall settings have been configured to allow DHCP and DNS.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery("Select * from HNet_ICSSettings")
For Each objItem in colItems
    Wscript.Echo "DHCP Enabled: " & objItem.DHCPEnabled
    Wscript.Echo "DNS Enabled: " & objItem.DNSEnabled
    Wscript.Echo "ID: " & objItem.ID
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking Port Mapping Protocols

Description
Enumerates all the Internet Connection Firewall port mapping protocols on a computer.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery("Select * from HNet_PortMappingProtocol")
For Each objItem in colItems
    Wscript.Echo "Built In: " & objItem.BuiltIn
    Wscript.Echo "ID: " & objItem.ID
    Wscript.Echo "IP Protocol: " & objItem.IPProtocol
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Port: " & objItem.Port
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking Port Mappings

Description
Returns a list of all the Internet Connection Firewall port mappings on a computer.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery _
    ("Select * from HNet_ConnectionPortMapping2")
For Each objItem in colItems
    Wscript.Echo "Connection: " & objItem.Connection
    Wscript.Echo "Enabled: " & objItem.Enabled
    Wscript.Echo "Name Active: " & objItem.NameActive
    Wscript.Echo "Protocol: " & objItem.Protocol
    Wscript.Echo "Target IP Address: " & objItem.TargetIPAddress
    Wscript.Echo "Target Name: " & objItem.TargetName
    Wscript.Echo "Target Port: " & objItem.TargetPort
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Home Networking Connection Properties

Description
Enumerates Internet Connection Firewall connection properties.

For general information about Internet Connection Firewall, click here. At this point in time, the WMI classes used in this script have not been publicly documented.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\microsoft\homenet")
Set colItems = objWMIService.ExecQuery _
    ("Select * from HNet_ConnectionProperties")
For Each objItem in colItems
    Wscript.Echo "Connection: " & objItem.Connection
    Wscript.Echo "Is Bridge: " & objItem.IsBridge
    Wscript.Echo "Is Bridge Member: " & objItem.IsBridgeMember
    Wscript.Echo "Is Firewalled: " & objItem.IsFirewalled
    Wscript.Echo "Is ICS Private: " & objItem.IsICSPrivate
    Wscript.Echo "Is ICS Public: " & objItem.IsICSPublic
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving SNMP MIB-II Interface Table Information

Description
Retrieves and displays SNMP MIB-II (RFC 1213) Interface Table information from an SNMP managed node using the WMI SNMP Provider.

Supported Platforms

Windows Server 2003 | Yes, with the WMI SNMP Provider installed
Windows XP | Yes, with the WMI SNMP Provider installed
Windows 2000 | Yes, with the WMI SNMP Provider installed
Windows NT 4.0 | Yes, with WMI and the WMI SNMP Provider installed
Windows 98 | Yes, with WMI and the WMI SNMP Provider installed

Script Code

strTargetSnmpDevice = "192.168.0.1"

Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")

Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"

Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , _
    objWmiNamedValueSet)

For Each objInterface In colIfTable
    WScript.Echo "ifIndex [Key]:        " & objInterface.ifIndex  & vbCrLf & _
        "   ifAdminStatus:     " & objInterface.ifAdminStatus     & vbCrLf & _
        "   ifDescr:           " & objInterface.ifDescr           & vbCrLf & _
        "   ifInDiscards:      " & objInterface.ifInDiscards      & vbCrLf & _
        "   ifInErrors:        " & objInterface.ifInErrors        & vbCrLf & _
        "   ifInNUcastPkts:    " & objInterface.ifInNUcastPkts    & vbCrLf & _
        "   ifInOctets:        " & objInterface.ifInOctets        & vbCrLf & _
        "   ifInUcastPkts:     " & objInterface.ifInUcastPkts     & vbCrLf & _
        "   ifInUnknownProtos: " & objInterface.ifInUnknownProtos & vbCrLf & _
        "   ifLastChange:      " & objInterface.ifLastChange      & vbCrLf & _
        "   ifMtu:             " & objInterface.ifMtu             & vbCrLf & _
        "   ifOperStatus:      " & objInterface.ifOperStatus      & vbCrLf & _
        "   ifOutDiscards:     " & objInterface.ifOutDiscards     & vbCrLf & _
        "   ifOutErrors:       " & objInterface.ifOutErrors       & vbCrLf & _
        "   ifOutNUcastPkts:   " & objInterface.ifOutNUcastPkts   & vbCrLf & _
        "   ifOutOctets:       " & objInterface.ifOutOctets       & vbCrLf & _
        "   ifOutQLen:         " & objInterface.ifOutQLen         & vbCrLf & _
        "   ifOutUcastPkts:    " & objInterface.ifOutUcastPkts    & vbCrLf & _
        "   ifPhysAddress:     " & objInterface.ifPhysAddress     & vbCrLf & _
        "   ifSpecific:        " & objInterface.ifSpecific        & vbCrLf & _
        "   ifSpeed:           " & objInterface.ifSpeed           & vbCrLf & _
        "   ifType:            " & objInterface.ifType            & vbCrLf
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving SNMP MIB-II System Group Information

Description
Retrieves and displays SNMP MIB-II (RFC 1213) System Group information from an SNMP managed node using the WMI SNMP Provider.

Supported Platforms

Windows Server 2003 | Yes, with the WMI SNMP Provider installed
Windows XP | Yes, with the WMI SNMP Provider installed
Windows 2000 | Yes, with the WMI SNMP Provider installed
Windows NT 4.0 | Yes, with WMI and the WMI SNMP Provider installed
Windows 98 | Yes, with WMI and the WMI SNMP Provider installed

Script Code

strTargetSnmpDevice = "192.168.0.1"

Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")

Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"

Set colSystem = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_system", , _
    objWmiNamedValueSet)

For Each objSystem In colSystem
    WScript.Echo "sysContact:  " & objSystem.sysContact  & vbCrLf & _
                 "sysDescr:    " & objSystem.sysDescr    & vbCrLf & _
                 "sysLocation: " & objSystem.sysLocation & vbCrLf & _
                 "sysName:     " & objSystem.sysName     & vbCrLf & _
                 "sysObjectID: " & objSystem.sysObjectID & vbCrLf & _
                 "sysServices: " & objSystem.sysServices & vbCrLf & _
                 "sysUpTime:   " & objSystem.sysUpTime
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving SNMP MIB-II TCP and UDP Connections and Listening Ports

Description
Retrieves and displays SNMP MIB-II (RFC 1213) TCP (and UDP) connections and listening ports from an SNMP managed node using the WMI SNMP Provider. Equivalent to running netstat -a -n (which displays all connections and listening ports in numerical form).

Supported Platforms

Windows Server 2003 | Yes, with the WMI SNMP Provider installed
Windows XP | Yes, with the WMI SNMP Provider installed
Windows 2000 | Yes, with the WMI SNMP Provider installed
Windows NT 4.0 | Yes, with WMI and the WMI SNMP Provider installed
Windows 98 | Yes, with WMI and the WMI SNMP Provider installed

Script Code

strTargetSnmpDevice = "192.168.0.1"

Set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")

Set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", "public"

Set colTcpConnTable = _
    objWmiServices.InstancesOf("SNMP_RFC1213_MIB_tcpConnTable", , _
        objWmiNamedValueSet)

Set colUdpTable = _
    objWmiServices.InstancesOf("SNMP_RFC1213_MIB_udpTable", , _
        objWmiNamedValueSet)

WScript.Echo "TCP Connections and Listening Ports" & vbCrLf & _
    "-----------------------------------"

For Each objTcpConn In colTcpConnTable
    WScript.Echo objTcpConn.tcpConnLocalAddress & ":"    & _
                 objTcpConn.tcpConnLocalPort    & " => " & _
                 objTcpConn.tcpConnRemAddress   & ":"    & _
                 objTcpConn.tcpConnRemPort      & " "    & _
                 "[State: " & objTcpConn.tcpConnState & "]"
Next

WScript.Echo vbCrLf & "UDP Ports" & vbCrLf & "---------"

For Each objUdp In colUdpTable
    WScript.Echo objUdp.udpLocalAddress & ":" & objUdp.UdpLocalPort
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Terminal Services Account

Description
Adds a new Terminal Service account for fabrikam\bob, giving this account guest access rights.

For more information about the AddAccount method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const GUEST_ACCESS = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSPermissionsSetting")
For Each objItem in colItems
    errResult = objItem.AddAccount("fabrikam\bob", GUEST_ACCESS)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Terminal Services Direct Connect License Server

Description
Adds the computer atl-ts-01 as a direct connect license server to a computer running Terminal Services.

For more information about the AddDirectConnectLicenseServer method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.AddDirectConnectLicenseServer("atl-ts-01")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Assigning Terminal Services Initial Program

Description
Assign the startup program C:\Accounting\Invoice.exe (with a startup folder of C:\Accounting\FY_2003) to users logging on to a computer running Terminal Services.

For more information about the InitialProgram method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const STARTUP_PROGRAM = "c:\accounting\invoice.exe"
Const STARTUP_FOLDER = "c:\accounting\fy_2003"

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSEnvironmentSetting")
For Each objItem in colItems
    errResult = objItem.InitialProgram(STARTUP_PROGRAM, STARTUP_FOLDER)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Explicit Terminal Services Logon

Description
Configures the credentials (name, password, and domain) used to log on to Terminal Services.

For more information about the ExplicitLogon method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const TS_USER = "tsuser"
CONST TS_DOMAIN = "fabrikam"
CONST TS_PASSWORD = "password"

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSLogonSetting")
For Each objItem in colItems
    errResult = objItem.ExplicitLogon(TS_USER, TS_DOMAIN, TS_PASSWORD)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Broken Connection Settings

Description
Configures Terminal Services to permanently delete a session in case of a broken connection. To configure Terminal Services to merely disconnect the user from the session instead, pass the value 0 (instead of 1) to the BrokenConnection method.

For more information about the BrokenConnection method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const DISCONNECT_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
For Each objItem in colItems
    errResult = objItem.BrokenConnection(DISCONNECT_USER)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Client Settings

Description
Disables audio mapping on a computer running Terminal Services. To enable audio mapping, pass the value 1 (rather than 0) to the SetClientProperty method. To configure a different property value, replace the parameter AudioMapping with the appropriate property name.

For more in formation about the SetClientProperty method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const DISABLE = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSClientSetting")
For Each objItem in colItems
    errResult = objItem.SetClientProperty("AudioMapping", DISABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Client Wallpaper Settings

Description
Disables client wallpaper on a computer running Terminal Services. To enable the use of client wallpaper, pass the value 1 (rather than 0) to the SetClientWallpaper method.

For more information about the SetClientWallpaper method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const NO_WALLPAPER = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSEnvironmentSetting")
For Each objItem in colItems
    errResult = objItem.SetClientWallpaper(NO_WALLPAPER)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Color Depth

Description
Configures Terminal Services to use 16-bit color for client sessions. To use 8-bit color, pass the value 1 (rather than 3) to the SetColorDepth method. Pass the value 4 to use 24-bit color.

For more information about the SetColorDepth method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const SIXTEEN_BIT_COLOR = 3

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSClientSetting")
For Each objItem in colItems
    errResult = objItem.SetColorDepth(SIXTEEN_BIT_COLOR)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Color Depth Policy

Description
Enables the color depth policy on a computer running Terminal Services. To disable this policy, pass the value 0 (rather than 1) to the SetColorDepthPolicy method.

For more information about the SetColorDepthPolicy used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSClientSetting")
For Each objItem in colItems
    errResult = objItem.SetColorDepthPolicy(ENABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Client Connection Settings

Description
Configures Terminal Services client so that mapped drives and printers are automatically connected at logon, and to enable print jobs to be sent directly to the client’s local printer. These settings can be disabled by setting the appropriate constant value to 0 rather than 1.

For more information about the ConnectionSettings method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const CONNECT_CLIENT_DRIVES = 1
Const CONNECT_PRINTER = 1
Const USE_CLIENT_PRINTER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSClientSetting")
For Each objItem in colItems
    errResult = objItem.ConnectionSettings _
        (CONNECT_CLIENT_DRIVES, CONNECT_PRINTER, USE_CLIENT_PRINTER)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Encryption Level

Description
Configures Terminal Services to use high encryption parameter value of 3). To use low-encryption, pass the SetEncryptionLevel method a value of 1. Client-compatible encryption uses a value of 2, and FIPS-compliant encryption uses a value of 4.

For more information about the SetEncryptionLevel method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const HIGH_ENCRYPTION = 3

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSGeneralSetting")
For Each objItem in colItems
    errResult = objItem.SetEncryptionLevel(HIGH_ENCRYPTION)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Home Directory

Description
Configures the default home directory on a Terminal Services server to C:\TSUsers.

For more information about the Win32_TerminalServiceSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetHomeDirectory("c:\tsusers")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Mode

Description
Enables per-session licensing for Terminal Services. To enable per-device licensing, pass the value 2 (rather than 4) to the ChangeMode method. To enable remote desktop for administration or personal Terminal Services licensing, pass the value 0.

For more information about the ChangeMode method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PER_SESSION = 4
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.ChangeMode(PER_SESSION)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Policy Property

Description
Disables the UseTempFolders policy on a computer running Terminal Services. To enable this policy, pass the value 1 (rather than 0) to the SetPolicyPropertyName method. To configure a different policy, simply replace the method parameter “UseTempFolders” with the appropriate policy name.

For more information about the SetPolicyPropertyName method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const DISABLE_POLICY = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetPolicyPropertyName("UseTempFolders", DISABLE_POLICY)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Profile Path

Description
Sets the Terminal Services profile path on a computer to C:\TSProfiles.

For more information about the Win32_TerminalServiceSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetProfilePath("c:\tsprofiles")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Service Remote Control Settings

Description
Enables remote user to view, but not actively control, a session. Permission of the logged-on session user is not required.

For more information about the RemoteControl method used in this script (including a complete list of permissions), click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE_NO_INPUT_NO_NOTIFY = 4

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
  ("Select * from Win32_TSRemoteControlSetting Where TerminalName = 'Accounting'")
For Each objItem in colItems
  errResult = objItem.RemoteControl(ENABLE_NO_INPUT_NO_NOTIFY)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Session Directory Location

Description
Sets the session directory location of a Terminal Services server to 192.168.1.3.

For more information about the SetSessionDirectoryProperty method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSSessionDirectory")
For Each objItem in colItems
    errResult = objItem.SetSessionDirectoryProperty _
        ("SessionDirectoryLocation", "192.168.1.3")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Session Time Limit

Description
Allows unlimited-length active sessions in Terminal Services. To enforce a time limit on active sessions, pass the TimeLimit method a value other than 0. Time limits must be expressed in milliseconds; for example, a one-minute session limit would be expressed as 60000: 60 seconds times 1000 milliseconds. A one-hour time limit would be expressed as 3600000.

For more information about the TimeLimit method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const NO_SESSION_LIMIT = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
For Each objItem in colItems
    errResult = objItem.TimeLimit("ActiveSessionLimit", NO_SESSION_LIMIT)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Time Zone Redirection

Description
Disable Terminal Service time zone redirection on a computer. To enable time zone redirection, pass the value 1 (instead of 0) to the SetTimeZoneRedirection method.

For more information about the SetTimeZoneRedirection method use din this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const DISABLE = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetTimeZoneRedirection(DISABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Terminal Services Account

Description
Deletes the Terminal Services account for fabrikam\bob. Note that in the WQL query you must separate the domain name (fabrikam) and the user name (bob) using two forward slashes rather than one. Thus the account fabrikam\kenmyer would be listed as fabrikam\\kenmyer.

For more information about the Delete method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSAccount Where AccountName = 'FABRIKAM\\bob'")
For Each objItem in colItems
    errResult = objItem.Delete()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Terminal Service Direct Connect License Server

Description
Removes the computer atl-ts-01 as a direct connect license server for a computer running Terminal Services.

For more information about the DeleteDirectConnectLicenseServer method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.DeleteDirectConnectLicenseServer("atl-ts-01")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Forcible Terminal Services Logoff

Description
Enables the ability to forcibly logoff an administrator connected to Terminal Services. To disable forcible logoff, pass the value 1 (rather than 0) to the SetDisableForcibleLogoff method.

For more information about the SetDisableForcibleLogoff method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE_LOGOFF = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetDisableForcibleLogoff(ENABLE_LOGOFF)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Single Session Terminal Service Sessions

Description
Enables single session Terminal Service sessions on a computer. To allow multiple sessions, pass the value 0 (rather than 1) to the SetSingleSession parameter.

For more information about the SetSingleSession method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetSingleSession(ENABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Terminal Services

Description
Enables the Accounting terminal on a computer running Terminal Services. To disable the Accounting terminal, set the parameter of the Enable method to 0 rather than 1.

For more information about the Enable method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_Terminal Where TerminalName = 'Accounting'")
For Each objItem in colItems
    errResult = objItem.Enable(ENABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Terminal Services Active Desktop

Description
Enables Terminal Service Active Desktop on a computer. To disable Active Desktop, set the value of the ActiveDesktop property to 0 instead of 1.

For more information about the Win32_TerminalServiceSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLED = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    objItem.ActiveDesktop = ENABLED
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Terminal Services Password Prompt

Description
Configure Terminal Services to prompt for a password each time a user logs on. To disable password prompting, pass the value 0 (rather than 1) to the SetpromptForPassword method.

For more information about the SetPromptForPassword method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSLogonSetting")
For Each objItem in colItems
    errResult = objItem.SetPromptForPassword(ENABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Terminal Services Session Directory

Description
Enable the session directory on a Terminal Services server. To disable the session directory, pass the value 0 (rather than 1) to the SetSessionDirectoryActive method.

For more information about the SetSessionDirectoryActive method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE_SESSION_DIRECTORY = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionDirectory")
For Each objItem in colItems
    errResult = objItem.SetSessionDirectoryActive(ENABLE_SESSION_DIRECTORY)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Terminal Service Connections

Description
Enables Terminal Services connections on a computer running Terminal Services. To disable connections, pass the value 0 (rather than 1) to the SetAllowTSConnections method.

For more information about the SetAllowTSConnections method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE_CONNECTIONS = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    errResult = objItem.SetAllowTSConnections(ENABLE_CONNECTIONS)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Accounts

Description
Returns information about all the Terminal Services accounts available on a computer.

For more information about the Win32_TSAccount class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSAccount")
For Each objItem in colItems
    Wscript.Echo "Account name: " & objItem.AccountName
    Wscript.Echo "Audit failure: " & objItem.AuditFail
    Wscript.Echo "Audit success: " & objItem.AuditSuccess
    Wscript.Echo "Permissions allowed: " & objItem.PermissionsAllowed
    Wscript.Echo "Permissions denied: " & objItem.PermissionsDenied
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "SID: " & objItem.SID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Client Settings

Description
Returns information about the Terminal Service client settings and policies configured on a computer.

For more information about the Win32_TSClientSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSClientSetting")
For Each objItem in colItems
    Wscript.Echo "Audio mapping: " & objItem.AudioMapping
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Clipboard mapping: " & objItem.ClipboardMapping
    Wscript.Echo "Color depth: " & objItem.ColorDepth
    Wscript.Echo "Color depth policy: " & objItem.ColorDepthPolicy
    Wscript.Echo "COM port mapping: " & objItem.COMPortMapping
    Wscript.Echo "Connect client drives at logon: " & _
        objItem.ConnectClientDrivesAtLogon
    Wscript.Echo "Connection policy: " & objItem.ConnectionPolicy
    Wscript.Echo "Connect printer at logon: " & objItem.ConnectPrinterAtLogon
    Wscript.Echo "Default to client printer: " & objItem.DefaultToClientPrinter
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Drive mapping: " & objItem.DriveMapping
    Wscript.Echo "LPT port mapping: " & objItem.LPTPortMapping
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo "Windows printer mapping: " & objItem.WindowsPrinterMapping
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Environment Settings

Description
Returns information about the Terminal Service client environment settings configured on a computer.

For more information about the Win32_TSEnvironmentSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSEnvironmentSetting")
For Each objItem in colItems
    Wscript.Echo "Client wallpaper: " & objItem.ClientWallpaper
    Wscript.Echo "Initial program path: " & objItem.InitialProgramPath
    Wscript.Echo "Initial program policy: " & objItem.InitialProgramPolicy
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Start in: " & objItem.Startin
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services General Settings

Description
Returns general information about how Terminal Services has been configured on a computer.

For more information about the Win32_TSGeneralSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSGeneralSetting")
For Each objItem in colItems
    Wscript.Echo "Comment: " & objItem.Comment
    Wscript.Echo "Minimum encryption level: " & objItem.MinEncryptionLevel
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo "Terminal protocol: " & objItem.TerminalProtocol
    Wscript.Echo "Transport: " & objItem.Transport
    Wscript.Echo "Windows authentication: " & objItem.WindowsAuthentication
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Logon Settings

Description
Returns information about the Terminal Service logon policies configured on a computer.

For more information about the Win32_TSLogonSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSLogonSetting")
For Each objItem in colItems
    Wscript.Echo "Client logon information policy: " & _
        objItem.ClientLogonInfoPolicy
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "Prompt for password: " & objItem.PromptForPassword
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo "User name: " & objItem.UserName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Network Adapter List Settings

Description
Enumerates the network adapters that can be configured for Terminal Services.

For more information about the Win32_TSNetworkAdapterListSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes, except for the NetworkAdapterIP property
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSNetworkAdapterListSetting")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Network Adapter ID: " & objItem.NetworkAdapterID
    Wscript.Echo "Network Adapter IP Address: " & objItem.NetworkAdapterIP
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Network Adapter Settings

Description
Enumerates Terminal Services network adapter settings, including the maximum number of connections allowed.

For more information about the Win32_TSNetworkAdapterSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSNetworkAdapterSetting")
For Each objItem in colItems
    Wscript.Echo "Maximum Connections: " & objItem.MaximumConnections
    Wscript.Echo "Network Adapter ID: " & objItem.NetworkAdapterID
    Wscript.Echo "Network Adapter Name: " & objItem.NetworkAdapterName
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal Name: " & objItem.TerminalName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Permission Settings

Description
Lists Terminal Services permission settings.

For more information about the Win32_TSPermissionsSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSPermissionsSetting")
For Each objItem in colItems
  Wscript.Echo objItem.Caption
  Wscript.Echo objItem.Description
  Wscript.Echo objItem.SettingID
  Wscript.Echo objItem.TerminalName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Remote Control Settings

Description
Returns information about Terminal Service remote control as configured on a computer.

For more information about the Win32_TSRemoteControlSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSRemoteControlSetting")
For Each objItem in colItems
    Wscript.Echo "Level of control: " & objItem.LevelofControl
    Wscript.Echo "Remote control policy: " & objItem.RemoteControlPolicy
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Session Directory Settings

Description
Returns configuration information for all the Terminal Service session directories found on a computer.

For more information about the Win32_TSSessionDirectory class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes, except for the property SessionDirectoryIPAddress
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionDirectory")
For Each objItem in colItems
    Wscript.Echo "Session Directory active: " & objItem.SessionDirectoryActive
    Wscript.Echo "Session Directory cluster name: " & _
        objItem.SessionDirectoryClusterName
    Wscript.Echo "Session Directory expose server IP address: " & _
        objItem.SessionDirectoryExposeServerIP
    Wscript.Echo "Session Directory IP address: " & _
        objItem.SessionDirectoryIPAddress
    Wscript.Echo "Session Directory location: " & _
        objItem.SessionDirectoryLocation
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Session Settings

Description
Returns Terminal Service session configuration information.

For more information about the Win32_TSSessionSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
For Each objItem in colItems
    Wscript.Echo "Active session limit: " & objItem.ActiveSessionLimit
    Wscript.Echo "Broken connection action: " & objItem.BrokenConnectionAction
    Wscript.Echo "Broken connection policy: " & objItem.BrokenConnectionPolicy
    Wscript.Echo "Disconnected session limit: " & _
        objItem.DisconnectedSessionLimit
    Wscript.Echo "Idle session limit: " & objItem.IdleSessionLimit
    Wscript.Echo "Reconnection policy: " & objItem.ReconnectionPolicy
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo "Time limit policy: " & objItem.TimeLimitPolicy
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Terminals

Description
Returns configuration information for all the Terminal Service terminals on a computer.

For more information about the Win32_TerminalSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TerminalSetting")
For Each objItem in colItems
  Wscript.Echo "Caption: " & objItem.Caption
  Wscript.Echo "Description: " & objItem.Description
  Wscript.Echo "Setting ID: " & objItem.SettingID
  Wscript.Echo "Terminal name: " & objItem.TerminalName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Terminals

Description
Returns a list of all the Terminal Service terminals on a computer.

For more information about the Win32_Terminal class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Terminal")
For Each objItem in colItems
    Wscript.Echo "Terminal name: " & objItem.TerminalName
    Wscript.Echo "Terminal enabled: " & objItem.fEnableTerminal
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Terminal Services Terminal Settings

Description
Enumerates the Terminal Service configuration settings on a computer.

For more information about the Win32_TerminalServiceSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes, except for the DisableForcibleLogoff and TimeZoneRedirection properties
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    Wscript.Echo "Active Desktop: " & objItem.ActiveDesktop
    Wscript.Echo "Allow TS connections: " & objItem.AllowTSConnections
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Delete temporary folders: " & objItem.DeleteTempFolders
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Direct connect license servers: " & _
        objItem.DirectConnectLicenseServers
    Wscript.Echo "Disable forcible logoff: " & objItem.DisableForcibleLogoff
    Wscript.Echo "Help: " & objItem.Help
    Wscript.Echo "Home directory: " & objItem.HomeDirectory
    Wscript.Echo "Licensing description: " & objItem.LicensingDescription
    Wscript.Echo "Licensing name: " & objItem.LicensingName
    Wscript.Echo "Licensing type: " & objItem.LicensingType
    Wscript.Echo "Logons: " & objItem.Logons
    Wscript.Echo "Profile path: " & objItem.ProfilePath
    Wscript.Echo "Server name: " & objItem.ServerName
    Wscript.Echo "Setting ID: " & objItem.SettingID
    Wscript.Echo "Single session: " & objItem.SingleSession
    Wscript.Echo "Terminal Server mode: " & objItem.TerminalServerMode
    Wscript.Echo "Time zone redirection: " & objItem.TimeZoneRedirection
    Wscript.Echo "User permission: " & objItem.UserPermission
    Wscript.Echo "Use temporary folders: " & objItem.UseTempFolders
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Exposing Terminal Services Session Directory Server IP Address

Description
Allow a Terminal Services server to make its session directory IP address available. To prevent a server from exposing its session directory IP address, pass the value 0 (rather than 1) to the SetSessionDirectoryExposeServerIP method.

For more information about the SetSessionDirectoryExposeServerIP method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLE = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSSessionDirectory")
For Each objItem in colItems
    errResult = objItem.SetSessionDirectoryExposeServerIP(ENABLE)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying Terminal Service Audit Permissions

Description
Denies the user fabrikam\bob from being able to query Terminal Services Accounting terminal for session information.

For more information about the ModifyAuditPermissions method used in this script (including a complete list of permissions and their values), click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const WINSTATION_QUERY = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSAccount Where AccountName = 'fabrikam\\bob' AND " _
        & "TerminalName = 'Accounting'")
For Each objItem in colItems
    errResult = objItem.ModifyAuditPermissions(WINSTATION_QUERY, False)
    Wscript.Echo errResult
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying Terminal Services Broken Connection Policy

Description
Enables per-user application of broken connection policies. To apply the same broken connection policies to all users, set the value of the BrokenConnectionPolicy property to 0 rather than 1.

For more information about the Win32_TSSessionSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PER_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
For Each objItem in colItems
    objItem.BrokenConnectionPolicy = PER_USER
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying Terminal Services Client Logon Settings

Description
Enables per-user application of client logon policies. To apply the same policies to all users, set the value of the ClientLogonInfoPolicy property to 0 rather than 1,

For more information about the Win32_TSLogonSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PER_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSLogonSetting")
For Each objItem in colItems
    objItem.ClientLogonInfoPolicy = PER_USER
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Comment

Description
Modifies the descriptive comment attached to a Terminal Services server.

For more information about the Win32_TSGeneralSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSGeneralSetting")
For Each objItem in colItems
    objItem.Comment = "Accounting session."
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Connection Policy

Description
Configures Terminal Services to use per-user connection settings. To apply the same connection settings to all users, set the value of the ConnectionPolicy property to 0 rather than 1.

For more information about the Win32_TSClientSrtting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PER_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSClientSetting")
For Each objItem in colItems
    objItem.ConnectionPolicy = PER_USER
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Initial Program Policy

Description
Configures Terminal Services to assign startup programs on a per-user basis. To have Terminal Services apply the same startup program to all users, set the value of the InitialProgramPolicy property to 0 rather than 1.

For more information about the Win32_TSEnvironmentSrtting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

CONST PER_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSEnvironmentSetting")
For Each objItem in colItems
    objItem.InitialProgramPolicy = PER_USER
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Logon Policy

Description
Enables new sessions on Terminal Services. To disable new sessions, set the value of the Logons property to 0 rather than 1.

For more information about the Win32_TerminalServiceSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const NEW_SESSIONS_ALLOWED = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    objItem.Logons = NEW_SESSIONS_ALLOWED
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Maximum Connections

Description
Sets the maximum number of connections allowed on a Terminal Services network adapter to 100.

For more information about the Win32_TSNetworkAdapterSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const MAXIMUM_CONNECTIONS = 100

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSNetworkAdapterSetting")
For Each objItem in colItems
    objItem.MaximumConnections = MAXIMUM_CONNECTIONS
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Service Permissions

Description
Gives the user fabrikam\bob the right to connect to another Terminal Services session.

For more information about the ModifyPermissions method used in this script (including a complete list of permissions), click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

CONST WINSTATION_CONNECT = 8

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSAccount Where AccountName = 'fabrikam\\bob' AND " & _
        "TerminalName = 'Accounting'")
For Each objItem in colItems
    errResult = objItem.ModifyPermissions(WINSTATION_CONNECT,True)
    Wscript.Echo errResult
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Reconnection Policy

Description
Allows a user to reconnect to a Terminal Services session using any client. To require users to reconnect to a session used the same client they used previously, set the value of the ReconnectionPolicy property to 1 rather than 0.

For more information about the Win32_TSSessionSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PREVIOUS_CLIENT = 0

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
For Each objItem in colItems
    objItem.ReconnectionPolicy = PREVIOUS_CLIENT
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Remote Control Policy

Description
Enables Terminal Services to apply per-user remote control policies. To apply the same remote control policies to all users, set the value of the RemoteControlPolicy property to 0 rather than 1.

For more information about the Win32_TSRemoteControlSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PER_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSRemoteControlSetting")
For Each objItem in colItems
    objItem.RemoteControlPolicy = PER_USER
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Session Directory IP Address

Description
Configures Terminal Services to use a session directory with the IP address of 192.168.1.3.

For more information about the Win32_TSSessionDirectory class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionDirectory")
For Each objItem in colItems
    objItem.SessionDirectoryIPAddress = "192.168.1.3"
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Time Limit Policy

Description
Configures Terminal Services to use per-user time limit policies. To apply the server’s time limit policies to all users, set the value of the TimeLImitPolicy property to 0 instead of 1.

For more information about the Win32_TSSessionSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PER_USER = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
For Each objItem in colItems
    objItem.TimeLimitPolicy = PER_USER
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services User Permissions

Description
Enables Terminal Services application compatibility. To disable application compatibility, set the value of the UserPermission property to 0 instead of 1.

For more information about the Win32_TerminalServiceSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ENABLED = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TerminalServiceSetting")
For Each objItem in colItems
    objItem.UserPermission = ENABLED
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Modify Terminal Services Windows Authentication Setting

Description
Configures Terminal Services to use standard Windows authentication. To disable standard authentication (in order to use a custom authentication package), set the value of the WindowsAuthentication property to 0 rather than 1.

For more information about the Win32_TSGeneralSetting class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const STANDARD_AUTHENTICATION = 1

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSGeneralSetting")
For Each objItem in colItems
    objItem.WindowsAuthentication = STANDARD_AUTHENTICATION
    objItem.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Terminal Services Environment Properties for a User Account

Description
Returns Terminal Services environment properties for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intConnectClientDrivesAtLogon = objUser.ConnectClientDrivesAtLogon
intConnectClientPrintersAtLogon = objUser.ConnectClientPrintersAtLogon
intDefaultToMainPrinter = objUser.DefaultToMainPrinter
strTerminalServicesInitialProgram = objUser.TerminalServicesInitialProgram
strTerminalServicesWorkDirectory = objUser.TerminalServicesWorkDirectory

WScript.Echo "ConnectClientDrivesAtLogon: " & intConnectClientDrivesAtLogon
WScript.Echo "ConnectClientPrintersAtLogon: " & _
    intConnectClientPrintersAtLogon
WScript.Echo "DefaultToMainPrinter: " & intDefaultToMainPrinter
WScript.Echo "TerminalServicesInitialProgram: " & _
    strTerminalServicesInitialProgram
WScript.Echo "TerminalServicesWorkDirectory: " & _
    strTerminalServicesWorkDirectory

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Terminal Services Profile Properties

Description
Returns Terminal Services profile information for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strTerminalServicesProfilePath = objUser.TerminalServicesProfilePath
strTerminalServicesHomeDirectory = objUser.TerminalServicesHomeDirectory
strTerminalServicesHomeDrive = objUser.TerminalServicesHomeDrive
intAllowLogon = objUser.AllowLogon

WScript.Echo "TerminalServicesProfilePath : " & strTerminalServicesProfilePath
WScript.Echo "TerminalServicesHomeDirectory: " & _
    strTerminalServicesHomeDirectory
WScript.Echo "TerminalServicesHomeDrive: " & strTerminalServicesHomeDrive
WScript.Echo "AllowLogon: " & intAllowLogon

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Rename a Terminal Service Terminal

Description
Renames the Terminal Services terminal RDP-tcp (the default name) to Accounting.

For more information about the Rename method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_Terminal Where TerminalName = 'RDP-tcp'")
For Each objItem in colItems
    errResult = objItem.Rename("Accounting")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Restoring Default Terminal Service Permissions

Description
Restores the default permission settings for all the Terminal Service accounts on a computer.

For more information about the RestoreDefaults method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_TSPermissionsSetting")
For Each objItem in colItems
    errResult = objItem.RestoreDefaults()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining if an Attribute is in the Global Catalog

Description
Determines whether or not a specified attribute (given-name) is included in the Active Directory global catalog.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strAttributeName = "cn=given-name"

Set objSchemaAttribute = GetObject _
    ("LDAP://" & strAttributeName & _
        ",cn=schema,cn=configuration,dc=fabrikam,dc=com")

blnInGC = objSchemaAttribute.Get("isMemberOfPartialAttributeSet")

If blnInGC Then
    WScript.Echo "The " & strAttributeName & _
        " attribute is replicated to the Global Catalog."
Else
    WScript.Echo "The " & strAttributeName & _
    " attribute is not replicated to the Global Catalog."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining if an Attribute is Operational

Description
Determines whether or not a specified attribute (Canonical-Name) is an operational within Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Client Extensions installed

Script Code

Const ADS_SYSTEMFLAG_ATTR_IS_CONSTRUCTED = &h00000004

strAttributeName = "cn=Canonical-Name"

Set objSchemaAttribute = GetObject _
    ("LDAP://" & strAttributeName & _
        ",cn=schema,cn=configuration,dc=fabrikam,dc=com")

intSystemFlags = objSchemaAttribute.Get("systemFlags")

If intSystemFlags AND ADS_SYSTEMFLAG_ATTR_IS_CONSTRUCTED Then
    WScript.Echo strAttributeName & " is operational."
Else
    WScript.Echo strAttributeName & " is not operational."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Active Directory Class Type for an Object

Description
Determines the Active Directory class type for the organizational-person object.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strClassName = "cn=organizational-person"

Set objSchemaClass = GetObject _
    ("LDAP://" & strClassName & _
        ",cn=schema,cn=configuration,dc=fabrikam,dc=com")

intClassCategory = objSchemaClass.Get("objectClassCategory")

WScript.StdOut.Write strClassName & " is categorized as "

Select Case intClassCategory
    Case 0
        WScript.Echo "88"
    Case 1
        WScript.Echo "structural"
    Case 2
        WScript.Echo "abstract"
    Case 3
        WScript.Echo "auxiliary"
End Select

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Parent Class of an Active Directory Object

Description
Determines the parent class of the Computer object within Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strClassName = "cn=computer"

Set objSchemaClass = GetObject _
    ("LDAP://" & strClassName & _
        ",cn=schema,cn=configuration,dc=fabrikam,dc=com")

strSubClassOf = objSchemaClass.Get("subClassOf")
WScript.Echo "The " & strClassName & _
    " class is a child of the " & strSubClassOf & " class."

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying the Six IADs Properties of a Domain Object

Description
Retrieves the ADsPath, Class, GUID, Name, Parent, and Schema properties of the IADs core interface for a domain object.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objDomain = GetObject("LDAP://dc=NA,dc=fabrikam,dc=com")
WScript.Echo "ADsPath:" & objDomain.ADsPath
WScript.Echo "Class:" & objDomain.Class
WScript.Echo "GUID:" & objDomain.GUID
WScript.Echo "Name:" & objDomain.Name
WScript.Echo "Parent:" & objDomain.Parent
WScript.Echo "Schema:" & objDomain.Schema

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Whether Attributes are Indexed and/or in the Global Catalog

Description
Determines which Active Directory attributes are indexed and which attributes are in the global catalog.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const IS_INDEXED = 1

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.Properties("Sort On") = "isMemberOfPartialAttributeSet"

objCommand.CommandText = _
    "<LDAP://CN=Schema,CN=Configuration,DC=fabrikam,DC=com>;" & _
        "(objectClass=attributeSchema);" & _
            "lDAPDisplayName, isMemberOfPartialAttributeSet,searchFlags;onelevel"

Set objRecordSet = objCommand.Execute

While Not objRecordSet.EOF
    WScript.Echo objRecordset.Fields("lDAPDisplayName")
    If objRecordset.Fields("isMemberOfPartialAttributeSet")Then
        WScript.Echo "In the global catalog."
    Else
        WScript.Echo "Not in the global catlog."
    End If

    If IS_INDEXED AND objRecordset.Fields("searchFlags") Then
        WScript.Echo "Is indexed."
    Else
        WScript.Echo "Is not indexed."
    End If
    Wscript.Echo VbCrLf
    objRecordSet.MoveNext
Wend

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All the Attributes of an Active Directory Class

Description
Returns all the attributes associated with the Computer class in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objSchemaComputer = GetObject("LDAP://schema/computer")

WScript.Echo "Mandatory (Must-Contain) attributes"
For Each strAttribute in objSchemaComputer.MandatoryProperties
    WScript.Echo strAttribute
Next

WScript.Echo VbCrLf & "Optional (May-Contain) attributes"
For Each strAttribute in objSchemaComputer.OptionalProperties
    WScript.Echo strAttribute
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Auxiliary Classes

Description
Returns a list of all the Active Directory auxiliary classes directly applied to the User class.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
strClassName = "cn=user"

Set objSchemaClass = GetObject _
    ("LDAP://" & strClassName & _
        ",cn=schema,cn=configuration,dc=fabrikam,dc=com")

arrSystemAuxiliaryClass = _
objSchemaClass.GetEx("systemAuxiliaryClass")

If isEmpty(arrSystemAuxiliaryClass) Then
    WScript.Echo "There are no auxiliary classes" & _
        " applied directly to this class."
    Else
        WScript.StdOut.Write "Auxiliary classes: "
    For Each strAuxiliaryClass in arrSystemAuxiliaryClass
        WScript.StdOut.Write strAuxiliaryClass & " | "
    Next
    WScript.Echo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Names of Objects in the Configuration Container

Description
Retrieves the names of the first level objects in the Configuration container.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objConfiguration = GetObject _
    ("LDAP://cn=Configuration,dc=fabrikam,dc=com")

For Each objContainer in objConfiguration
    WScript.Echo objContainer.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning Active Directory System Information

Description
Uses the ADSystemInfo interface to return domain information for a computer, including computer name, site name, and various domain names (short name, domain DNS name, and forest DNS name).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
Wscript.Echo "User name: " & objSysInfo.UserName
Wscript.Echo "Computer name: " & objSysInfo.ComputerName
Wscript.Echo "Site name: " & objSysInfo.SiteName
Wscript.Echo "Domain short name: " & objSysInfo.DomainShortName
Wscript.Echo "Domain DNS name: " & objSysInfo.DomainDNSName
Wscript.Echo "Forest DNS name: " & objSysInfo.ForestDNSName
Wscript.Echo "PDC role owner: " & objSysInfo.PDCRoleOwner
Wscript.Echo "Schema role owner: " & objSysInfo.SchemaRoleOwner
Wscript.Echo "Domain is in native mode: " & objSysInfo.IsNativeMode

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using a Search Operation to Modify Similar Active Directory Objects

Description
Searches for all computers that begin with the letters, "ATL" in a domain and any child domains. Then, modifies the location attribute of all computers in the result set.

Note Use the GC moniker instead of the LDAP moniker on line 8 if there is a global catalog server in the domain where the search begins. For example, change:

"<LDAP://dc=NA,dc=fabrikam,dc=com>;" & _

to

"<GC://dc=NA,dc=fabrikam,dc=com>;" & _

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
    "<LDAP://dc=NA,dc=fabrikam,dc=com>;" & _
        "(&(objectCategory=Computer)(cn=ATL*));" & _
            "ADsPath;subtree"

Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
    strADsPath = objRecordset.Fields("ADsPath")
    Set objComputer = GetObject(strADsPath)
    objComputer.Put "location", "Atlanta, Georgia"
    objComputer.SetInfo
    objRecordSet.MoveNext
Wend

WScript.Echo objRecordSet.RecordCount & _
   " computers objects modified."

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using a Search Operation to Move Similar Active Directory Objects

Description
Searches for all user account objects whose department attribute is "Human Resources in a domain and any child domains. Then, the script moves the user accounts in the result set that are not already in the HR OU of the na.fabrikam.com to this OU.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
    "<LDAP://dc=NA,dc=fabrikam,dc=com>;" & _
        "(&(&(objectCategory=person)(objectClass=user)" & _
            "(department=Human Resources)));" & _
                "ADsPath,distinguishedName, name;subtree"

Set objRecordSet = objCommand.Execute
Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")

While Not objRecordset.EOF
    strADsPath = objRecordset.Fields("ADsPath")

    strDNRecord=lcase(objRecordset.Fields("distinguishedName"))
    strDNCompare=lcase("cn=" & objRecordset.Fields("name") & _
        ",ou=HR,dc=NA,dc=fabrikam,dc=com")

    If strDNRecord <> strDNCompare Then
        objOU.MoveHere strADsPath, vbNullString
        WScript.Echo objRecordset.Fields("distinguishedName") & " Moved."
    Else
        WScript.Echo objRecordset.Fields("distinguishedName") & " Not Moved."
    End If
    objRecordSet.MoveNext
Wend

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading and Using Attributes of rootDSE for AD Object Binding Operations

Description
How to use rootDSE to perform binding operations to:

· The schema (schemaNamingContext attribute)

· The configuration container (configurationNamingContext attribute)

· The current domain (defaultNamingContext attribute)

· The root domain (rootDomainNamingContext attribute)

Additional code displays selected properties of the objects created in the binding operation to the operator.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objRootDSE = GetObject("LDAP://rootDSE")

strSchema = "LDAP://" & objRootDSE.Get("schemaNamingContext")
WScript.echo "ADsPath to schema: " & strSchema
Set objSchema = GetObject(strSchema)
WScript.Echo "Schema Object:"
WScript.Echo "Name: " & objSchema.Name
WScript.Echo "Class: " & objSchema.Class & VbCrLf

strConfiguration = "LDAP://" & objRootDSE.Get("configurationNamingContext")
WScript.Echo "ADsPath to configuration container: " & strConfiguration
Set objConfiguration = GetObject(strConfiguration)
WScript.Echo "Configuration Object:"
WScript.Echo "Name: " & objConfiguration.Name
WScript.Echo "Class: " & objConfiguration.Class & VbCrLf

strDomain = "LDAP://" & objRootDSE.Get("defaultNamingContext")
WScript.Echo "ADsPath to current domain container: " & strDomain
Set objDomain = GetObject(strDomain)
WScript.Echo "Current Domain Object:"
WScript.Echo "Name: " & objDomain.Name
WScript.Echo "Class: " & objDomain.Class & VbCrLf

strRootDomain = "LDAP://" & objRootDSE.Get("rootDomainNamingContext")
WScript.Echo "ADsPath to root domain container: " & strDomain
Set objRootDomain = GetObject(strRootDomain)
WScript.Echo "Current Domain Object:"
WScript.Echo "Name: " & objRootDomain.Name
WScript.Echo "Class: " & objRootDomain.Class & VbCrLf

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Default WMI Namespace

Description
Sets the WMI "Default namespace for scripting" setting to "root\cimv2".

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colWMISettings = objWMIService.InstancesOf("Win32_WMISetting")

For Each objWMISetting in colWMISettings
    objWMISetting.ASPScriptDefaultNamespace = "root\cimv2"
    objWMISetting.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring WMI Settings

Description
Configures WMI backup interval and logging level.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colWMISettings = objWMIService.ExecQuery _
    ("Select * from Win32_WMISetting")
For Each objWMISetting in colWMISettings
    objWMISetting.BackupInterval = 60
    objWMISetting.LoggingLevel = 2
    objWMISetting.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Abstract Classes in WMI

Description
Lists all WMI Abstract classes defined in the root\cimv2 namespace.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colClasses = objWMIService.SubclassesOf()

For Each objClass in colClasses
    For Each objClassQualifier In objClass.Qualifiers_
        If LCase(objClassQualifier.Name) = "abstract" Then
            WScript.Echo objClass.Path_.Class & ": " & _
            objClassQualifier.Name & "=" & _
            objClassQualifier.Value
        End If
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All WMI Namespaces

Description
Lists all WMI namespaces.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "."
Call EnumNameSpaces("root")

Sub EnumNameSpaces(strNameSpace)
    WScript.Echo strNameSpace
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
        "\" & strNameSpace)
    Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")
    For Each objNameSpace In colNameSpaces
        Call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
    Next
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Dynamic Classes in WMI

Description
Lists all WMI Dynamic classes (including Association classes) defined in the root\cimv2 namespace.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colClasses = objWMIService.SubclassesOf()

For Each objClass in colClasses
    For Each objClassQualifier In objClass.Qualifiers_
        If LCase(objClassQualifier.Name) = "dynamic" Then
            WScript.Echo objClass.Path_.Class & ": " & _
            objClassQualifier.Name & "=" & _
            objClassQualifier.Value
        End If
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Properties for a WMI Class

Description
Lists the properties for a specified WMI class.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
strNameSpace = "root\cimv2"
strClass = "Win32_Service"

Set objClass = GetObject("winmgmts:\\" & strComputer & _
    "\" & strNameSpace & ":" & strClass)

WScript.Echo strClass & " Class Properties"
WScript.Echo "------------------------------"

For Each objClassProperty In objClass.Properties_
    WScript.Echo objClassProperty.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Properties, Methods, and Qualifiers for a WMI Class

Description
Lists the class qualifiers, properties, property qualifiers, methods, and method qualifiers for a specified WMI class.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
strNameSpace = "root\cimv2"
strClass = "Win32_Service"

Set objClass = GetObject("winmgmts:\\" & strComputer & _
    "\" & strNameSpace & ":" & strClass)

WScript.Echo strClass & " Class Qualifiers"
WScript.Echo "------------------------------"
i = 1

For Each objClassQualifier In objClass.Qualifiers_
    If VarType(objClassQualifier.Value) = (vbVariant + vbArray) Then
        strQualifier = i & ". " & objClassQualifier.Name & " = " & _
            Join(objClassQualifier.Value, ",")
    Else
        strQualifier = i & ". " & objClassQualifier.Name & " = " & _
        objClassQualifier.Value
    End If
    WScript.Echo strQualifier
    strQualifier = ""
    i = i + 1
Next

WScript.Echo
WScript.Echo strClass & " Class Properties and Property Qualifiers"
WScript.Echo "------------------------------------------------------"
i = 1 : j = 1

For Each objClassProperty In objClass.Properties_
    WScript.Echo i & ". " & objClassProperty.Name
    For Each objPropertyQualifier In objClassProperty.Qualifiers_
        If VarType(objPropertyQualifier.Value) = (vbVariant + vbArray) Then
            strQualifier = i & "." & j & ". " & _
                objPropertyQualifier.Name & " = " & _
            Join(objPropertyQualifier.Value, ",")
        Else
            strQualifier = i & "." & j & ". " & _
                objPropertyQualifier.Name & " = " & _
            objPropertyQualifier.Value
        End If
        WScript.Echo strQualifier
        strQualifier = ""
        j = j + 1
    Next
    WScript.Echo
    i = i + 1 : j = 1
Next

WScript.Echo
WScript.Echo strClass & " Class Methods and Method Qualifiers"
WScript.Echo "-------------------------------------------------"
i = 1 : j = 1

For Each objClassMethod In objClass.Methods_
    WScript.Echo i & ". " & objClassMethod.Name
    For Each objMethodQualifier In objClassMethod.Qualifiers_
        If VarType(objMethodQualifier.Value) = (vbVariant + vbArray) Then
            strQualifier = i & "." & j & ". " & _
                objMethodQualifier.Name & " = " & _
            Join(objMethodQualifier.Value, ",")
        Else
            strQualifier = i & "." & j & ". " & _
                objMethodQualifier.Name & " = " & _
                    objMethodQualifier.Value
        End If
    WScript.Echo strQualifier
    strQualifier = ""
    j = j + 1
    Next

    WScript.Echo
    i = i + 1 : j = 1
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Qualifiers for a WMI Class

Description
Lists the class qualifiers for a specified WMI class.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
strNameSpace = "root\cimv2"
strClass = "Win32_Service"

Set objClass = GetObject("winmgmts:\\" & strComputer & _
    "\" & strNameSpace & ":" & strClass)

WScript.Echo strClass & " Class Qualifiers"
WScript.Echo "------------------------------"

For Each objClassQualifier In objClass.Qualifiers_
    If VarType(objClassQualifier.Value) = (vbVariant + vbArray) Then
        strQualifier = objClassQualifier.Name & " = " & _
            Join(objClassQualifier.Value, ",")
    Else
        strQualifier = objClassQualifier.Name & " = " & _
            objClassQualifier.Value
    End If
    WScript.Echo strQualifier
    strQualifier = ""
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating WMI Namespaces

Description
Lists only those WMI namespaces immediately below the connected namespace.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root")
Set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")

For Each objNameSpace In colNameSpaces
    WScript.Echo objNameSpace.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating WMI Providers

Description
Lists all WMI Providers installed in the root\cimv2 namespace.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colWin32Providers = objWMIService.InstancesOf("__Win32Provider")

For Each objWin32Provider In colWin32Providers
    WScript.Echo objWin32Provider.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating WMI Settings

Description
Returns a list of WMI settings as configured on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colWMISettings = objWMIService.ExecQuery _
    ("Select * from Win32_WMISetting")
For Each objWMISetting in colWMISettings
    Wscript.Echo "Default namespace: " & _
        objWMISetting.ASPScriptDefaultNamespace
    Wscript.Echo "Backup interval: " & objWMISetting.BackupInterval
    Wscript.Echo "Last backup: " & objWMISetting.BackupLastTime
    Wscript.Echo "Build version: " & objWMISetting.BuildVersion
    Wscript.Echo "Repository directory: " & _
        objWMISetting.DatabaseDirectory
    Wscript.Echo "Enable events: " & objWMISetting.EnableEvents
    Wscript.Echo "High threshold on client objects: " & _
        objWMISetting.HighThresholdOnClientObjects
    Wscript.Echo "High threshold on events: " & _
        objWMISetting.HighThresholdOnEvents
    Wscript.Echo "Installation folder: " & _
        objWMISetting.InstallationDirectory
    Wscript.Echo "Logging folder: " & objWMISetting.LoggingDirectory
    Wscript.Echo "Logging level: " & objWMISetting.LoggingLevel
    Wscript.Echo "Low threshold on client objects: " & _
        objWMISetting.LowThresholdOnClientObjects
    Wscript.Echo "Low threshold on events: " & _
        objWMISetting.LowThresholdOnEvents
    Wscript.Echo "Maximum log file size: " & objWMISetting.MaxLogFileSize
    Wscript.Echo "Maximum wait time on client objects: " & _
        objWMISetting.MaxWaitOnClientObjects
    Wscript.Echo "Maximum wait time on events: " & _
        objWMISetting.MaxWaitOnEvents
    Wscript.Echo "MOF Self-install folder: " & _
        objWMISetting.MofSelfInstallDirectory
    For i = 0 to Ubound(objWMISetting.AutorecoverMofs)
        Wscript.Echo "Autorecover MOF: " & _
            objWMISetting.AutorecoverMofs(i)
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing the Properties and Methods of the Win32 Classes

Description
Returns the properties and methods for all the WMI Win32 classes (for example, Win32_Service, Win32_Process, Win32_NTEventLog, etc.).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

For Each objclass in objWMIService.SubclassesOf()
    intCounter=0
    If Left(objClass.Path_.Class,5) = "Win32" Then
        For Each Qualifier in objClass.Qualifiers_
            If UCase(Trim(Qualifier.Name)) = "ASSOCIATION" Then
                intCounter = 1
            End If
        Next
        If x = 0 Then
            strComputer = "."
            Set objWMIService = GetObject _
                ("winmgmts:{impersonationLevel=impersonate}!\\" & _
                    strComputer & "\root\cimv2")
            Set strClass = objWMIService.Get(objClass.Path_.Class)
            Wscript.Echo "PROPERTIES:"
            For each strItem in strClass.properties_
                Wscript.Echo objClass.Path_.Class & vbTab & strItem.name
            Next
            Wscript.Echo "METHODS:"
            For Each strItem in strClass.methods_
                Wscript.Echo objClass.Path_.Class & vbTab & strItem.name
            Next
        End If
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing WMI cimV2 Classes

Description
Returns a list of all the WMI classes found in the cimV2 namespace.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

For Each objclass in objWMIService.SubclassesOf()
    Wscript.Echo objClass.Path_.Class
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing WMI Methods for a Class

Description
Lists the methods for a specified WMI class.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
strNameSpace = "root\cimv2"
strClass = "Win32_Service"

Set objClass = GetObject("winmgmts:\\" & strComputer & _
    "\" & strNameSpace & ":" & strClass)

WScript.Echo strClass & " Class Methods"
WScript.Echo "---------------------------"

For Each objClassMethod In objClass.Methods_
    WScript.Echo objClassMethod.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Default WMI Namespace

Description
Retrieve and display the current WMI "Default namespace for scripting" setting.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colWMISettings = objWMIService.InstancesOf("Win32_WMISetting")

For Each objWMISetting in colWMISettings
    Wscript.Echo "Default namespace for scripting: " & _
    objWMISetting.ASPScriptDefaultNamespace
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Definition of a WMI Class in MOF Format

Description
Retrieves and displays the textual representation of a WMI class definition in MOF (Managed Object Format) syntax.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
strNameSpace = "root\cimv2"
strClass = "Win32_Service"

Const wbemFlagUseAmendedQualifiers = &h20000

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\" & strNameSpace)
Set objClass = objWMIService.Get(strClass, wbemFlagUseAmendedQualifiers)
strMOF = objClass.GetObjectText_

WScript.Echo strMOF

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Checking the Size of a File Before Reading It

Description
Demonstration script that uses the FileSystemObject to ensure that a text file is not empty before attempting to read it. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\Windows\Netlogon.log")
If objFile.Size > 0 Then
    Set objReadFile = objFSO.OpenTextFile("C:\Windows\Netlogon.log", 1)
    strContents = objReadFile.ReadAll
    Wscript.Echo strContents
    objReadFile.Close
Else
    Wscript.Echo "The file is empty."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Text File

Description
Demonstration script that creates a new, empty text file. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\FSO\ScriptLog.txt")

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating and Naming a Text File

Description
Demonstration script that uses the FileSystemObject's GetTempName method to generate a file name, and then creates a file by that name.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = "C:\FSO"
strFileName = objFSO.GetTempName
strFullName = objFSO.BuildPath(strPath, strFileName)
Set objFile = objFSO.CreateTextFile(strFullName)
objFile.Close
objFSO.DeleteFile(strFullName)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Generating a File Name

Description
Demonstration script that uses the FileSystemObject's GetTempName method to generate random file names. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 1 to 10
    strTempFile = objFSO.GetTempName
    Wscript.Echo strTempFile
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading a Text File Character by Character

Description
Demonstration script that uses the FileSystemObject to read a text file character-by-character, and individually echo those characters to the screen. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\FSO\New Text Document.txt", 1)
Do Until objFile.AtEndOfStream
    strCharacters = objFile.Read(1)
    Wscript.Echo strCharacters
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading a Text File from the Bottom Up

Description
Demonstration script that uses the FileSystemObject to read a text file, and then to echo the text file in inverse order (that is, beginning with the last line in the text file and ending with the first line).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Dim arrFileLines()
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\FSO\ScriptLog.txt", 1)
Do Until objFile.AtEndOfStream
     Redim Preserve arrFileLines(i)
     arrFileLines(i) = objFile.ReadLine
     i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
    Wscript.Echo arrFileLines(l)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading a Text File into an Array

Description
Demonstration script that uses the VBScript Split command to read a line from a commas-separated values file, and then place the individual items in that line into an array.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\servers and services.txt", ForReading)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    arrServiceList = Split(strNextLine , ",")
    Wscript.Echo "Server name: " & arrServiceList(0)
    For i = 1 to Ubound(arrServiceList)
        Wscript.Echo "Service: " & arrServiceList(i)
    Next
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing Data to a Text File

Description
Demonstration script that retrieves the status for all the services installed on a computer, and then saves the service name and status to a text file.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\service_status.txt", ForAppending, True)
Set colServices =  GetObject("winmgmts:").ExecQuery _
    ("Select * from Win32_Service")
For Each objService in colServices
    objTextFile.WriteLine(objService.DisplayName & vbTab & _
        objService.State)
Next
objTextFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding Elements to a Dictionary

Description
Demonstration script that adds three key-item pairs to a Script Runtime Dictionary. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an Instance of Internet Explorer

Description
Demonstration script that creates an instance of Internet Explorer, opened to a blank page.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=300
objExplorer.Height = 150
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating Script Documentation Using Script Comments

Description
Demonstrates the use of the FileSystemObject as a way to copy comments from a script to a separate text file. Requires comments to have been marked using '*.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objScriptFile = objFSO.OpenTextFile("c:\scripts\Service_Monitor.vbs", _
    ForReading)
Set objCommentFile = objFSO.OpenTextFile("c:\scripts\Comments.txt", _
    ForWriting, TRUE)
Do While objScriptFile.AtEndOfStream <> TRUE
    strCurrentLine = objScriptFile.ReadLine
    intIsComment = Instr(1,strCurrentLine,"'*")
    If intIsComment > 0 Then
        objCommentFile.Write strCurrentLine & VbCrLf
    End If
Loop
objScriptFile.Close
objCommentFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Number of Items in a Dictionary

Description
Demonstration script that counts the number of key-item pairs in a Script Runtime Dictionary. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
Wscript.Echo objDictionary.Count

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying Real Time Events in a Command Window

Description
Creates a temporary event consumer that monitors the event log for error events. When an error event occurs, the script displays the event information in the command window.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Security)}!\\" & _
        strComputer & "\root\cimv2")
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("Select * from __InstanceCreationEvent within 5 where TargetInstance isa " _
        & "'Win32_NTLogEvent' and TargetInstance.EventType = '1'")
Do
    Set objLatestEvent = colMonitoredEvents.NextEvent
        Wscript.Echo "Record No.: " & _
            objLatestEvent.TargetInstance.RecordNumber
        Wscript.Echo "Event ID: " & objLatestEvent.TargetInstance.EventCode
        Wscript.Echo "Time: " & objLatestEvent.TargetInstance.TimeWritten
        Wscript.Echo "Source: " & objLatestEvent.TargetInstance.SourceName
        Wscript.Echo "Category: " & _
            objLatestEvent.TargetInstance.CategoryString
        Wscript.Echo "Event Type: " & objLatestEvent.TargetInstance.Type
        Wscript.Echo "Computer: " & _
            objLatestEvent.TargetInstance.ComputerName
        Wscript.Echo "User: " & objLatestEvent.TargetInstance.User
        Wscript.echo "Text: " & objLatestEvent.TargetInstance.Message
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying Tabular Output in a Command Window

Description
Retrieves service data from a computer, and then outputs that data in tabular format in a command window.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set colServices = GetObject("winmgmts:"). _
    ExecQuery("Select * from Win32_Service")
For Each objService in colServices
    intPadding = 50 - Len(objService.DisplayName)
    intPadding2 = 17 - Len(objService.StartMode)
    strDisplayName = objService.DisplayName & Space(intPadding)
    strStartMode = objService.StartMode & Space(intPadding2)
    Wscript.Echo strDisplayName & strStartMode & objService.State
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Masking Command Line Passwords

Description
Demonstration script that uses ScriptPW.dll to mask passwords entered at the command line.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objPassword = CreateObject("ScriptPW.Password")
WScript.StdOut.Write "Please enter your password:"
strPassword = objPassword.GetPassword()
Wscript.Echo
Wscript.Echo "Your password is: " & strPassword

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Masking Passwords Using Internet Explorer

Description
Demonstration script that creates an instance of Internet Explorer, and retrieves a password typed into a password-style text box. Requires a Web page named password.htm with the appropriate text box.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objExplorer = WScript.CreateObject _
    ("InternetExplorer.Application", "IE_")
objExplorer.Navigate "file:///c:\scripts\password.htm"
objExplorer.Visible = 1
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=400
objExplorer.Height = 250
objExplorer.Left = 0
objExplorer.Top = 0
Do While (objExplorer.Document.Body.All.OKClicked.Value = "")
    Wscript.Sleep 250
Loop
strPassword = objExplorer.Document.Body.All.PasswordBox.Value
objExplorer.Quit
Wscript.Sleep 250
Wscript.Echo strPassword

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing All Elements from a Dictionary

Description
Demonstration script that deletes all the key-item pairs from a Script Runtime Dictionary. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
colKeys = objDictionary.Keys
Wscript.Echo "First run: "
For Each strKey in colKeys
    Wscript.Echo strKey
Next
objDictionary.RemoveAll
colKeys = objDictionary.Keys
Wscript.Echo VbCrLf & "Second run: "
For Each strKey in colKeys
    Wscript.Echo strKey
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing Debugging Comments

Description
Demonstrates the use of the FileSystemObject as a way to remove debugging comments from a script. Requires comments to have been marked as '* BUG.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Scripts\CreateUser.vbs", ForReading)

Do While objTextFile.AtEndOfStream <> true
    strNextLine = objTextFile.Readline
    intCheckForBugComment = Instr(strNextLine, "'* BUG")
    If intCheckForBugComment = 0 Then
        strSavedLines = strSavedLines & strNextLine & VbCrLf
    End If
Loop

Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\CreateUser.vbs ", ForWriting)
objTextFile.Write strSavedLines
objTextFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing One Element from a Dictionary

Description
Demonstration script that deletes a specific key-item pair from a Script Runtime Dictionary. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
colKeys = objDictionary.Keys
Wscript.Echo "First run: "

For Each strKey in colKeys
    Wscript.Echo strKey
Next

objDictionary.Remove("Printer 2")
colKeys = objDictionary.Keys
Wscript.Echo VbCrLf & "Second run: "

For Each strKey in colKeys
    Wscript.Echo strKey
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving a Web Page

Description
Retrieves the HTML source for the Web page http://www.microsoft.com. This script contributed by Maxim Stepin of Microsoft.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

url="http://www.microsoft.com"
Set objHTTP = CreateObject("MSXML2.XMLHTTP")
Call objHTTP.Open("GET", url, FALSE)
objHTTP.Send
WScript.Echo(objHTTP.ResponseText)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Command Line Arguments from an Active Directory Container

Description
Demonstration script that retrieves the names of all the computers in an Active Directory container, and then returns service information from each of those computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
i = 0
Set objOU = GetObject("LDAP://CN=Computers, DC=fabrikam, DC=com")
objOU.Filter = Array("Computer")
For Each objComputer in objOU
    objDictionary.Add i, objComputer.CN
    i = i + 1
Next
For Each objItem in objDictionary
    Set colServices = GetObject("winmgmts://" & _
        objDictionary.Item(objItem) _
            & "").ExecQuery("Select * from Win32_Service")
    Wscript.Echo colServices.Count
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Command Line Arguments from a Text File

Description
Demonstration script that opens a hypothetical text file consisting of server names, then retrieves service information from each on the servers in the file.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt", ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
    objDictionary.Add i, strNextLine
    i = i + 1
Loop
For Each objItem in objDictionary
    Set colServices = GetObject("winmgmts://" & _
        objDictionary.Item(objItem) _
            & "").ExecQuery("Select * from Win32_Service")
    Wscript.Echo colServices.Count
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Saving Data in XML Format

Description
Demonstration script that retrieves service information for a computer, and then saves that data as an XML file.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const ForAppending = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\service_status.xml", ForAppending, True)
objTextFile.WriteLine ""
objTextFile.Write ""
objTextFile.WriteLine ""
strComputer = "."
Set colServices = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"). _
        ExecQuery("Select * from Win32_Service")
For Each objService in colServices
    objTextFile.WriteLine ""
    objTextFile.WriteLine ""
    objTextFile.WriteLine objService.DisplayName
    objTextFile.WriteLine ""
    objTextFile.WriteLine ""
    objTextFile.WriteLine objService.State
    objTextFile.WriteLine ""
    objTextFile.WriteLine ""
Next
objTextFile.WriteLine ""
objTextFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Sorting WMI Data

Description
Demonstration script showing how WMI data can be sorted using a disconnected recordset (by itself, WMI does not allow you to specify a sort order for returned data). In this script, service information is retrieved using WMI and is stored in a disconnected recordset, a recordset that is not tied to a physical data source. The Sort method is then used to sort the service data by service state rather than by service name.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const adVarChar = 200
Const MaxCharacters = 255

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "ServiceName", adVarChar, MaxCharacters
DataList.Fields.Append "ServiceState", adVarChar, MaxCharacters
DataList.Open

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set ServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service")

For Each Service in ServiceList
    DataList.AddNew
    DataList("ServiceName") = Service.Name
    DataList("ServiceState") = Service.State
    DataList.Update
Next

DataList.Sort = "ServiceState"
DataList.MoveFirst

Do Until DataList.EOF
    Wscript.Echo DataList.Fields.Item("ServiceName") _
        & vbTab & DataList.Fields.Item("ServiceState")
    DataList.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Suppressing Multiple Event Notifications

Description
Issues an alert if available space on a disk drive falls below 100 megabytes. Will wait one hour before issuing the next alert.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

dtmStartTime = Now
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objDiskDrives = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For Each objDrive in objDiskDrives
    If objDrive.FreeSpace < 10000000 Then
        Wscript.Echo "Drive is low on disk space."
    End If
Next
Do
Set objDiskDrives = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk")
For Each objDrive in objDiskDrives
    If objDrive.FreeSpace < 10000000 Then
        intElapsedHours = DateDiff("h", dtmStartTime, Now)
            If intElapsedHours >= 1 Then
                Wscript.Echo "Drive is low on disk space."
            dtmStartTime = Now
        End If
    End If
Next
Wscript.Sleep 1000
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Tracking Script Progress in a Command Window

Description
Demonstrates the use of StdOut as a method for indicating the progress being made by a script.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Windows Script Host 5.6 installed
Windows NT 4.0 | Yes, with Windows Script Host 5.6 installed
Windows 98 | Yes, with Windows Script Host 5.6 installed

Script Code

Wscript.Echo "Processing information. This might take several minutes."
strComputer = "."
Set colServices = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2"). _
    ExecQuery("Select * from Win32_Service")
For Each objService in colServices
    Wscript.StdOut.Write(".")
Next
Wscript.StdOut.WriteLine
Wscript.Echo "Service information processed."

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Tracking Script Progress Using Internet Explorer

Description
Demonstrates how to use Internet Explorer as a method for indicating the progress being made by a script.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width=400
objExplorer.Height = 200
objExplorer.Left = 0
objExplorer.Top = 0
Do While (objExplorer.Busy)
    Wscript.Sleep 200
Loop
objExplorer.Visible = 1
objExplorer.Document.Body.InnerHTML = "Retrieving service information. " _
    & "This might take several minutes to complete."
strComputer = "."
Set colServices = GetObject("winmgmts: \\" & strComputer & "\root\cimv2"). _
    ExecQuery("Select * from Win32_Service")
For Each objService in colServices
    Wscript.Sleep 200
Next
objExplorer.Document.Body.InnerHTML = "Service information retrieved."
Wscript.Sleep 3000
Wscript.Quit

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using a Text File as a Command Line Argument

Description
Demonstration script that allows you to drag a text file (consisting of server names) onto the script icon in Windows Explorer. The script then opens the text file, then retrieves service information from each on the servers in the file.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objArgs = WScript.Arguments
Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(objArgs(0), ForReading)
i = 0

Do While objTextFile.AtEndOfStream <> True
  strNextLine = objTextFile.Readline
  objDictionary.Add i, strNextLine
  i = i + 1
Loop

For Each objItem in objDictionary
  Set colServices = GetObject("winmgmts://" & objDictionary.Item(objItem) _
      & "").ExecQuery("Select * from Win32_Service")
  Wscript.Echo colServices.Count
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Verifying the Existence of a Dictionary Key

Description
Demonstration script that verifies the existence of a particular key within a Script Runtime Dictionary. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "Printer 1", "Printing"
objDictionary.Add "Printer 2", "Offline"
objDictionary.Add "Printer 3", "Printing"
If objDictionary.Exists("Printer 4") Then
    Wscript.Echo "Printer 4 is in the Dictionary."
Else
    Wscript.Echo "Printer 4 is not in the Dictionary."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Printer Connection

Description
Adds a printer connection to a network printer. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\PrintServer1\Xerox300"
WshNetwork.SetDefaultPrinter "\\PrintServer1\Xerox300"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Printer

Description
Deletes a printer named ScriptedPrinter.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer where DeviceID = 'ScriptedPrinter'")
For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Printer Connections

Description
Enumerates all the printer connections on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo "Name: " & objPrinter.Name
    Wscript.Echo "Location: " & objPrinter.Location
    Wscript.Echo "Default: " & objPrinter.Default
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing a Printer Connection

Description
Removes a printer connection to a network printer. Script must be run on the local computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\PrintServer\xerox3006"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming a Printer

Description
Renames both a printer and its printer share name.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where DeviceID = 'HP LaserJet 4Si M'")
For Each objPrinter in colPrinters
    objPrinter.RenamePrinter("ArtDepartmentPrinter")
Next
Set colPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer Where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrinters
    objPrinter.ShareName = "ArtDepartmentPrinter"
    objPrinter.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Default Printer

Description
Sets the default printer on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Name = 'ScriptedPrinter'")
For Each objPrinter in colInstalledPrinters
    objPrinter.SetDefaultPrinter()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Default Printer Based on Queue Length

Description
Examines all the print queues on a computer, and sets the default printer to the queue with the fewest documents.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

intSmallestQueue = 1000
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues =  objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_Spooler_PrintQueue " _
        & "Where Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
    intCurrentQueue = objPrintQueue.Jobs + objPrintQueue.JobsSpooling
    If intCurrentQueue <= intSmallestQueue Then
        strNewDefault = objPrintQueue.Name
        intSmallestQueue = intCurrentQueue
    End If
Next
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Name = '" & strNewDefault & "'")
For Each objPrinter in colInstalledPrinters
    objPrinter.SetDefaultPrinter()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing Print Job Priority

Description
Uses ADSI to change the priority of current print jobs based on the size of those print jobs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objPrinter = GetObject("WinNT://atl-dc-02/ArtDepartmentPrinter, printqueue")
For each objPrintJob in objPrinter.PrintJobs
    If objPrintJob.Size > 400000 Then
        objPrintJob.Put "Priority" , 2
        objPrintJob.SetInfo
    Else
        objPrintJob.Put "Priority" , 3
        objPrintJob.SetInfo
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing Print Job Start Time

Description
Uses ADSI to change the start time for all print jobs larger than 400K to 2 AM.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client extensions installed
Windows 98 | Yes, with Active Directory Client extensions installed

Script Code

Set objPrinter = GetObject("WinNT://atl-dc-02/ArtDepartmentPrinter,printqueue")
For each objPrintQueue in objPrinter.PrintJobs
If objPrintQueue.Size > 400000 Then
    objPrintQueue.Put "StartTime" , TimeValue("2:00:00 AM")
    objPrintQueue.SetInfo
End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Printer Availability

Description
Configures a printer so that documents can only be printed between 8 AM and 6 PM.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

dtmStartTime= "********080000.000000+000"
dtmEndTime= "********180000.000000+000"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer Where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrinters
    objPrinter.StartTime = dtmStartTime
    objPrinter.UntilTime = dtmEndTime
    objPrinter.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Printer Locations

Description
Uses ADSI to configure the location attribute for all printers in a specified OU.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://OU = Finance, DC = fabrikam, DC = com")
objOU.Filter = Array("printqueue")
For Each objPrintQueue In objOU
    objPrintQueue.Put "Location" , "USA/Redmond/Finance Building"
    objPrintQueue.SetInfo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Printer Priority

Description
Sets the priority for a printer to 2.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
    ("Select * From Win32_Printer where DeviceID = 'ArtDepartmentPrinter' ")
For Each objPrinter in colPrinters
    objPrinter.Priority = 2
    objPrinter.Put_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting All Printers on a Print Server

Description
Deletes all the printers from a print server.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Print Jobs

Description
Deletes all print jobs larger than 1 megabyte.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob Where Size > 1000000")
For Each objPrintJob in colPrintJobs
    objPrintJob.Delete_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Specific Printers

Description
Deletes all HP QuietJet printers installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where DriverName = 'HP QuietJet'")
For Each objPrinter in colInstalledPrinters
    objPrinter.Delete_
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All Published Printers

Description
Returns a list of all the printers published in Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
    & " 'LDAP://DC=fabrikam,DC=com'  where objectClass='printQueue'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
    Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Printer Capabilities

Description
Lists properties and capabilities for all the printers installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrinterConfiguration")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo "Name: " & objPrinter.Name
    Wscript.Echo "Collate: " & objPrinter.Collate
    Wscript.Echo "Copies: " & objPrinter.Copies
    Wscript.Echo "Driver Version: " & objPrinter.DriverVersion
    Wscript.Echo "Duplex: " & objPrinter.Duplex
    Wscript.Echo "Horizontal Resolution: " & _
        objPrinter.HorizontalResolution
    If objPrinter.Orientation = 1 Then
        strOrientation =  "Portrait"
    Else
        strOrientation = "Landscape"
    End If
    Wscript.Echo "Orientation : " & strOrientation
    Wscript.Echo "Paper Length: " & objPrinter.PaperLength / 254
    Wscript.Echo "Paper Width: " & objPrinter.PaperWidth / 254
    Wscript.Echo "Print Quality: " & objPrinter.PrintQuality
    Wscript.Echo "Scale: " & objPrinter.Scale
    Wscript.Echo "Specification Version: " & _
        objPrinter.SpecificationVersion
    If objPrinter.TTOption = 1 Then
        strTTOption = "Print TrueType fonts as graphics."
    Elseif objPrinter.TTOption = 2 Then
        strTTOption = "Download TrueType fonts as soft fonts."
    Else
        strTTOption = "Substitute device fonts for TrueType fonts."
    End If
    Wscript.Echo "True Type Option: " & strTTOption
    Wscript.Echo "Vertical Resolution: " & objPrinter.VerticalResolution
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing a Printer

Description
Installs a logical network printer on a print server.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName   = "IP_169.254.110.160"
objPrinter.DeviceID   = "ScriptedPrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "ScriptedPrinter"
objPrinter.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing Multiple Printers for One Print Device

Description
Installs two logical network printers (with different printer priorities) for the same physical print device.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get("Win32_Printer").SpawnInstance_
objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName   = "IP_169.254.110.160"
objPrinter.DeviceID   = "PublicPrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.ShareName = "PublicPrinter"
objPrinter.Put_

objPrinter.DriverName = "HP LaserJet 4000 Series PS"
objPrinter.PortName   = "IP_169.254.110.160"
objPrinter.DeviceID   = "PrivatePrinter"
objPrinter.Location = "USA/Redmond/Building 37/Room 114"
objPrinter.Priority = 2
objPrinter.Network = True
objPrinter.Shared = True
objPrinter.Hidden = True
objPrinter.ShareName = "PrivatePrinter"
objPrinter.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Printer Status

Description
Displays current status for all printers on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    Wscript.Echo  "Name: " & objPrinter.Name
    Wscript.Echo  "Location: " & objPrinter.Location
    Select Case objPrinter.PrinterStatus
        Case 1
            strPrinterStatus = "Other"
        Case 2
            strPrinterStatus = "Unknown"
        Case 3
            strPrinterStatus = "Idle"
        Case 4
            strPrinterStatus = "Printing"
        Case 5
            strPrinterStatus = "Warmup"
    End Select
    Wscript.Echo  "Printer Status: " & strPrinterStatus
    Wscript.Echo  "Server Name: " & objPrinter.ServerName
    Wscript.Echo  "Share Name: " & objPrinter.ShareName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Printers with a Temporary Event Subscription

Description
Uses a temporary event consumer to issues alerts any time a printer changes status.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService. _
    ExecNotificationQuery("Select * from __instancemodificationevent " _
        & "within 30 where TargetInstance isa 'Win32_Printer'")
i = 0
Do While i = 0
    Set objPrinter = colPrinters.NextEvent
    If objPrinter.TargetInstance.PrinterStatus <> _
        objPrinter.PreviousInstance.PrinterStatus Then
        Select Case objPrinter.TargetInstance.PrinterStatus
            Case 1 strCurrentState = "Other"
            Case 2 strCurrentState = "Unknown"
            Case 3 strCurrentState = "Idle"
            Case 4 strCurrentState = "Printing"
            Case 5 strCurrentState = "Warming Up"
        End Select
        Select Case objPrinter.PreviousInstance.PrinterStatus
            Case 1 strPreviousState = "Other"
            Case 2 strPreviousState = "Unknown"
            Case 3 strPreviousState = "Idle"
            Case 4 strPreviousState = "Printing"
            Case 5 strPreviousState = "Warming Up"
        End Select
        Wscript.Echo objPrinter.TargetInstance.Name _
            &  " is " & strCurrentState _
                & ". The printer previously was " & strPreviousState & "."
    End If
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Print Job Status

Description
Returns the job ID, user name, and total pages for each print job on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, Owner, Total Pages"
For Each objPrintJob in colPrintJobs
    strPrinter = Split(objPrintJob.Name,",",-1,1)
    Wscript.Echo strPrinter(0) & ", " & _
        objPrintJob.JobID & ", " &  objPrintJob.Owner & ", " _
            & objPrintJob.TotalPages
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Print Queues

Description
Uses cooked performance counters to return the number of jobs currently in each print queue on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues =  objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where " & _
        "Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
    Wscript.Echo "Name: " & objPrintQueue.Name
    Wscript.Echo "Current jobs: " & objPrintQueue.Jobs
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Print Queue Times

Description
Identifies any print jobs that have been in the print queue for more than 15 minutes.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const USE_LOCAL_TIME = True
Set DateTime = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
Wscript.Echo "Print Queue, Job ID, TimeSubmitted, Total Pages"
For Each objPrinter in colInstalledPrinters
    DateTime.Value = objPrinter.TimeSubmitted
    dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
    TimeinQueue = DateDiff("n", actualTime, Now)
    If TimeinQueue > 15 Then
        strPrinterName = Split(objPrinter.Name,",",-1,1)
        Wscript.Echo strPrinterName(0) & ", " _
            & objPrinter.JobID & ", " & dtmActualTime & ", " & _
                objPrinter.TotalPages
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring the Print Service

Description
Returns the status of the Spooler service (running, stopped, paused, etc.).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices =  objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name = 'Spooler'")
For Each objService in colRunningServices
    Wscript.Echo objService.DisplayName  & VbTab & objService.State
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Notifying Users of a Purged Print Queue

Description
Uses Msg.exe to send a network alert to any users who had documents in a print queue about to be purged. After sending the alert, the script purges the print queue.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
For Each objPrintJob in colInstalledPrintJobs
    strPrinterName = Split(objPrintJob.Name,",",-1,1)
    If objDictionary.Exists(objPrintJob.Notify) Then
    Else
        objDictionary.Add objPrintJob.Notify, strPrinterName(0)
    End If
Next
arrKeys = objDictionary.Keys
arrItems = objDictionary.Items
For i = 0 to objDictionary.Count - 1
    Message = "The documents you were printing on printer "
    Message = Message & arrItems(i)
    Message = Message & " had to be deleted from the print queue. "
    Message = Message & "You will need to reprint these documents."
    CommandString = "%comspec% /c msg " & arrKeys(i) & " " & Chr(34) _
        & Message & Chr(34)
    WshShell.Run CommandString, 0, True
Next
Set colInstalledPrinters = objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    objPrinter.CancelAllJobs()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pausing a Printer

Description
Pauses a printer named ArtDepartmentPrinter.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each objPrinter in colInstalledPrinters
    ObjPrinter.Pause()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pausing Printers with Empty Print Queues

Description
Pauses any printers that have no pending print jobs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
    Set colPrintJobs = objWMIService.ExecQuery _
        ("Select * from Win32_PerfFormattedData_Spooler_PrintQueue " _
            & "Where Name = '" & objPrinter.Name & "'")
    For Each objPrintQueue in colPrintJobs
        If objPrintQueue.Jobs = 0 and objPrintQueue.Name <> "_Total" Then
            objPrinter.Pause()
        End If
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pausing Print Jobs

Description
Pauses all the print jobs on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
    objPrintJob.Pause
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Purging a Print Queue

Description
Deletes all the print jobs for a printer named HP QuietJet.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Name = 'HP QuietJet'")
For Each objPrinter in colInstalledPrinters
    objPrinter.CancelAllJobs()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Receiving Notification When a Printer Stops

Description
Checks the status for each printer on a computer, and issues an alert if any of these printers have stopped.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where PrinterStatus = '1' " _
        & "or PrinterStatus = '2'")
If colInstalledPrinters.Count = 0 Then
    Wscript.Echo "All printers are functioning correctly."
Else
    For Each objPrinter in colInstalledPrinters
        Wscript.Echo "Printer " & objprinter.Name & " is not responding."
    Next
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renaming a Printer Published in Active Directory

Description
Uses the MoveHere method to rename a published printer in an OU.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")
objOU.MoveHere _
    "LDAP://cn=Printer1,ou=HR,dc=NA,dc=fabrikam,dc=com", "cn=HRPrn1"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reporting Print Queue Statistics

Description
Returns total number of jobs, total number of pages, and largest job for all print queues on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
    intTotalJobs = intTotalJobs + 1
    intTotalPages = intTotalPages + objPrintJob.TotalPages
    If objPrintJob.TotalPages > intMaxPrintJob Then
        intMaxPrintJob = objPrintJob.TotalPages
    End If
Next
Wscript.Echo "Total print jobs in queue: " & intTotalJobs
Wscript.Echo "Total pages in queue: " & intTotalPages
Wscript.Echo "Largest print job in queue: " & intMaxPrintJob

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resuming All Paused Printers

Description
Resumes all the paused printers on a print server.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const PRINTER_IS_PAUSED = 8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer where ExtendedPrinterStatus = 8")
For Each objPrinter in colInstalledPrinters
    ObjPrinter.Resume()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resuming a Paused Printer

Description
Resumes a paused printer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer Where Name = 'ArtDepartmentPrinter'")
For Each objPrinter in colInstalledPrinters
    ObjPrinter.Resume()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resuming Print Jobs

Description
Resumes all the print jobs on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintJobs =  objWMIService.ExecQuery _
    ("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
    objPrintJob.Resume
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Print Queue Statistics

Description
Uses cooked performance counters to retrieve data such as total number of jobs printed and total number of printing errors for each print queue on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrintQueues =  objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_Spooler_PrintQueue Where " & _
        "Name <> '_Total'")
For Each objPrintQueue in colPrintQueues
    Wscript.Echo "Name: " & objPrintQueue.Name
    Wscript.Echo "Jobs: " & objPrintQueue.Jobs
    Wscript.Echo "Current jobs spooling: " & objPrintQueue.JobsSpooling
    Wscript.Echo "Maximum jobs spooling: " & objPrintQueue.MaxJobsSpooling
    Wscript.Echo "Total jobs printed: " & objPrintQueue.TotalJobsPrinted
    Wscript.Echo "NamJob errors: " & objPrintQueue.JobErrors
    Wscript.Echo "Not ready errors: " & objPrintQueue.NotReadyErrors
    Wscript.Echo "Out of paper errors: " & objPrintQueue.OutOfPaperErrors
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Searching for Specific Printers

Description
Searches Active Directory for all printers with a priority of 2.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _
    & "'LDAP://DC=fabrikam,DC=com'  where objectClass='printQueue' and " _
        & " Priority = 2 "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
    Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
    objRecordSet.MoveNext
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Transfering Print Jobs to a Different Print Queue

Description
Changes the TCP/IP printer port for a logical printer, which has the net effect of transferring existing print jobs to the new printer port, and thus to a different printer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objPrinter = objWMIService.Get _
    ("Win32_Printer.DeviceID='ArtDepartmentPrinter'")
objPrinter.PortName = "IP_192.168.1.10"
objPrinter.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Updating Printer Locations

Description
Uses ADSI to update the location attribute for all printers in a specified OU.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://OU=Finance, DC=fabrikam, DC=com")
objOU.Filter = Array("printqueue")
For Each objPrintQueue In objOU
    strNewLocation = "Redmond/" & objPrintQueue.Location
    objPrintQueue.Put "Location" , strNewLocation
    objPrintQueue.SetInfo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting A Printer Port

Description
Deletes a TCP/IP printer port from a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPorts =  objWMIService.ExecQuery _
    ("Select * from Win32_TCPIPPrinterPort Where Name = 'IP_169.254.110.14'")
For Each objPort in colInstalledPorts
    objPort.Delete
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Unused Printer Ports

Description
Deletes any printer ports that have been installed on a computer but are not in use.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colPrinters
    objDictionary.Add objPrinter.PortName, objPrinter.PortName
Next
Set colPorts = objWMIService.ExecQuery _
    ("Select * from Win32_TCPIPPrinterPort")
For Each objPort in colPorts
    If objDictionary.Exists(objPort.Name) Then
    Else
        ObjPort.Delete_
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Printer Port Availability

Description
Identifies all the TCP/IP printer ports on a computer, and indicates which ports are being used and which ports are available.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_Printer")
For Each objPrinter in colPrinters
    objDictionary.Add objPrinter.PortName, objPrinter.PortName
Next
Set colPorts = objWMIService.ExecQuery _
    ("Select * from Win32_TCPIPPrinterPort")
For Each objPort in colPorts
    If objDictionary.Exists(objPort.Name) Then
        strUsedPorts = strUsedPorts & _
            objDictionary.Item(objPort.Name) & VbCrLf
    Else
        strFreePorts = strFreePorts & objPort.Name & vbCrLf
    End If
Next
Wscript.Echo "The following ports are in use: " & VbCrLf & strUsedPorts
Wscript.Echo "The following ports are available: " & VbCrLf & strFreePorts

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Printer Drivers

Description
Lists all the printer drives that have been installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery _
    ("Select * from Win32_PrinterDriver")
For each objPrinter in colInstalledPrinters
    Wscript.Echo "Config File: " & objPrinter.ConfigFile
    Wscript.Echo "Data File: " & objPrinter.DataFile
    Wscript.Echo "Description: " & objPrinter.Description
    Wscript.Echo "Driver Path: " & objPrinter.DriverPath
    Wscript.Echo "File Path: " & objPrinter.FilePath
    Wscript.Echo "Help File: " & objPrinter.HelpFile
    Wscript.Echo "INF Name: " & objPrinter.InfName
    Wscript.Echo "Monitor Name: " & objPrinter.MonitorName
    Wscript.Echo "Name: " & objPrinter.Name
    Wscript.Echo "OEMUrl: " & objPrinter.OEMUrl
    Wscript.Echo "Supported Platform: " & objPrinter.SupportedPlatform
    Wscript.Echo "Version: " & objPrinter.Version
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Printer Port Properties

Description
Lists properties of all the TCP/IP printer ports installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colPorts =  objWMIService.ExecQuery _
    ("Select * from Win32_TCPIPPrinterPort")
For Each objPort in colPorts
    Wscript.Echo "Description: " & objPort.Description
    Wscript.Echo "Host Address: " & objPort.HostAddress
    Wscript.Echo "Name: " & objPort.Name
    Wscript.Echo "Port Number: " & objPort.PortNumber
    Wscript.Echo "Protocol: " & objPort.Protocol
    Wscript.Echo "SNMP Community: " & objPort.SNMPCommunity
    Wscript.Echo "SNMP Dev Index: " & objPort.SnMPDevIndex
    Wscript.Echo "SNMP Enabled: " & objPort.SNMPEnabled
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing a Printer Driver not Found in Drivers Cab

Description
Installs a hypothetical printer using a print driver not found in Drivers.cab.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = "NewPrinter Model 2900"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
objDriverPath = "C:\Scripts\NewPrinter.dll"
objInfname = "C:\Scripts\NewPrinter.inf"
intResult = objDriver.AddPrinterDriver(objDriver)
Wscript.Echo intResult

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing Printer Drivers

Description
Installs the printer driver for an Apple LaserWriter 8500 printer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objWMIService = GetObject("winmgmts:")
Set objDriver = objWMIService.Get("Win32_PrinterDriver")
objDriver.Name = "Apple LaserWriter 8500"
objDriver.SupportedPlatform = "Windows NT x86"
objDriver.Version = "3"
errResult = objDriver.AddPrinterDriver(objDriver)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing Printer Ports

Description
Installs a TCP/IP printer port on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objWMIService = GetObject("winmgmts:")
Set objNewPort = objWMIService.Get _
    ("Win32_TCPIPPrinterPort").SpawnInstance_
objNewPort.Name = "IP_169.254.110.14"
objNewPort.Protocol = 1
objNewPort.HostAddress = "169.254.110.14"
objNewPort.PortNumber = "9999"
objNewPort.SNMPEnabled = False
objNewPort.Put_

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing the Priority Of a Running Process

Description
Changes the priority of a running instance of Notepad.exe from Normal to Above Normal.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ABOVE_NORMAL = 32768
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcesses
    objProcess.SetPriority(ABOVE_NORMAL)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Higher Priority Process

Description
Starts Notepad.exe with an Above Normal priority.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const ABOVE_NORMAL = 32768
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.PriorityClass = ABOVE_NORMAL
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
objProcess.Create "Notepad.exe", Null, objConfig, intProcessID

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Process in a Hidden Window

Description
Starts Notepad.exe on the local computer, but in a hidden window.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Const HIDDEN_WINDOW = 12
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create("Notepad.exe", null, objConfig, intProcessID)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Process on a Remote Computer

Description
Starts Notepad.exe on a remote computer. On Windows XP and Windows Server 2003, Notepad will run in a hidden window.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "webserver"
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")

Error = objWMIService.Create("notepad.exe", null, null, intProcessID)
If Error = 0 Then
    Wscript.Echo "Notepad was started with a process ID of " _
         & intProcessID & "."
Else
    Wscript.Echo "Notepad could not be started due to error " & _
        Error & "."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Process Ownership

Description
Reports the account name under which each process on a computer is running.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process")
For Each objProcess in colProcessList
    colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
    Wscript.Echo "Process " & objProcess.Name & " is owned by " _
        & strUserDomain & "\" & strNameOfUser & "."
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Threads

Description
Returns a list of threads and thread states for each process running on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set objDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
    ("Select * from Win32_Process")
For each objProcess in colProcesses
    objDictionary.Add objProcess.ProcessID, objProcess.Name
Next
Set colThreads = objWMIService.ExecQuery _
    ("Select * from Win32_Thread")
For each objThread in colThreads
    intProcessID = CInt(objThread.ProcessHandle)
    strProcessName = objDictionary.Item(intProcessID)
    Wscript.Echo strProcessName & VbTab & objThread.ProcessHandle & _
        VbTab & objThread.Handle & VbTab & objThread.ThreadState
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Preventing a Process from Running

Description
Temporary event consumer that terminates any new instances of Notepad.exe as soon as those new instances are created.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colMonitoredProcesses = objWMIService. _
    ExecNotificationQuery("select * from __instancecreationevent " _
        & " within 1 where TargetInstance isa 'Win32_Process'")
i = 0
Do While i = 0
    Set objLatestProcess = colMonitoredProcesses.NextEvent
    If objLatestProcess.TargetInstance.Name = "notepad.exe" Then
    objLatestProcess.TargetInstance.Terminate
    End If
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Terminating a Process

Description
Terminates any running instances of Notepad.exe.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Notepad.exe'")
For Each objProcess in colProcessList
    objProcess.Terminate()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Checking Registry Key Access

Checking Registry Key Access Rights

Description
Uses WMI to check access rights for the logged on user to HKLM\SYSTEM\CurrentControlSet.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const KEY_QUERY_VALUE = &H0001
const KEY_SET_VALUE = &H0002
const KEY_CREATE_SUB_KEY = &H0004
const DELETE = &H00010000

const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet"

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_QUERY_VALUE, _
    bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Query Value Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Query Value Access Rights on Key"
End If

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_SET_VALUE, _
    bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Set Value Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Set Value Access Rights on Key"
End If

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, KEY_CREATE_SUB_KEY, _
    bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Create SubKey Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Create SubKey Access Rights on Key"
End If

oReg.CheckAccess HKEY_LOCAL_MACHINE, strKeyPath, DELETE, bHasAccessRight
If bHasAccessRight = True Then
    StdOut.WriteLine "Have Delete Access Rights on Key"
Else
    StdOut.WriteLine "Do Not Have Delete Access Rights on Key"
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a MultiString Value

Description
Uses WMI to create a string a multi-string value under HKLM\SOFTWARE\System Admin Scripting Guide.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "Multi String Value Name"
arrStringValues = Array("first string", "second string",_
 "third string", "fourth string")

oReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,arrStringValues

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Registry Key

Description
Uses WMI to create a registry key HKLM\SOFTWARE\System Admin Scripting Guide.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating Expanded String Values

Description
Uses WMI to create an expanded string value under HKLM\SOFTWARE\System Admin Scripting Guide.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "Expanded String Value Name"
strValue = "%PATHEXT%"

oReg.SetExpandedStringValue _
    HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating String and DWORD Values

Description
Uses WMI to create string and DWORD values under HKLM\SOFTWARE\System Admin Scripting Guide.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "String Value Name"
strValue = "string value"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strValueName = "DWORD Value Name"
dwValue = 82
oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Registry Key

Description
Uses WMI to delete the registry key HKLM\SOFTWARE\System Admin Scripting Guide.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"

oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Registry Values

Description
Uses WMI to delete all the registry values under HKLM\SOFTWARE\System Admin Scripting Guide.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strDWORDValueName = "DWORD Value Name"
strExpandedStringValueName = "Expanded String Value Name"
strMultiStringValueName = "Multi String Value Name"
strStringValueName = "String Value Name"

oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strDWORDValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strExpandedStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strMultiStringValueName
oReg.DeleteValue HKEY_LOCAL_MACHINE,strKeyPath,strStringValueName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Registry Values and Types

Description
Uses WMI to list all the registry values and their types under HKLM\SYSTEM\CurrentControlSet\Control\Lsa.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
const REG_SZ = 1
const REG_EXPAND_SZ = 2
const REG_BINARY = 3
const REG_DWORD = 4
const REG_MULTI_SZ = 7

strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Control\Lsa"

oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
 arrValueNames, arrValueTypes

For i=0 To UBound(arrValueNames)
    StdOut.WriteLine "Value Name: " & arrValueNames(i)

    Select Case arrValueTypes(i)
        Case REG_SZ
            StdOut.WriteLine "Data Type: String"
            StdOut.WriteBlankLines(1)
        Case REG_EXPAND_SZ
            StdOut.WriteLine "Data Type: Expanded String"
            StdOut.WriteBlankLines(1)
        Case REG_BINARY
            StdOut.WriteLine "Data Type: Binary"
            StdOut.WriteBlankLines(1)
        Case REG_DWORD
            StdOut.WriteLine "Data Type: DWORD"
            StdOut.WriteBlankLines(1)
        Case REG_MULTI_SZ
            StdOut.WriteLine "Data Type: Multi String"
            StdOut.WriteBlankLines(1)
    End Select
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Subkeys

Description
Uses WMI to enumerate all the registry subkeys under HKLM\SYSTEM\CurrentControlSet\Services.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
    StdOut.WriteLine subkey
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing Registry Files

Description
Uses WMI to list all the registry file and locations under HKLM\System\CurrentControlSet\Control\Hivelist.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "System\CurrentControlSet\Control\hivelist"
oReg.EnumValues HKEY_LOCAL_MACHINE, strKeyPath,_
 arrValueNames, arrValueTypes

For i=0 To UBound(arrValueNames)
    StdOut.WriteLine "File Name: " & arrValueNames(i) & " -- "
    oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
    arrValueNames(i),strValue
    StdOut.WriteLine "Location: " & strValue
    StdOut.WriteBlankLines(1)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Registry Entry Level Events

Description
Temporary event consumer that monitors the registry for any changes to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

wmiServices.ExecNotificationQueryAsync wmiSink, _
  "SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' " & _
      "AND KeyPath='SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'" _
          & " AND ValueName='CSDVersion'"

WScript.Echo "Listening for Registry Change Events..." & vbCrLf

While(1)
    WScript.Sleep 1000
Wend

Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    WScript.Echo "Received Registry Change Event" & vbCrLf & _
                 "------------------------------" & vbCrLf & _
                 wmiObject.GetObjectText_()
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Registry Subkey Events

Description
Temporary event consumer that monitors the registry for any changes to HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

wmiServices.ExecNotificationQueryAsync wmiSink, _
  "SELECT * FROM RegistryKeyChangeEvent WHERE Hive='HKEY_LOCAL_MACHINE' AND " & _
    "KeyPath='SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion'"

WScript.Echo "Listening for Registry Change Events..." & vbCrLf

While(1)
    WScript.Sleep 1000
Wend

Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    WScript.Echo "Received Registry Change Event" & vbCrLf & _
                 "------------------------------" & vbCrLf & _
                 wmiObject.GetObjectText_()
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Registry Subtree Events

Description
Temporary event consumer that monitors the registry for any changes to HKLM.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

Set wmiServices = GetObject("winmgmts:root/default")
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_")

wmiServices.ExecNotificationQueryAsync wmiSink, _
    "SELECT * FROM RegistryTreeChangeEvent WHERE Hive= " _
        & "'HKEY_LOCAL_MACHINE' AND RootPath=''"

WScript.Echo "Listening for Registry Change Events..." & vbCrLf

While(1)
    WScript.Sleep 1000
Wend

Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext)
    WScript.Echo "Received Registry Change Event" & vbCrLf & _
                 "------------------------------" & vbCrLf & _
                 wmiObject.GetObjectText_()
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading a Binary Registry Value

Description
Uses WMI to read a binary registry value.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "LicenseInfo"
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue

For i = lBound(strValue) to uBound(strValue)
    StdOut.WriteLine  strValue(i)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading a MultiString Value

Description
Uses WMI to read a multi-string registry value.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SYSTEM\CurrentControlSet\Services\Eventlog\System"
strValueName = "Sources"
oReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,arrValues

For Each strValue In arrValues
    StdOut.WriteLine  strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading an Expanded String Value

Description
Uses WMI to read an expanded string registry value.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strValueName = "UIHost"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue

StdOut.WriteLine  "The Windows logon UI host is: " & strValue

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading String and DWORD Values

Description
Uses WMI to read a string and a DWORD registry value.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & "\root\default:StdRegProv")

strKeyPath = "Console"
strValueName = "HistoryBufferSize"
oReg.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
StdOut.WriteLine "Current History Buffer Size: " & dwValue

strKeyPath = "SOFTWARE\Microsoft\Windows Script Host\Settings"
strValueName = "TrustPolicy"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
StdOut.WriteLine "Current WSH Trust Policy Value: " & strValue

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Registry Properties

Description
Returns information about the computer registry.

For more information about the Win32_Registry class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Registry")
For Each objItem in colItems
    Wscript.Echo "Current Size: " & objItem.CurrentSize
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Install Date: " & objItem.InstallDate
    Wscript.Echo "Maximum Size: " & objItem.MaximumSize
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Proposed Size: " & objItem.ProposedSize
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Programmatically Verifying a Script Signature

Description
Verifies that an individual script has been digitally signed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Windows Script Host 5.6 installed
Windows NT 4.0 | Yes, with Windows Script Host 5.6 installed
Windows 98 | Yes, with Windows Script Host 5.6 installed

Script Code

blnShowGUI = False
set objSigner = WScript.CreateObject("Scripting.Signer")
blnShowGUI = False
blnIsSigned = objSigner.VerifyFile("C:\Scripts\CreateUser.vbs", blnShowGUI)
If blnIsSigned then
    WScript.Echo "Script has been signed."
Else
   WScript.Echo " Script has not been signed."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Signing All the Scripts in a Folder

Description
Uses the Scripting Runtime Signer object to digitally sign all the scripts in a folder. Requires a valid digital certificate.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Windows Script Host 5.6 installed
Windows NT 4.0 | Yes, with Windows Script Host 5.6 installed
Windows 98 | Yes, with Windows Script Host 5.6 installed

Script Code

set objSigner = WScript.CreateObject("Scripting.Signer")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\scripts")
Set colListOfFiles = objFolder.Files
For each objFile in colListOfFiles
    objSigner.SignFile objFile.Path, "IT Department"
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Signing a Script Programmatically

Description
Uses the Scripting Runtime Signer object to digitally sign a script. Requires a valid digital certificate.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Windows Script Host 5.6 installed
Windows NT 4.0 | Yes, with Windows Script Host 5.6 installed
Windows 98 | Yes, with Windows Script Host 5.6 installed

Script Code

set objSigner = WScript.CreateObject("Scripting.Signer")
objSigner.SignFile "C:\Scripts\CreateUsers.vbs", "IT Department"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Verifying Signatures for All the Scripts in a Folder

Description
Verifies that all the scripts in the C:\Scripts folder have been digitally signed.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, with Windows Script Host 5.6 installed
Windows NT 4.0 | Yes, with Windows Script Host 5.6 installed
Windows 98 | Yes, with Windows Script Host 5.6 installed

Script Code

blnShowGUI = False
set objSigner = WScript.CreateObject("Scripting.Signer")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Scripts\")
Set colListOfFiles = objFolder.Files
For each objFile in colListOfFiles
If Right(objFile.Name, 3) = "vbs" Then
    blnIsSigned = objSigner.VerifyFile(objFile.Path, blnShowGUI)
    If blnIsSigned then
        WScript.Echo objFile.Name & " has been signed."
        Else
            WScript.Echo objFile.Name & " has not been signed."
    End If
End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing a Service Account Password

Description
Changes the service account password for any services running under the hypothetical service account Netsvc.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For Each objservice in colServiceList
    If objService.Startname = ".\netsvc" Then
        errReturn = objService.Change( , , , , , , , "password")
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Service Error Control Codes

Description
Configures all auto-start services to issue an alert if the service fails during startup.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

Const NORMAL_ERROR_CONTROL = 2
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where ErrorControl = 'Ignore'")
For Each objService in colServiceList
    errReturn = objService.Change( , , , NORMAL_ERROR_CONTROL)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Service Start Options

Description
Disables all services configured as manual start. Among other things, this prevents Power Users from being able to start these services.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where StartMode = 'Manual'")
For Each objService in colServiceList
    errReturnCode = objService.Change( , , , , "Disabled")
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Services Running in All Processes

Description
Returns a list of processes and all the services currently running in each process.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

set objIdDictionary = CreateObject("Scripting.Dictionary")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where State <> 'Stopped'")
For Each objService in colServices
    If objIdDictionary.Exists(objService.ProcessID) Then
    Else
        objIdDictionary.Add objService.ProcessID, objService.ProcessID
    End If
Next
colProcessIDs = objIdDictionary.Items
For i = 0 to objIdDictionary.Count - 1
    Set colServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service Where ProcessID = '" & _
            colProcessIDs(i) & "'")
    Wscript.Echo "Process ID: " & colProcessIDs(i)
    For Each objService in colServices
        Wscript.Echo VbTab & objService.DisplayName
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Services Running in a Process

Description
Returns a list of services running in the Services.exe process.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For Each objService in colListOfServices
    If objService.PathName = "C:\WINDOWS\system32\services.exe" Then
        Wscript.Echo objService.DisplayName
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Services that can be Paused

Description
Returns a list of services that can be paused.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where AcceptPause = True")
For Each objService in colServices
    Wscript.Echo objService.DisplayName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Services that can be Stopped

Description
Returns a list of services that can be stopped.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where AcceptStop = True")
For Each objService in colServices
    Wscript.Echo objService.DisplayName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Antecedent Services for a Single Service

Description
Enumerates all the services that must be running before the SMTP service can be started.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
 & "{Win32_service.Name='SMTPSVC'} Where " _
    & "AssocClass=Win32_DependentService " & "Role=Dependent")
For Each objService in colServiceList
    Wscript.Echo objService.DisplayName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Dependent Services for a Single Service

Description
Enumerates all the services that cannot start until the Rasman service has started.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='rasman'} Where " _
        & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For Each objService in colServiceList
    Wscript.Echo objService.DisplayName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Dependent Services for All Services

Description
Enumerates dependent services for all the services installed on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = _
     objFSO.OpenTextFile("c:\scripts\service_dependencies.csv", _
         ForAppending, True)
objLogFile.Write("Service Dependencies")
objLogFile.Writeline
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")

For Each objService in colListofServices
    objServiceRegistryName = objService.Name
    objServiceDisplayName = objService.DisplayName

Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='" & objServiceRegistryName & "'} Where " & _
        "AssocClass=Win32_DependentService Role=Antecedent" )

 If colServiceList.Count = 0 then
        objLogFile.Write(objServiceDisplayName) & ", None"
        objLogFile.Writeline
    Else
        For Each objDependentService in colServiceList
            objLogFile.Write(objServiceDisplayName) & ","
            objLogFile.Write(objDependentService.DisplayName)
        Next
        objLogFile.WriteLine
    End If
Next
objLogFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Inactive Services

Description
Returns a list of all the services installed on a computer that are currently stopped.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & _
    "{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2")
Set colStoppedServices = objWMIService.ExecQuery _
  ("SELECT DisplayName,State FROM Win32_Service WHERE State <> 'Running'")

For Each objService in colStoppedServices
    Wscript.Echo objService.DisplayName  & " = " & objService.State
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Service Load Order Groups

Description
Returns a list of all the service load order groups found on a computer, and well as their load order.

For more information about the Win32_LoadOrderGroup class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LoadOrderGroup")
For Each objItem in colItems
    Wscript.Echo "Driver Enabled: " & objItem.DriverEnabled
    Wscript.Echo "Group Order: " & objItem.GroupOrder
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Installing a Service

Description
Installs a hypothetical service Db.exe.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

Const OWN_PROCESS = 16
Const NOT_INTERACTIVE = False
Const NORMAL_ERROR_CONTROL = 2
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objService = objWMIService.Get("Win32_BaseService")
errReturn = objService.Create("DbService" ,"Personnel Database" , _
    "c:\windows\system32\db.exe", OWN_PROCESS, NORMAL_ERROR_CONTROL, "Manual", _
        NOT_INTERACTIVE, "NT AUTHORITY\LocalService", ""  )
Wscript.Echo errReturn

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Service Performance

Description
Uses formatted performance counters to retrieve performance data for the DHCP Server service.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDHCPServer = objRefresher.AddEnum _
    (objWMIService, "win32_PerfFormattedData_DHCPServer_DHCPServer"). _
          ObjectSet
objRefresher.Refresh
For i = 1 to 60
    For Each objDHCPServer in colDHCPServer
        Wscript.Echo "Acknowledgements per second: " & _
            objDHCPServer.AcksPerSec
        Wscript.Echo "Declines per second: " & _
            objDHCPServer.DeclinesPerSec
        Wscript.Echo "Discovers per second: " & _
            objDHCPServer.DiscoversPerSec
        Wscript.Echo "Informs per second: " & objDHCPServer.InformsPerSec
        Wscript.Echo "Offers per second: " & objDHCPServer.OffersPerSec
        Wscript.Echo "Releases per second: " & _
            objDHCPServer.ReleasesPerSec
        Wscript.Echo "Requests per second: " & _
            objDHCPServer.RequestsPerSec
    Next
    Wscript.Sleep 10000
    objRefresher.Refresh
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Pausing Services Running Under a Specific Account

Description
Pauses all services running under the hypothetical service account Netsvc.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For each objService in colServices
    If objService.StartName = ".\netsvc" Then
        errReturnCode = objService.PauseService()
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing a Service

Description
Removes a hypothetical service named DbService.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name = 'DbService'")
For Each objService in colListOfServices
    objService.StopService()
    objService.Delete()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Resuming AutoStart Services that are Paused

Description
Restarts any auto-start services that have been paused.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
 ("Select * from Win32_Service Where State = 'Paused' and StartMode = 'Auto'")
For Each objService in colListOfServices
    objService.ResumeService()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Service Properties

Description
Retrieves a complete list of services and their associated properties. Information is saved to a text file: C:\Scripts\Service_List.cs.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\scripts\service_list.csv", _
    ForAppending, True)
objLogFile.Write _
    ("System Name,Service Name,Service Type,Service State, Exit " _
        & "Code,Process ID,Can Be Paused,Can Be Stopped,Caption," _
        & "Description,Can Interact with Desktop,Display Name,Error " _
        & "Control, Executable Path Name,Service Started," _
        & "Start Mode,Account Name ")
objLogFile.Writeline
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
        ("Select * from Win32_Service")
For Each objService in colListOfServices
    objLogFile.Write(objService.SystemName) & ","
    objLogFile.Write(objService.Name) & ","
    objLogFile.Write(objService.ServiceType) & ","
    objLogFile.Write(objService.State) & ","
    objLogFile.Write(objService.ExitCode) & ","
    objLogFile.Write(objService.ProcessID) & ","
    objLogFile.Write(objService.AcceptPause) & ","
    objLogFile.Write(objService.AcceptStop) & ","
    objLogFile.Write(objService.Caption) & ","
    objLogFile.Write(objService.Description) & ","
    objLogFile.Write(objService.DesktopInteract) & ","
    objLogFile.Write(objService.DisplayName) & ","
    objLogFile.Write(objService.ErrorControl) & ","
    objLogFile.Write(objService.PathName) & ","
    objLogFile.Write(objService.Started) & ","
    objLogFile.Write(objService.StartMode) & ","
    objLogFile.Write(objService.StartName) & ","
    objLogFile.writeline
Next
objLogFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Service Status

Description
Returns a list of all the services installed on a computer, and indicates their current status (typically, running or not running).

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For Each objService in colRunningServices
    Wscript.Echo objService.DisplayName  & VbTab & objService.State
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Service Status Changes from Event Logs

Description
Retrieves events from the System event log that have an event ID of 7036. These events are recorded any time a service changes status.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceEvents = objWMIService.ExecQuery _
    ("Select * from Win32_NTLogEvent Where Logfile = 'System' and " _
        & "EventCode = '7036'")
For Each strEvent in colServiceEvents
    dtmConvertedDate.Value = strEvent.TimeWritten
    Wscript.Echo dtmConvertedDate.GetVarDate
    Wscript.Echo strEvent.Message
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Starting a Service and Its Dependents

Description
Starts the NetDDE service and all its dependent services.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery _
    ("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
    errReturn = objService.StartService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='NetDDE'} Where " _
        & "AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
    objService.StartService()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Stopping a Service and Its Dependents

Description
Stops the NetDDE service and all its dependent services.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery("Associators of " _
   & "{Win32_Service.Name='NetDDE'} Where " _
        & "AssocClass=Win32_DependentService " & "Role=Antecedent" )
For each objService in colServiceList
    objService.StopService()
Next
Wscript.Sleep 20000
Set colServiceList = objWMIService.ExecQuery _
        ("Select * from Win32_Service where Name='NetDDE'")
For each objService in colServiceList
    errReturn = objService.StopService()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Starting AutoStart Services that have Stopped

Description
Restarts any auto-start services that have been stopped.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery _
 ("Select * from Win32_Service Where State = 'Stopped' and StartMode = " _
     & "'Auto'")
For Each objService in colListOfServices
    objService.StartService()
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Stopping Services Running Under a Specific Account

Description
Stops all services running under the hypothetical service account Netsvc.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from win32_Service")
For each objService in colServices
    If objService.StartName = ".\netsvc" Then
        errReturnCode = objService.StopService()
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Switching Service Accounts to Local Service

Description
Changes the service account to LocalService for any services running under the hypothetical service account Netsvc.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed, although the script cannot be run against a Windows 98 computer

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service")
For each objService in colServices
    If objService.StartName = ".\netsvc" Then
        errServiceChange = objService.Change _
        ( , , , , , , "NT AUTHORITY\LocalService" , "")
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting All Scheduled Tasks

Description
Deletes all the scheduled tasks on a computer. Note: WMI can only delete scheduled tasks created with the Win32_ScheduledJob class or the At.exe utility. It cannot delete tasks created using the Task Scheduler.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledTasks = objWMIService.ExecQuery _
    ("Select * from Win32_ScheduledJob")
For Each objTask in colScheduledTasks
    intJobID = objTask.JobID
    Set objInstance = objWMIService.Get _
        ("Win32_ScheduledJob.JobID=" & intJobID)
    objInstance.Delete
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Scheduled Task

Description
Deletes the scheduled task with the JobID of 1.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objInstance = objWMIService.Get("Win32_ScheduledJob.JobID=1")
err = objInstance.Delete
Wscript.Echo err

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Scheduled Tasks

Description
Enumerates all the scheduled tasks on a computer. Note: WMI can only enumerate scheduled tasks created with the Win32_ScheduledJob class or the At.exe utility. It cannot enumerate tasks created using the Task Scheduler.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colScheduledJobs = objWMIService.ExecQuery _
    ("Select * from Win32_ScheduledJob")
For Each objJob in colScheduledJobs
    Wscript.Echo "Caption: " & objJob.Caption
    Wscript.Echo "Command: " & objJob.Command
    Wscript.Echo "Days Of Month: " & objJob.DaysOfMonth
    Wscript.Echo "Days Of Week: " & objJob.DaysOfWeek
    Wscript.Echo "Description: " & objJob.Description
    Wscript.Echo "Elapsed Time: " & objJob.ElapsedTime
    Wscript.Echo "Install Date: " & objJob.InstallDate
    Wscript.Echo "Interact with Desktop: " & objJob.InteractWithDesktop
    Wscript.Echo "Job ID: " & objJob.JobID
    Wscript.Echo "Job Status: " & objJob.JobStatus
    Wscript.Echo "Name: " & objJob.Name
    Wscript.Echo "Notify: " & objJob.Notify
    Wscript.Echo "Owner: " & objJob.Owner
    Wscript.Echo "Priority: " & objJob.Priority
    Wscript.Echo "Run Repeatedly: " & objJob.RunRepeatedly
    Wscript.Echo "Start Time: " & objJob.StartTime
    Wscript.Echo "Status: " & objJob.Status
    Wscript.Echo "Time Submitted: " & objJob.TimeSubmitted
    Wscript.Echo "Until Time: " & objJob.UntilTime
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Scheduling a Task

Description
Schedules Notepad to run at 12:30 PM every Monday, Wednesday, and Friday.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
    ("Notepad.exe", "********123000.000000-420", _
        True , 1 OR 4 OR 16, , , JobID)
Wscript.Echo errJobCreated

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding 1,000 Users to a Security Group

Description
Demonstration script that creates a security group named Group1, and adds one thousand users (UserNo1 through UserNo10000) to that group. This script is not intended for use in a production environment.

For more information about creating objects using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3
Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
                               objRootDSE.Get("defaultNamingContext"))
Set objGroup = objContainer.Create("Group", "cn=Group1")
objGroup.Put "sAMAccountName","Group1"
objGroup.SetInfo
For i = 1 To 1000
strDN = ",cn=Users," & objRootDSE.defaultNamingContext
  objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
    Array("cn=UserNo" & i & strDN)
  objGroup.SetInfo
Next
WScript.Echo "Group1 created and 1000 Users added to the group."

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding New Members to a Group

Description
Adds two groups (Executives and Scientists) and one user account (MyerKen) to the Sea-Users group in Active Directory.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objGroup = GetObject _
  ("LDAP://cn=Sea-Users,cn=Users,dc=NA,dc=fabrikam,dc=com")

objGroup.PutEx ADS_PROPERTY_APPEND, "member", _
    Array("cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com", _
      "cn=Executives,ou=Management,dc=NA,dc=fabrikam,dc=com", _
      "cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Assigning a Group Manager

Description
Assigns user MyerKen as the manager of the Active Directory security group named Scientists.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.Put "managedBy", "cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com"
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing the Scope of a Group

Description
Changes a global distribution group named Scientists to a universal security group.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

Set objGroup = GetObject _
   ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.Put "groupType", _
  ADS_GROUP_TYPE_GLOBAL_GROUP + ADS_GROUP_TYPE_SECURITY_ENABLED

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Domain Local Distribution Group

Description
Creates a domain local Active Directory distribution group named Vendors.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=Vendors")
objGroup.Put "sAMAccountName", "vendors"
objGroup.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Domain Local Security Group

Description
Creates a domain local Active Directory security group named DB-Servers.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objOU = GetObject("LDAP://cn=Computers,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=DB-Servers")
objGroup.Put "sAMAccountName", "DBServers"
objGroup.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP Or _
    ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Global Distribution Group

Description
Creates a global Active Directory distribution group named Scientists.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Set objOU = GetObject("LDAP://ou=R&D,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=Scientists")
objGroup.Put "sAMAccountName", "scientists"
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Global Group

Description
Creates a new global security group -- atl-users02 -- within Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=atl-users02")
objGroup.Put "sAMAccountName", "atl-users02"
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Global Security Group

Description
Creates a global Active Directory security group named HR-Employees.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objOU = GetObject("LDAP://ou=HR,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=HR-Employees")
objGroup.Put "sAMAccountName", "HRStaff"
objGroup.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP Or _
    ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Universal Distribution Group

Description
Creates a universal Active Directory distribution group named Customers.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Set objOU = GetObject("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=Customers")
objGroup.Put "sAMAccountName", "customers"
objGroup.Put "groupType", ADS_GROUP_TYPE_UNIVERSAL_GROUP
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Universal Security Group

Description
Creates a universal Active Directory security group named All-Employees.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000
Set objOU = GetObject("LDAP://cn=Users,dc=NA,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=All-Employees")
objGroup.Put "sAMAccountName", "AllEmployees"
objGroup.Put "groupType", ADS_GROUP_TYPE_UNIVERSAL_GROUP Or _
   ADS_GROUP_TYPE_SECURITY_ENABLED
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Group from Active Directory

Description
Deletes a group named atl-users from the HR organizational unit in the hypothetical domain fabrikam.com.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://ou=hr, dc=fabrikam,dc=com")
objOU.Delete "group", "cn=atl-users"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Other Groups a Group Belongs To

Description
Returns a list of all the groups that the Active Directory security group Scientists is a member of.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo

arrMembersOf = objGroup.GetEx("memberOf")

WScript.Echo "MembersOf:"
For Each strMemberOf in arrMembersOf
  WScript.Echo strMemberOf
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Primary Group for a User Account

Description
Reports the primary group for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
intPrimaryGroupID = objUser.Get("primaryGroupID")

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
    "<LDAP://dc=NA,dc=fabrikam,dc=com>;(objectCategory=Group);" & _
        "distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
    If objRecordset.Fields("primaryGroupToken") = intPrimaryGroupID Then
        WScript.Echo "Primary group:"
        WScript.Echo objRecordset.Fields("distinguishedName") & _
            " (primaryGroupID: " & intPrimaryGroupID & ")"
    End If
    objRecordset.MoveNext
Wend

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Group Members

Description

Retrieves the memberOf and primaryGroupID attributes of a user account to display group membership. Note that the primaryGroupID attribute contains an integer that maps to the name of the primary group. The memberOf attribute does not contain the name of the primary group of which the user is a member.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Set objOU = GetObject _
    ("LDAP://cn=Users,dc=NA,dc=fabrikam,dc=com")

ObjOU.Filter= Array("user")

For Each objUser in objOU
    WScript.Echo objUser.cn & " is a member of: "
    WScript.Echo vbTab & "Primary Group ID: " & _
    objUser.Get("primaryGroupID")

    arrMemberOf = objUser.GetEx("memberOf")

    If Err.Number <>  E_ADS_PROPERTY_NOT_FOUND Then
        For Each Group in arrMemberOf
        WScript.Echo vbTab & Group
        Next
    Else
        WScript.Echo vbTab & "memberOf attribute is not set"
        Err.Clear
      End If
    Wscript.Echo VbCrLf
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the Owner of a Group

Description
Returns the owner of an Active Directory security group named Scientists.

For more information about working with Active Directory security descriptor, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

Set objNtSecurityDescriptor = objGroup.Get("ntSecurityDescriptor")

WScript.Echo "Owner Tab"
WScript.Echo "Current owner of this item: " & objNtSecurityDescriptor.Owner

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying Group Properties

Description
Modifies both single-value (samAccountName, mail, info) and multi-value (description) attributes for a group named Scientists.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objGroup = GetObject _
   ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.Put "sAMAccountName", "Scientist01"
objGroup.Put "mail", "YoungRob@fabrikam.com"
objGroup.Put "info", "Use this group for official communications " & _
  "with scientists who are contracted to work with Contoso.com."

objGroup.PutEx ADS_PROPERTY_UPDATE, _
    "description", Array("Scientist Mailing List")

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying Group Type

Description
Changes a local group named Scientists to a global security group.

For more information about the group type constants used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

Set objGroup = GetObject _
   ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.Put "groupType", _
  ADS_GROUP_TYPE_UNIVERSAL_GROUP + ADS_GROUP_TYPE_SECURITY_ENABLED

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a Group Within a Domain

Description
Moves a group account from the HR OU to the Users container.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://cn=Users,dc=NA,dc=fabrikam,dc=com")
objOU.MoveHere "LDAP://cn=atl-users,ou=HR,dc=NA,dc=fabrikam,dc=com", _
    vbNullString

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading the General Properties for a Group

Description
Reads the values found on the General Properties page in Active Directory Users and Computers for a group named Scientists.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const ADS_GROUP_TYPE_GLOBAL_GROUP = &h2
Const ADS_GROUP_TYPE_LOCAL_GROUP = &h4
Const ADS_GROUP_TYPE_UNIVERSAL_GROUP = &h8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &h80000000

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo

strName = objGroup.Get("name")
strSAMAccountName = objGroup.Get("sAMAccountName")
strMail = objGroup.Get("mail")
intgroupType = objGroup.Get("groupType")
strInfo = objGroup.Get("info")

strDescription = objGroup.GetEx("description")

WScript.Echo "name: " & strName
WScript.Echo "sAMAccountName: " & strSAMAccountName
WScript.Echo "mail: " & strMail
WScript.Echo "info: " & strInfo

WScript.StdOut.Write "Group scope: "
If intGroupType AND ADS_GROUP_TYPE_LOCAL_GROUP Then
  WScript.Echo "Domain local"
ElseIf intGroupType AND ADS_GROUP_TYPE_GLOBAL_GROUP Then
  WScript.Echo "Global"
ElseIf intGroupType AND ADS_GROUP_TYPE_UNIVERSAL_GROUP Then
  WScript.Echo "Universal"
Else
  WScript.Echo "Unknown"
End If

WScript.StdOut.Write "Group type: "
If intGroupType AND ADS_GROUP_TYPE_SECURITY_ENABLED Then
  WScript.Echo "Security group"
Else
  WScript.Echo "Distribution group"
End If

For Each strValue in strDescription
  WScript.Echo "description: " & strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading the Security Descriptor for a Group

Description
Returns information found on the security descriptor for the Active Directory group named Scientists. This script must be run under CScript.

For more information about working with Active Directory security descriptor, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SE_DACL_PROTECTED = &H1000

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

Set objNtSecurityDescriptor = objGroup.Get("ntSecurityDescriptor")

intNtSecurityDescriptorControl = objNtSecurityDescriptor.Control

WScript.Echo "Permissions Tab"
WScript.StdOut.WriteLine "Allow inheritable permissions from the parent to"
WScript.StdOut.Write "propogate to this object and all child objects "
If (intNtSecurityDescriptorControl And SE_DACL_PROTECTED) Then
  Wscript.Echo "is disabled."
Else
  WScript.Echo "is enabled."
End If
WScript.Echo VbCr

Set objDiscretionaryAcl = objNtSecurityDescriptor.DiscretionaryAcl
DisplayAceInformation objDiscretionaryAcl, "DACL"

Sub DisplayAceInformation(SecurityStructure, strType)
  Const ADS_ACETYPE_ACCESS_ALLOWED = &H0
  Const ADS_ACETYPE_ACCESS_DENIED = &H1
  Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &H5
  Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
  intAceCount = 0
  For Each objAce In SecurityStructure
    strTrustee = Mid(objAce.Trustee,1,12)
    If StrComp(strTrustee, "NT AUTHORITY", 1) <> 0 Then
      intAceCount = intAceCount + 1
      WScript.Echo strType & " permission entry: " & intAceCount
      WScript.Echo "Name: " & objAce.Trustee

      intAceType = objAce.AceType
      If (intAceType = ADS_ACETYPE_ACCESS_ALLOWED Or _
        intAceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT) Then
        WScript.Echo "Type: Allow Access"
      ElseIf (intAceType = ADS_ACETYPE_ACCESS_DENIED Or _
        intAceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) Then
        WScript.StdOut.Write "Type: Deny Acess"
      Else
        WScript.Echo "Acess Type Unknown."
      End If
      ReadBitsInAccessMask(objAce.AccessMask)
      WScript.Echo VbCr
    End If
  Next
End Sub

Sub ReadBitsInAccessMask(AccessMask)
  Const ADS_RIGHT_DELETE = &H10000
  Const ADS_RIGHT_READ_CONTROL = &H20000
  Const ADS_RIGHT_WRITE_DAC = &H40000
  Const ADS_RIGHT_WRITE_OWNER = &H80000
  Const ADS_RIGHT_DS_CREATE_CHILD = &H1
  Const ADS_RIGHT_DS_DELETE_CHILD = &H2
  Const ADS_RIGHT_ACTRL_DS_LIST = &H4
  Const ADS_RIGHT_DS_SELF = &H8
  Const ADS_RIGHT_DS_READ_PROP = &H10
  Const ADS_RIGHT_DS_WRITE_PROP = &H20
  Const ADS_RIGHT_DS_DELETE_TREE = &H40
  Const ADS_RIGHT_DS_LIST_OBJECT = &H80
  Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

  WScript.Echo VbCrLf & "Standard Access Rights"
  If (AccessMask And ADS_RIGHT_DELETE) Then _
    WScript.Echo vbTab & "-Delete an object."
  If (AccessMask And ADS_RIGHT_READ_CONTROL) Then _
    WScript.Echo vbTab & "-Read permissions."
  If (AccessMask And ADS_RIGHT_WRITE_DAC) Then _
    WScript.Echo vbTab & "-Write permissions."
  If (AccessMask And ADS_RIGHT_WRITE_OWNER) Then _
    WScript.Echo vbTab & "-Modify owner."

  WScript.Echo VbCrLf & "Directory Service Specific Access Rights"
  If (AccessMask And ADS_RIGHT_DS_CREATE_CHILD) Then _
    WScript.Echo vbTab & "-Create child objects."
  If (AccessMask And ADS_RIGHT_DS_DELETE_CHILD) Then _
    WScript.Echo vbTab & "-Delete child objects."
  If (AccessMask And ADS_RIGHT_ACTRL_DS_LIST) Then _
    WScript.Echo vbTab & "-Enumerate an object."
  If (AccessMask And ADS_RIGHT_DS_READ_PROP) Then _
    WScript.Echo vbTab & "-Read the properties of an object."
  If (AccessMask And ADS_RIGHT_DS_WRITE_PROP) Then _
    WScript.Echo vbTab & "-Write the properties of an object."
  If (AccessMask And ADS_RIGHT_DS_DELETE_TREE) Then _
    WScript.Echo vbTab & "-Delete a tree of objects"
  If (AccessMask And ADS_RIGHT_DS_LIST_OBJECT) Then _
    WScript.Echo vbTab & "-List a tree of objects."

  WScript.Echo VbCrLf & "Control Access Rights"
  If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) + _
    (AccessMask And ADS_RIGHT_DS_SELF) = 0 Then
    WScript.Echo "-None"
  Else
    If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) Then _
      WScript.Echo vbTab & "-Extended access rights."
    If (AccessMask And ADS_RIGHT_DS_SELF) Then
      WScript.Echo vbTab & "-Active Directory must validate a property "
      WScript.Echo vbTab & " write operation beyond the schema definition "
      WScript.Echo vbTab & " for the attribute."
    End If
  End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading the System Access Control List for a Group

Description
Returns information found on the System Access Control List (SACL) for an Active Directory security group named Scientists.

For more information about working with Active Directory security descriptor, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SE_SACL_PROTECTED = &H2000
Const ADS_SECURITY_INFO_OWNER = &H1
Const ADS_SECURITY_INFO_GROUP = &H2
Const ADS_OPTION_SECURITY_MASK =&H3
Const ADS_SECURITY_INFO_DACL = &H4
Const ADS_SECURITY_INFO_SACL = &H8

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.SetOption ADS_OPTION_SECURITY_MASK, ADS_SECURITY_INFO_OWNER _
  Or ADS_SECURITY_INFO_GROUP Or ADS_SECURITY_INFO_DACL _
  Or ADS_SECURITY_INFO_SACL

Set objNtSecurityDescriptor = objGroup.Get("ntSecurityDescriptor")

intNtSecurityDescriptorControl = objNtSecurityDescriptor.Control

WScript.Echo "Auditing Tab"
WScript.StdOut.WriteLine "Allow inheritable auditing entries from" & _
  "the parent to "
WScript.StdOut.Write "propogate to this object and all child objects "
If (intNtSecurityDescriptorControl And SE_SACL_PROTECTED) Then
  Wscript.Echo "is disabled."
Else
  WScript.Echo "is enabled."
End If
WScript.Echo VbCr

Set objSacl = objNtSecurityDescriptor.SystemAcl
DisplayAceInformation objSacl, "SACL"

Sub DisplayAceInformation(SecurityStructure, strType)
  Const ADS_ACETYPE_SYSTEM_AUDIT = &H2
  Const ADS_ACETYPE_SYSTEM_AUDIT_OBJECT = &H7

  intAceCount = 0
  For Each objAce In SecurityStructure
    strTrustee = Mid(objAce.Trustee,1,12)
    If StrComp(strTrustee, "NT AUTHORITY", 1) <> 0 Then
      intAceCount = intAceCount + 1
      WScript.Echo strType & " permission entry: " & intAceCount
      WScript.Echo "Name: " & objAce.Trustee

      intAceType = objAce.AceType
      WScript.Echo "ACETYPE IS: " & intAceType
      If (intAceType = ADS_ACETYPE_SYSTEM_AUDIT or _
       intAceType = ADS_ACETYPE_SYSTEM_AUDIT_OBJECT) Then
        WScript.StdOut.Write "Type: Success or Failure Audit"
      Else
        WScript.StdOut.Write "Audit Type Unknown."
      End If
      ReadBitsInAccessMask(objAce.AccessMask)
      WScript.Echo VbCr
    End If
  Next
End Sub

Sub ReadBitsInAccessMask(AccessMask)
  Const ADS_RIGHT_DELETE = &H10000
  Const ADS_RIGHT_READ_CONTROL = &H20000
  Const ADS_RIGHT_WRITE_DAC = &H40000
  Const ADS_RIGHT_WRITE_OWNER = &H80000
  Const ADS_RIGHT_DS_CREATE_CHILD = &H1
  Const ADS_RIGHT_DS_DELETE_CHILD = &H2
  Const ADS_RIGHT_ACTRL_DS_LIST = &H4
  Const ADS_RIGHT_DS_SELF = &H8
  Const ADS_RIGHT_DS_READ_PROP = &H10
  Const ADS_RIGHT_DS_WRITE_PROP = &H20
  Const ADS_RIGHT_DS_DELETE_TREE = &H40
  Const ADS_RIGHT_DS_LIST_OBJECT = &H80
  Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

  WScript.Echo VbCrLf & "Standard Access Rights"
  If (AccessMask And ADS_RIGHT_DELETE) Then _
    WScript.Echo vbTab & "-Delete an object."
  If (AccessMask And ADS_RIGHT_READ_CONTROL) Then _
    WScript.Echo vbTab & "-Read permissions."
  If (AccessMask And ADS_RIGHT_WRITE_DAC) Then _
    WScript.Echo vbTab & "-Write permissions."
  If (AccessMask And ADS_RIGHT_WRITE_OWNER) Then _
    WScript.Echo vbTab & "-Modify owner."

  WScript.Echo VbCrLf & "Directory Service Specific Access Rights"
  If (AccessMask And ADS_RIGHT_DS_CREATE_CHILD) Then _
    WScript.Echo vbTab & "-Create child objects."
  If (AccessMask And ADS_RIGHT_DS_DELETE_CHILD) Then _
    WScript.Echo vbTab & "-Delete child objects."
  If (AccessMask And ADS_RIGHT_ACTRL_DS_LIST) Then _
    WScript.Echo vbTab & "-Enumerate an object."
  If (AccessMask And ADS_RIGHT_DS_READ_PROP) Then _
    WScript.Echo vbTab & "-Read the properties of an object."
  If (AccessMask And ADS_RIGHT_DS_WRITE_PROP) Then _
    WScript.Echo vbTab & "-Write the properties of an object."
  If (AccessMask And ADS_RIGHT_DS_DELETE_TREE) Then _
    WScript.Echo vbTab & "-Delete a tree of objects"
  If (AccessMask And ADS_RIGHT_DS_LIST_OBJECT) Then _
    WScript.Echo vbTab & "-List a tree of objects."

  WScript.Echo VbCrLf & "Control Access Rights"
  If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) + _
    (AccessMask And ADS_RIGHT_DS_SELF) = 0 Then
    WScript.Echo "-None"
  Else
    If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) Then _
      WScript.Echo vbTab & "-Extended access rights."
    If (AccessMask And ADS_RIGHT_DS_SELF) Then
      WScript.Echo vbTab & "-Active Directory must validate a property "
      WScript.Echo vbTab & " write operation beyond the schema definition "
      WScript.Echo vbTab & " for the attribute."
    End If
  End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing a Group Manager

Description
Removes the manager entry for the Active Directory security group named Scientists. When this script is run, the group will no longer have an assigned manager.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.PutEx ADS_PROPERTY_CLEAR, "managedBy", 0
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing a User from All Active Directory Security Groups

Description
Removes the MyerKen user account from all Active Directory security groups.

For more information about deleing objects from Active Directory, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const ADS_PROPERTY_DELETE = 4
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
arrMemberOf = objUser.GetEx("memberOf")

If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "This account is not a member of any security groups."
    WScript.Quit
End If

For Each Group in arrMemberOf
    Set objGroup = GetObject("LDAP://" & Group)
    objGroup.PutEx ADS_PROPERTY_DELETE, _
        "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
    objGroup.SetInfo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing All the Members of a Group

Description
Removes all the members of an Active Directory group named Sea-Users.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objGroup = GetObject _
  ("LDAP://cn=Sea-Users,cn=Users,dc=NA,dc=fabrikam,dc=com")

objGroup.PutEx ADS_PROPERTY_CLEAR, "member", 0

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing a User from a Group

Description
Removes user MyerKen from the group Sea-Users.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_DELETE = 4

Set objGroup = GetObject _
  ("LDAP://cn=Sea-Users,cn=Users,dc=NA,dc=fabrikam,dc=com")

objGroup.PutEx ADS_PROPERTY_DELETE, _
  "member", _
    Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Replacing Group Membership

Description
Replaces the existing membership of a group named Scientists with two new group members: YoungRob and ShenAlan.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.PutEx ADS_PROPERTY_UPDATE, "member", _
    Array("cn=YoungRob,ou=R&D,dc=NA,dc=fabrikam,dc=com", _
      "cn=ShenAlan,ou=R&D,dc=NA,dc=fabrikam,dc=com")

objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning the Attributes of the Group Class

Description
Returns a list of mandatory and optional attributes of the group class (as stored in the Active Directory schema).

For more information about the group class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objGroupClass = GetObject("LDAP://schema/group")
Set objSchemaClass = GetObject(objGroupClass.Parent)

i = 0
WScript.Echo "Mandatory attributes:"
For Each strAttribute in objGroupClass.MandatoryProperties
  i= i + 1
  WScript.StdOut.Write i & vbTab & strAttribute
  Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
  WScript.StdOut.Write " (Syntax: " & objAttribute.Syntax & ")"
  If objAttribute.MultiValued Then
    WScript.Echo " Multivalued"
  Else
    WScript.Echo " Single-valued"
  End If
Next

WScript.Echo VbCrLf & "Optional attributes:"
For Each strAttribute in objGroupClass.OptionalProperties
  i= i + 1
  WScript.StdOut.Write i & vbTab & strAttribute
  Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
  WScript.StdOut.Write " [Syntax: " & objAttribute.Syntax & "]"
  If objAttribute.MultiValued Then
    WScript.Echo " Multivalued"
  Else
    WScript.Echo " Single-valued"
  End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Active Directory Groups a User Belongs To

Description
Returns a list of all the Active Directory security groups (including the primary group) that include the MyerKen user account as a member.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intPrimaryGroupID = objUser.Get("primaryGroupID")
arrMemberOf = objUser.GetEx("memberOf")

If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "The memberOf attribute is not set."
Else
    WScript.Echo "Member of: "
    For each Group in arrMemberOf
        WScript.Echo Group
    Next
End If

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
  "<LDAP://dc=NA,dc=fabrikam,dc=com>;(objectCategory=Group);" & _
  "distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
    If objRecordset.Fields("primaryGroupToken") = intPrimaryGroupID Then
        WScript.Echo "Primary group:"
        WScript.Echo objRecordset.Fields("distinguishedName") & _
            " (primaryGroupID: " & intPrimaryGroupID & ")"
    End If
    objRecordset.MoveNext
Wend

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning a List of Group Members

Description
Returns the members of an Active Directory group named Scientists.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfo

arrMemberOf = objGroup.GetEx("member")

WScript.Echo "Members:"
For Each strMember in arrMemberOf
  WScript.echo strMember
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning Group Object Information

Description
Retrieves the information found on the Object page in Active Directory Users and Computers for a security group named Scientists.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objGroup = GetObject _
  ("GC://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

strWhenCreated = objGroup.Get("whenCreated")
strWhenChanged = objGroup.Get("whenChanged")

Set objUSNChanged = objGroup.Get("uSNChanged")
dblUSNChanged = _
  Abs(objUSNChanged.HighPart * 2^32 + objUSNChanged.LowPart)

Set objUSNCreated = objGroup.Get("uSNCreated")
dblUSNCreated = _
  Abs(objUSNCreated.HighPart * 2^32 + objUSNCreated.LowPart)

objGroup.GetInfoEx Array("canonicalName"), 0
arrCanonicalName = objGroup.GetEx("canonicalName")

WScript.echo "CanonicalName of object:"
For Each strValue in arrCanonicalName
  WScript.echo vbTab & strValue
Next
WScript.Echo vbCr

WScript.Echo "Object class: " & objGroup.Class & vbCrLf
WScript.echo "whenCreated: " & strWhenCreated & " (Created - GMT)"
WScript.echo "whenChanged: " & strWhenChanged & " (Modified - GMT)"
WScript.Echo VbCrLf
WScript.Echo "uSNChanged: " & dblUSNChanged & " (USN Current)"
WScript.Echo "uSNCreated: " & dblUSNCreated & " (USN Original)"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning Managed By Information for a Group

Description
Returns information about the manager assigned to an Active Directory security group named Scientists.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

Set objGroup = GetObject _
  ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")

strManagedBy = objGroup.Get("managedBy")

If IsEmpty(strManagedBy) = TRUE Then
  WScript.Echo "No user account is assigned to manage " & _
    "this group."
Else
  Set objUser = GetObject("LDAP://" & strManagedBy)
  strPhysicalDeliveryOfficeName = _
    objUser.Get("physicalDeliveryOfficeName")
  strStreetAddress = objUser.Get("streetAddress")
  strLocalityName = objUser.Get("l")
  strStateProvince = objUser.Get("st")
  strCountryName = objUser.Get("c")
  strTelephoneNumber = objUser.Get("telephoneNumber")
  strFacsimileTelephoneNumber = _
    objUser.Get("facsimileTelephoneNumber")

  Call GetUpdateMemberList

  WScript.echo "physicalDeliveryOfficeName: " & _
    strPhysicalDeliveryOfficeName
  WScript.echo "streetAddress: " & strStreetAddress
  WScript.echo "l: " & strLocalityName
  WScript.echo "state/province: " & strStateProvince
  WScript.echo "c: " & strCountryName
  WScript.echo "telephoneNumber: " & strTelephoneNumber
  WScript.echo "facsimileTelephoneNumber: " & _
    strFacsimileTelephoneNumber
End If

Sub GetUpdateMemberList
  Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &H5
  Const Member_SchemaIDGuid = "{BF9679C0-0DE6-11D0-A285-00AA003049E2}"
  Const ADS_RIGHT_DS_WRITE_PROP = &H20
  objUser.GetInfoEx Array("canonicalName"),0
  strCanonicalName = objUser.Get("canonicalName")
  strDomain = Mid(strCanonicalName,1,InStr(1,strCanonicalName,".")-1)
  strSAMAccountName = objUser.Get("sAMAccountName")

  Set objNtSecurityDescriptor = objGroup.Get("ntSecurityDescriptor")
  Set objDiscretionaryAcl = objNtSecurityDescriptor.DiscretionaryAcl

  blnMatch = False
  For Each objAce In objDiscretionaryAcl
    If LCase(objAce.Trustee) = _
      LCase(strDomain & "\" & strSAMAccountName) AND _
      objAce.ObjectType =  Member_SchemaIDGuid AND _
      objAce.AceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT AND _
      objAce.AccessMask And ADS_RIGHT_DS_WRITE_PROP Then
      blnMatch = True
    End If
  Next
  If blnMatch Then
    WScript.Echo "Manager can update the member list"
  Else
    WScript.Echo "Manager cannot update the member list."
  End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a User to Two Security Groups

Description
Adds a user (MyerKen) to two different Active Directory security groups: Atl-Users and NA-Employees.

For more information about the PutEx method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objGroup = GetObject _
    ("LDAP://cn=Atl-Users,cn=Users,dc=NA,dc=fabrikam,dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND, _
    "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objGroup.SetInfo

Set objGroup = GetObject _
    ("LDAP://cn=NA-Employees,cn=Users,dc=NA,dc=fabrikam,dc=com")
objGroup.PutEx ADS_PROPERTY_APPEND, _
    "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Appending a Home Phone Number to a User Account

Description
Appends a new phone number to the otherHomePhone attribute of an Active Directory user account. This operation adds the phone number to the attribute without deleting ant existing phone numbers.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_APPEND, "otherHomePhone", Array("(425) 555-0116")
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Appending a Multi-Valued Attribute

Description
Adds an additional URL to a user account. Demonstrates how to append a new value to a multi-valued attribute.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_APPEND, _
  "url", Array("http://www.fabrikam.com/policy")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Appending a Phone Number

Description
Appends an additional home phone number for a user.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_APPEND, _
  "otherHomePhone", Array("(425) 555-1113")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a Route to the Dial-In Properties of a User Account

Description
Appends a new route to the Dial-In properties of a user account in Active Directory. This operation adds the new route without deleting any existing routes.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_APPEND, _
    "msRASSavedFramedRoute", _
        Array("128.168.0.0/15 0.0.0.0 5")
objUser.PutEx ADS_PROPERTY_APPEND, _
    "msRADIUSFramedRoute", _
        Array("128.168.0.0/15 0.0.0.0 5")
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Appending Address Page Information for a User Account

Description
Appends new entries to the postOfficeBox attribute of an Active Directory user account. This operation adds the new post office boxes without deleting any existing entries.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_APPEND, "postOfficeBox", Array("2225","2226")
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Assigning a Published Certificate to a User Account

Description
Copies a published certificate from a template account (userTemplate) and assigns it to the MyerKen Active Directory user account. This operation replaces any existing published certificates for the MyerKen account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const ADS_PROPERTY_UPDATE = 2

Set objUserTemplate = _
    GetObject("LDAP://cn=userTemplate,OU=Management,dc=NA,dc=fabrikam,dc=com")
arrUserCertificates = objUserTemplate.GetEx("userCertificate")

Set objUser = _
    GetObject("LDAP://cn=MyerKen,OU=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_UPDATE, "userCertificate", arrUserCertificates
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing a User Password

Description
Changes the password for a user. Requires you to know the user's previous password.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.ChangePassword "i5A2sj*!", "jl3R86df"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing User Account Attributes

Description
Configures user account attributes found on the General Properties page of the user account object in Active Directory users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.Put "givenName", "Ken"
objUser.Put "initials", "E."
objUser.Put "sn", "Myer"
objUser.Put "displayName", "Myer, Ken"
objUser.Put "physicalDeliveryOfficeName", "Room 4358"
objUser.Put "telephoneNumber", "(425) 555-1211"
objUser.Put "mail", "myerken@fabrikam.com"
objUser.Put "wWWHomePage", "http://www.fabrikam.com"

objUser.PutEx ADS_PROPERTY_UPDATE, _
    "description", Array("Management staff")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherTelephone", Array("(800) 555-1212", "(425) 555-1213")
objUser.PutEx ADS_PROPERTY_UPDATE, _
     "url", Array("http://www.fabrikam.com/management")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing Address Page Information for a User Account

Description
Removes all information for the c (country) and postOfficeBox attributes of the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_CLEAR, "c", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "postOfficeBox", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing All Published Certificates from a User Account

Description
Removes all published certificates for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_CLEAR, "userCertificate", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing User Account Attributes

Description
Clears selected attributes for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "initials", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "otherTelephone", 0

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing Department and Direct Report Information from a User Account

Description
Removes all information from the deparment, directReports, and manager attributes of the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const ADS_PROPERTY_CLEAR = 1
Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_CLEAR, "department", 0
objUser.SetInfo

arrDirectReports = objUser.GetEx("directReports")
If err.number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Quit
Else
    For Each strValue in arrDirectReports
        Set objUserSource = GetObject("LDAP://" & strValue)
        objUserSource.PutEx ADS_PROPERTY_CLEAR, "manager", 0
        objUserSource.SetInfo
    Next
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing Telephone Attributes

Description
Clears selected telephone-related attributes for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "info", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "otherPager", 0

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing User Account Address Attributes

Description
Clears selected address-related attributes for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1
Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "streetAddress", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "c", 0

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing Telephone Properties for a User Account

Description
Removes all information from the info and otherPager attributes of the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_CLEAR, "info", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "otherPager", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring a User Account So It Never Expires

Description
Configures the MyerKen Active Directory user account so that it never expires. This is done by setting the expiration date to January 1, 1970.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.AccountExpirationDate = "01/01/1970"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Account Page Information for a User Account

Description
Configures basic account information for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "userPrincipalName", "MyerKen@fabrikam.com"
objUser.Put "sAMAccountName", "MyerKen01"
objUser.Put "userWorkstations","wks1,wks2,wks3"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring COM+ Information for a User Account

Description
Sets COM+ information for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "msCOM-UserPartitionSetLink", _
  "cn=PartitionSet1,cn=ComPartitionSets,cn=System,dc=NA,dc=fabrikam,dc=com"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring User Account Telephone Numbers

Description
Configures telephone numbers and calling information for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "homePhone", "(425) 555-0100"
objUser.Put "pager", "(425) 555-0101"
objUser.Put "mobile", "(425) 555-0102"
objUser.Put "facsimileTelephoneNumber", "(425) 555-0103"
objUser.Put "ipPhone", "5555"
objUser.Put "info", "Please do not call this user account" & _
    " at home unless there is a work-related emergency. Call" & _
    " this user's mobile phone before calling the pager number."

objUser.PutEx ADS_PROPERTY_UPDATE, "otherHomePhone", Array("(425) 555-0110")
objUser.PutEx ADS_PROPERTY_UPDATE, "otherPager", Array("(425) 555-0111")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherMobile", Array("(425) 555-0112", "(425) 555-0113")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherFacsimileTelephoneNumber", Array("(425) 555-0114")
objUser.PutEx ADS_PROPERTY_UPDATE, "otherIpPhone", Array("5556")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Address Page Information for a User Account

Description
Configures address-related information for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "streetAddress", "Building 43" & vbCrLf & "One Microsoft Way"
objUser.Put "l", "Redmond"
objUser.Put "st", "Washington"
objUser.Put "postalCode", "98053"
objUser.Put "c", "US"

objUser.PutEx ADS_PROPERTY_UPDATE, _
 "postOfficeBox", Array("2222", "2223", "2224")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Dial-In Properties for a User Account

Description
Configures Dial-In attribute values for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "msNPAllowDialin", TRUE
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "msNPSavedCallingStationID", Array("555-0100", "555-0111")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "msNPCallingStationID", Array("555-0100", "555-0111")
objUser.Put "msRADIUSServiceType", 4
objUser.Put "msRADIUSCallbackNumber", "555-0112"
objUser.Put "msRASSavedFramedIPAddress", 167903442
objUser.Put "msRADIUSFramedIPAddress", 167903442 'value of 10.2.0.210
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "msRASSavedFramedRoute", _
        Array("10.1.0.0/16 0.0.0.0 1", "192.168.1.0/24 0.0.0.0 3")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "msRADIUSFramedRoute", _
        Array("10.1.0.0/16 0.0.0.0 1", "192.168.1.0/24 0.0.0.0 3")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Organization Properties for a User Account

Description
Configures organization information for the MyerKen Active Directory user account. The script also assigns MyerKen as the manager for LewJudy and AkersKim.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=Myerken,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "title", "Manager"
objUser.Put "department", "Executive Management Team"
objUser.Put "company", "Fabrikam"
objUser.Put "manager", _
    "cn=AckermanPilar,OU=Management,dc=NA,dc=fabrikam,dc=com"
objUser.SetInfo

Set objUser01 = GetObject _
    ("LDAP://cn=LewJudy,OU=Sales,dc=NA,dc=fabrikam,dc=com")
Set objUser02 = GetObject _
    ("LDAP://cn=AckersKim,OU=Sales,dc=NA,dc=fabrikam,dc=com")

objUser01.Put "manager", objUser.Get("distinguishedName")
objUser02.Put "manager", objUser.Get("distinguishedName")

objUser01.SetInfo
objUser02.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the Expiration Date for a User Account

Description
Configures the MyerKen Active Directory user account to expire on March 30, 2003.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.AccountExpirationDate = "03/30/2003"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring the UPN Suffixes Defined in the Forest

Description
Configures the upnSuffixes attribute of the Partitions container and displays the new values to the operator.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3
Set objPartitions = GetObject _
    ("LDAP://cn=Partitions,cn=Configuration,dc=fabrikam,dc=com")

objPartitions.PutEx ADS_PROPERTY_APPEND, _
    "upnSuffixes", Array("sa.fabrikam.com","corp.fabrikam.com")
objPartitions.SetInfo

For Each Suffix in objPartitions.GetEx("upnSuffixes")
    WScript.Echo Suffix
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring User Profile Properties

Description
Configures user profile settings for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.Put "profilePath", "\\sea-dc-01\Profiles\myerken"
objUser.Put "scriptPath", "logon.bat"
objUser.Put "homeDirectory", "\\sea-dc-01\HomeFolders\myerken"
objUser.Put "homeDrive", "H"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring User Profile Properties for a User Account

Description
Configures user profile properties for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=Myerken,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.Put "profilePath", "\\sea-dc-01\Profiles\myerken"
objUser.Put "scriptPath", "logon.bat"
objUser.Put "homeDirectory", "\\sea-dc-01\HomeFolders\myerken"
objUser.Put "homeDrive", "H"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring User Telephone Properties

Description
Configures telephone numbers and telephone-related attributes for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.Put "homePhone", "(425) 555-1111"
objUser.Put "pager", "(425) 555-2222"
objUser.Put "mobile", "(425) 555-3333"
objUser.Put "facsimileTelephoneNumber", "(425) 555-4444"
objUser.Put "ipPhone", "5555"
objUser.Put "info", "Please do not call this user account" & _
  " at home unless there is a work-related emergency. Call" & _
  " this user's mobile phone before calling the pager number"

objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherHomePhone", Array("(425) 555-1112")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherPager", Array("(425) 555-2223")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherMobile", Array("(425) 555-3334", "(425) 555-3335")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherFacsimileTelephoneNumber", Array("(425) 555-4445")
objUser.PutEx ADS_PROPERTY_UPDATE, _
    "otherIpPhone", Array("6666")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying a Published Certificate to a User Account

Description
Copies a published certificate from a template account (userTemplate) to the MyerKen Active Directory user account. This operation appends the new certificate without deleting any existing certificates.

For more information about user account attributes, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const ADS_PROPERTY_APPEND = 3

Set objUserTemplate = _
    GetObject("LDAP://cn=userTemplate,OU=Management,dc=NA,dc=fabrikam,dc=com")
arrUserCertificates = objUserTemplate.GetEx("userCertificate")

Set objUser = _
    GetObject("LDAP://cn=MyerKen,OU=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_APPEND, "userCertificate", arrUserCertificates
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying Allowed Logon Hours from One Account to Another

Description
Copies the allowed logon hours from a template account (userTemplate) and assigns them to the MyerKen Active Directory user account. The MyerKen account will thus have the same logon hour restrictions as those assigned to the userTemplate account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUserTemplate = _
    GetObject("LDAP://cn=userTemplate,OU=Management,dc=NA,dc=fabrikam,dc=com")
arrLogonHours = objUserTemplate.Get("logonHours")

Set objUser = _
    GetObject("LDAP://cn=MyerKen,OU=Management,dc=NA,dc=fabrikam,dc=com")
objUser.Put "logonHours", arrLogonHours
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an Active Directory User Account

Description
Creates a user account in Active Directory. This script only creates the account, it does not enable it.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")
Set objUser = objOU.Create("User", "cn=MyerKen")
objUser.Put "sAMAccountName", "myerken"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating 1,000 User Accounts

Description
Demonstration script that creates 1,000 user accounts (named UserNo1, UserNo2, UserNo3, etc.) in the Users container in Active Directory. The script is useful for test scenarios that require multiple user accounts.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objRootDSE = GetObject("LDAP://rootDSE")
Set objContainer = GetObject("LDAP://cn=Users," & _
    objRootDSE.Get("defaultNamingContext"))

For i = 1 To 1000
    Set objLeaf = objContainer.Create("User", "cn=UserNo" & i)
    objLeaf.Put "sAMAccountName", "UserNo" & i
    objLeaf.SetInfo
Next

WScript.Echo "1000 Users created."

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Contact in Active Directory

Description
Creates a contact account named MyerKen in the Management organizational unit in a hypothetical domain named fabrikam.com.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com")
Set objUser = objOU.Create("contact", "cn=MyerKen")
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a User, a Group, and an OU

Description
Demonstration script that: 1) creates a new Active Directory organizational unit; 2) creates a new user account and new security group; and, 3) adds the new user as a member of that security group.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extenions installed
Windows 98 | Yes, with Active Directory Client Extenions installed

Script Code

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")
Set objOU = objDomain.Create("organizationalUnit", "ou=Management")
objOU.SetInfo

Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
Set objUser = objOU.Create("User", "cn= AckermanPilar")
objUser.Put "sAMAccountName", "AckermanPila"
objUser.SetInfo

Set objOU = GetObject("LDAP://OU=Management,dc=fabrikam,dc=com")
Set objGroup = objOU.Create("Group", "cn=atl-users")
objGroup.Put "sAMAccountName", "atl-users"
objGroup.SetInfo

objGroup.Add objUser.ADSPath

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Post Office Box from a User Account

Description
Removes a specified value (2224) from the postOfficeBox attribute of the MyerKen Active Directory user account. This operation removes only the specified post office box; other entries will not be deleted.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_DELETE = 4

Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_DELETE, "postOfficeBox", Array("2224")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting One Telephone Number from a User Account

Description
Deletes a phone number from the otherMobile attribute of the MyerKen Active Directory user account. This operation removes only one phone number (425-555-0113) without affecting any other phone numbers.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=Myerken,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_DELETE, "otherMobile", Array("(425) 555-0113")

objUser.SetInfo
objComptCopy.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Published Certificates from a User Account

Description
Retrieves a set of published certificates from a template account (userTemplate), and then deletes each of those certificates from the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const ADS_PROPERTY_DELETE = 4

Set objUserTemplate = _
    GetObject("LDAP://cn=userTemplate,OU=Management,dc=NA,dc=fabrikam,dc=com")
arrUserCertificates = objUserTemplate.GetEx("userCertificate")

Set objUser = _
    GetObject("LDAP://cn=MyerKen,OU=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_DELETE, "userCertificate", arrUserCertificates
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Calling Station ID from a User Account

Description
Removes a specific calling station ID from the MyerKen Active Directory user account. This operation only removes the specified calling station ID; no other IDs are deleted.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_DELETE = 4

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_DELETE, _
    "msNPSavedCallingStationID", Array("555-0111")
objUser.PutEx ADS_PROPERTY_DELETE, _
    "msNPCallingStationID", Array("555-0111")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Phone Number

Description
Deletes a phone number from a user account with multiple mobile phone numbers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_DELETE = 4

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_DELETE, _
  "otherMobile", Array("(425) 555-3334")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting Single- and Multi-Valued Attributes

Description
Deletes selected attributes from a user account. Demonstrates how to delete single-valued attributes as well as how to delete a single entry from a multi-valued attribute.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_DELETE = 4

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_DELETE, _
  "otherTelephone", Array("(425) 555-1213")
objUser.PutEx ADS_PROPERTY_DELETE, _
  "initials", Array("E.")

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a User Account from Active Directory

Description
Deletes the user account for MyerKen from the HR organizational unit in a hypothetical domain named fabrikam.com.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://ou=hr,dc=fabrikam,dc=com")
objOU.Delete "user", "cn=MyerKen"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining the Owner of a User Account

Description
Reports the owner of the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

Set objNtSecurityDescriptor = objUser.Get("ntSecurityDescriptor")
WScript.Echo "Owner Tab"
WScript.Echo "Current owner of this item: " & objNtSecurityDescriptor.Owner

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining User Account Status

Description
Identifies whether a user account is enabled or disabled.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

If objUser.AccountDisabled = FALSE Then
      WScript.Echo "The account is enabled."
Else
      WScript.Echo "The account is disabled."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining User Logon Hours

Description
Retrieves the allowed logon hours for a user.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Dim arrLogonHoursBytes(20)
Dim arrLogonHoursBits(167)
arrDayOfWeek = Array _
  ("Sun", "Mon", "Tue", "Wed", _
   "Thu", "Fri", "Sat")

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfoEx Array("logonHours"), 0
arrLogonHours = objUser.Get("logonHours")

For i = 1 To LenB(arrLogonHours)
     arrLogonHoursBytes(i-1) = AscB(MidB(arrLogonHours, i, 1))
Next

intCounter = 0
intLoopCounter = 0
WScript.Echo "Day  Byte 1   Byte 2   Byte 3"
For Each LogonHourByte In arrLogonHoursBytes
  arrLogonHourBits = GetLogonHourBits(LogonHourByte)

   If intCounter = 0 Then
    WScript.STDOUT.Write arrDayOfWeek(intLoopCounter) & Space(2)
    intLoopCounter = intLoopCounter + 1
  End If

    For Each LogonHourBit In arrLogonHourBits
        WScript.STDOUT.Write LogonHourBit
        intCounter = 1 + intCounter

        If intCounter = 8 or intCounter = 16 Then
          WScript.STDOUT.Write Space(1)
        End If

        If intCounter = 24 Then
          WScript.echo VbCr
          intCounter = 0
        End If
    Next
Next

Function GetLogonHourBits(x)
    Dim arrBits(7)
    For i = 7 to 0 Step -1
        If x And 2^i Then
            arrBits(i) = 1
        Else
            arrBits(i) = 0
        End If
    Next
    GetLogonHourBits = arrBits
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining When a Password Expires

Description
Determines the date when a user password will expire.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SEC_IN_DAY = 86400
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000

Set objUserLDAP = GetObject _
  ("LDAP://CN=myerken,OU=management,DC=fabrikam,DC=com")
intCurrentValue = objUserLDAP.Get("userAccountControl")

If intCurrentValue and ADS_UF_DONT_EXPIRE_PASSWD Then
  wscript.echo "The password does not expire."
Else
  dtmValue = objUserLDAP.PasswordLastChanged
  Wscript.echo "The password was last changed on " & _
  DateValue(dtmValue) & " at " & TimeValue(dtmValue) & VbCrLf & _
  "The difference between when the password was last set" & VbCrLf & _
  "and today is " & int(now - dtmValue) & " days"
  intTimeInterval = int(now - dtmValue)

  Set objDomainNT = GetObject("WinNT://fabrikam")
  intMaxPwdAge = objDomainNT.Get("MaxPasswordAge")
  If intMaxPwdAge < 0 Then
    WScript.Echo "The Maximum Password Age is set to 0 in the " & _
      "domain. Therefore, the password does not expire."
  Else
    intMaxPwdAge = (intMaxPwdAge/SEC_IN_DAY)
    Wscript.echo "The maximum password age is " & intMaxPwdAge & " days"
    If intTimeInterval >= intMaxPwdAge Then
      Wscript.echo "The password has expired."
    Else
      Wscript.echo "The password will expire on " & _
      DateValue(dtmValue + intMaxPwdAge) & " (" & _
      int((dtmValue + intMaxPwdAge) - now) & " days from today" & ")."
    End If
  End If
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining When a Password was Last Set

Description
Identifies the last time a user password was set.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://CN=myerken,OU=management,DC=Fabrikam,DC=com")
dtmValue = objUser.PasswordLastChanged
WScript.echo "pwdLastSet is: " & dtmValue

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining When a User Account Expires

Description
Reports the date that the MyerKen Active Directory user account expires.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
dtmAccountExpiration = objUser.AccountExpirationDate

If Err.Number = -2147467259 Or dtmAccountExpiration = "1/1/1970" Then
    WScript.Echo "No account expiration specified"
Else
    WScript.Echo "Account expiration: " & objUser.AccountExpirationDate
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining When an Account Expires

Description
Returns the expiration date for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

dtmAccountExpiration = objUser.AccountExpirationDate

If err.number = -2147467259 Or _
 dtmAccountExpiration = "1/1/1970" Then
  WScript.echo "No account expiration specified"
Else
  WScript.echo "Account expiration:" & _
    objUser.AccountExpirationDate
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling the “Smartcard Required” Attribute for a User Account

Description
Disables the setting that required MyerKen to use a smartcard when logging on to Active Directory.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_SMARTCARD_REQUIRED = &h40000
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intUAC = objUser.Get("userAccountControl")

If (intUAC AND ADS_UF_SMARTCARD_REQUIRED) <> 0 Then
    objUser.Put "userAccountControl", intUAC XOR ADS_UF_SMARTCARD_REQUIRED
    objUser.SetInfo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling a Password Flag

Description
Disables the option allowing a password to be stored using reversible encrypted text.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &H80

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

If intUAC AND _
  ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED Then
    objUser.Put "userAccountControl", intUAC XOR _
      ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED
    objUser.SetInfo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling a User Account

Description
Disables a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_ACCOUNTDISABLE = 2

Set objUser = GetObject _
("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

objUser.Put "userAccountControl", intUAC OR ADS_UF_ACCOUNTDISABLE
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying Allowed Logon Hours for a User Account

Description
Returns the allowed logon hours for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Dim arrLogonHoursBytes(20)
Dim arrLogonHoursBits(167)
arrDayOfWeek = Array _
    ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
arrLogonHours = objUser.Get("logonHours")

For i = 1 To LenB(arrLogonHours)
    arrLogonHoursBytes(i-1) = AscB(MidB(arrLogonHours, i, 1))
    WScript.Echo "MidB returns: " & MidB(arrLogonHours, i, 1)
    WScript.Echo "arrLogonHoursBytes: " & arrLogonHoursBytes(i-1)
    wscript.echo vbcrlf
Next

intCounter = 0
intLoopCounter = 0
WScript.echo "Day  Byte 1   Byte 2   Byte 3"
For Each LogonHourByte In arrLogonHoursBytes
    arrLogonHourBits = GetLogonHourBits(LogonHourByte)

    If intCounter = 0 Then
        WScript.STDOUT.Write arrDayOfWeek(intLoopCounter) & Space(2)
        intLoopCounter = intLoopCounter + 1
    End If

    For Each LogonHourBit In arrLogonHourBits
        WScript.STDOUT.Write LogonHourBit
        intCounter = 1 + intCounter

        If intCounter = 8 or intCounter = 16 Then
            Wscript.STDOUT.Write Space(1)
        End If

        If intCounter = 24 Then
            WScript.echo vbCr
            intCounter = 0
        End If
    Next
Next

Function GetLogonHourBits(x)
    Dim arrBits(7)
    For i = 7 to 0 Step -1
        If x And 2^i Then
            arrBits(i) = 1
        Else
            arrBits(i) = 0
        End If
    Next
    GetLogonHourBits = arrBits
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling the User Cannot Change Password Option

Description
Disables the User Cannot Change Password option, allowing the user to change their password.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const CHANGE_PASSWORD_GUID  = _
  "{ab721a53-1e2f-11d0-9819-00aa0040529b}"

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
Set objSD   = objUser.Get("nTSecurityDescriptor")
Set objDACL = objSD.DiscretionaryAcl
arrTrustees = Array("nt authority\self", "everyone")

For Each strTrustee In arrTrustees
  For Each ace In objDACL
    If(LCase(ace.Trustee) = strTrustee) Then
      If((ace.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) And _
        (LCase(ace.ObjectType) = CHANGE_PASSWORD_GUID)) Then
        objDACL.RemoveAce ace
      End If
    End If
  Next
Next

objUser.Put "nTSecurityDescriptor", objSD
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying Domain Password Attributes

Description
Displays password policy settings for the domain.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const MIN_IN_DAY = 1440, SEC_IN_MIN = 60

Set objDomain = GetObject("WinNT://fabrikam")
Set objAdS = GetObject("LDAP://dc=fabrikam,dc=com")

intMaxPwdAgeSeconds = objDomain.Get("MaxPasswordAge")
intMinPwdAgeSeconds = objDomain.Get("MinPasswordAge")
intLockOutObservationWindowSeconds = objDomain.Get("LockoutObservationInterval")
intLockoutDurationSeconds = objDomain.Get("AutoUnlockInterval")
intMinPwdLength = objAds.Get("minPwdLength")

intPwdHistoryLength = objAds.Get("pwdHistoryLength")
intPwdProperties = objAds.Get("pwdProperties")
intLockoutThreshold = objAds.Get("lockoutThreshold")
intMaxPwdAgeDays = _
  ((intMaxPwdAgeSeconds/SEC_IN_MIN)/MIN_IN_DAY) & " days"
intMinPwdAgeDays = _
  ((intMinPwdAgeSeconds/SEC_IN_MIN)/MIN_IN_DAY) & " days"
intLockOutObservationWindowMinutes = _
  (intLockOutObservationWindowSeconds/SEC_IN_MIN) & " minutes"

If intLockoutDurationSeconds <> -1 Then
  intLockoutDurationMinutes = _
(intLockOutDurationSeconds/SEC_IN_MIN) & " minutes"
Else
  intLockoutDurationMinutes = _
    "Administrator must manually unlock locked accounts"
End If

WScript.Echo "maxPwdAge = " & intMaxPwdAgeDays
WScript.Echo "minPwdAge = " & intMinPwdAgeDays
WScript.Echo "minPwdLength = " & intMinPwdLength
WScript.Echo "pwdHistoryLength = " & intPwdHistoryLength
WScript.Echo "pwdProperties = " & intPwdProperties
WScript.Echo "lockOutThreshold = " & intLockoutThreshold
WScript.Echo "lockOutObservationWindow = " & intLockOutObservationWindowMinutes
WScript.Echo "lockOutDuration = " & intLockoutDurationMinutes

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying Password Property Attributes

Description
Displays password settings for the domain.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objHash = CreateObject("Scripting.Dictionary")

objHash.Add "DOMAIN_PASSWORD_COMPLEX", &h1
objHash.Add "DOMAIN_PASSWORD_NO_ANON_CHANGE", &h2
objHash.Add "DOMAIN_PASSWORD_NO_CLEAR_CHANGE", &h4
objHash.Add "DOMAIN_LOCKOUT_ADMINS", &h8
objHash.Add "DOMAIN_PASSWORD_STORE_CLEARTEXT", &h16
objHash.Add "DOMAIN_REFUSE_PASSWORD_CHANGE", &h32

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")

intPwdProperties = objDomain.Get("PwdProperties")
WScript.Echo "pwdProperties = " & intPwdProperties

For Each Key In objHash.Keys
    If objHash(Key) And intPwdProperties Then
        WScript.Echo Key & " is enabled"
    Else
        WScript.Echo Key & " is disabled"
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying User Account Password Attributes

Description
Displays password-related attributes for an individual user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_PASSWORD_EXPIRED = &h800000
Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const CHANGE_PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}"

Set objHash = CreateObject("Scripting.Dictionary")
objHash.Add "ADS_UF_PASSWD_NOTREQD", &h00020
objHash.Add "ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED", &h0080
objHash.Add "ADS_UF_DONT_EXPIRE_PASSWD", &h10000

Set objUser = GetObject _
  ("LDAP://CN=MyerKen,OU=management,DC=Fabrikam,DC=com")
intUserAccountControl = objUser.Get("userAccountControl")

Set objUserNT = GetObject("WinNT://fabrikam/myerken")
intUserFlags = objUserNT.Get("userFlags")

If ADS_UF_PASSWORD_EXPIRED And intUserFlags Then
  blnExpiredFlag = True
  Wscript.Echo "ADS_UF_PASSWORD_EXPIRED is enabled"
Else
  Wscript.Echo "ADS_UF_PASSWORD_EXPIRED is disabled"
End If

For Each Key In objHash.Keys
  If objHash(Key) And intUserAccountControl Then
    WScript.Echo Key & " is enabled"
  Else
    WScript.Echo Key & " is disabled"
  End If
Next

Set objSD = objUser.Get("nTSecurityDescriptor")
Set objDACL = objSD.DiscretionaryAcl
For Each Ace In objDACL
  If ((Ace.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) And _
      (LCase(Ace.ObjectType) = CHANGE_PASSWORD_GUID)) Then
    blnACEPresent = True
  End If
Next
If blnACEPresent Then
  Wscript.Echo "ADS_UF_PASSWD_CANT_CHANGE is enabled"
Else
  Wscript.Echo "ADS_UF_PASSWD_CANT_CHANGE is disabled"
End If

If blnExpiredFlag = True Then
  Wscript.echo "pwdLastSet is null"
Else
  Wscript.echo "pwdLastSet is " & objUser.PasswordLastChanged
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Requiring a User to Logon on Using a Smartcard

Description
Configures the MyerKen user account so that the user must use a smartcard in order to logon to Active Directory.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_SMARTCARD_REQUIRED = &h40000
Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intUAC = objUser.Get("userAccountControl")

If (intUAC AND ADS_UF_SMARTCARD_REQUIRED) = 0 Then
  objUser.Put "userAccountControl", intUAC XOR ADS_UF_SMARTCARD_REQUIRED
  objUser.SetInfo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling a User Account

Description
Enables a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.AccountDisabled = FALSE
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling a User to Log on at Any Time

Description
Configures the MyerKen Active Directory user account so that the user can log on at any time on any day of the week.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1
Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "logonHours", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Ensuring that an Account will not Expire

Description
Configures a user account so that it will not expire. This is done by setting the expiration date to 1/1/1970.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.AccountExpirationDate = "01/01/1970"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Audit Permissions for a User Account

Description
Returns audit permissions for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SE_SACL_PROTECTED = &H2000
Const ADS_SECURITY_INFO_OWNER = &H1
Const ADS_SECURITY_INFO_GROUP = &H2
Const ADS_OPTION_SECURITY_MASK =&H3
Const ADS_SECURITY_INFO_DACL = &H4
Const ADS_SECURITY_INFO_SACL = &H8

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.SetOption ADS_OPTION_SECURITY_MASK, ADS_SECURITY_INFO_OWNER _
    Or ADS_SECURITY_INFO_GROUP Or ADS_SECURITY_INFO_DACL _
        Or ADS_SECURITY_INFO_SACL

Set objNtSecurityDescriptor = objUser.Get("ntSecurityDescriptor")

intNtSecurityDescriptorControl = objNtSecurityDescriptor.Control

WScript.Echo "Auditing Tab"
WScript.StdOut.WriteLine "Allow inheritable auditing entries from" & _
    "the parent to "
WScript.StdOut.Write "propogate to this object and all child objects "
If (intNtSecurityDescriptorControl And SE_SACL_PROTECTED) Then
    Wscript.Echo "is disabled."
Else
    WScript.Echo "is enabled."
End If
WScript.Echo VbCr

Set objSacl = objNtSecurityDescriptor.SystemAcl
DisplayAceInformation objSacl, "SACL"

Sub DisplayAceInformation(SecurityStructure, strType)
    Const ADS_ACETYPE_SYSTEM_AUDIT = &H2
    Const ADS_ACETYPE_SYSTEM_AUDIT_OBJECT = &H7

    intAceCount = 0
    For Each objAce In SecurityStructure
        strTrustee = Mid(objAce.Trustee,1,12)
        If StrComp(strTrustee, "NT AUTHORITY", 1) <> 0 Then
            intAceCount = intAceCount + 1
            WScript.Echo strType & " permission entry: " & intAceCount
            WScript.Echo "Name: " & objAce.Trustee

            intAceType = objAce.AceType
            WScript.Echo "ACETYPE IS: " & intAceType
            If (intAceType = ADS_ACETYPE_SYSTEM_AUDIT or _
                intAceType = ADS_ACETYPE_SYSTEM_AUDIT_OBJECT) Then
                WScript.StdOut.Write "Type: Success or Failure Audit"
            Else
                WScript.StdOut.Write "Audit Type Unknown."
            End If
            ReadBitsInAccessMask(objAce.AccessMask)
            WScript.Echo VbCr
        End If
    Next
End Sub

Sub ReadBitsInAccessMask(AccessMask)
    Const ADS_RIGHT_DELETE = &H10000
    Const ADS_RIGHT_READ_CONTROL = &H20000
    Const ADS_RIGHT_WRITE_DAC = &H40000
    Const ADS_RIGHT_WRITE_OWNER = &H80000
    Const ADS_RIGHT_DS_CREATE_CHILD = &H1
    Const ADS_RIGHT_DS_DELETE_CHILD = &H2
    Const ADS_RIGHT_ACTRL_DS_LIST = &H4
    Const ADS_RIGHT_DS_SELF = &H8
    Const ADS_RIGHT_DS_READ_PROP = &H10
    Const ADS_RIGHT_DS_WRITE_PROP = &H20
    Const ADS_RIGHT_DS_DELETE_TREE = &H40
    Const ADS_RIGHT_DS_LIST_OBJECT = &H80
    Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

    WScript.Echo VbCrLf & "Standard Access Rights"
    If (AccessMask And ADS_RIGHT_DELETE) Then _
        WScript.Echo vbTab & "-Delete an object."
    If (AccessMask And ADS_RIGHT_READ_CONTROL) Then _
        WScript.Echo vbTab & "-Read permissions."
    If (AccessMask And ADS_RIGHT_WRITE_DAC) Then _
        WScript.Echo vbTab & "-Write permissions."
    If (AccessMask And ADS_RIGHT_WRITE_OWNER) Then _
        WScript.Echo vbTab & "-Modify owner."

    WScript.Echo VbCrLf & "Directory Service Specific Access Rights"
    If (AccessMask And ADS_RIGHT_DS_CREATE_CHILD) Then _
        WScript.Echo vbTab & "-Create child objects."
    If (AccessMask And ADS_RIGHT_DS_DELETE_CHILD) Then _
        WScript.Echo vbTab & "-Delete child objects."
    If (AccessMask And ADS_RIGHT_ACTRL_DS_LIST) Then _
        WScript.Echo vbTab & "-Enumerate an object."
    If (AccessMask And ADS_RIGHT_DS_READ_PROP) Then _
        WScript.Echo vbTab & "-Read the properties of an object."
    If (AccessMask And ADS_RIGHT_DS_WRITE_PROP) Then _
        WScript.Echo vbTab & "-Write the properties of an object."
    If (AccessMask And ADS_RIGHT_DS_DELETE_TREE) Then _
        WScript.Echo vbTab & "-Delete a tree of objects"
    If (AccessMask And ADS_RIGHT_DS_LIST_OBJECT) Then _
        WScript.Echo vbTab & "-List a tree of objects."

    WScript.Echo VbCrLf & "Control Access Rights"
    If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) + _
        (AccessMask And ADS_RIGHT_DS_SELF) = 0 Then
        WScript.Echo "-None"
    Else
        If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) Then _
            WScript.Echo vbTab & "-Extended access rights."
            If (AccessMask And ADS_RIGHT_DS_SELF) Then
                WScript.Echo vbTab & _
                    "-Active Directory must validate a property "
                WScript.Echo vbTab & _
                    " write operation beyond the schema definition "
                WScript.Echo vbTab & " for the attribute."
        End If
    End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating the Dial-In Property Configuration for a User Account

Description
Enumerates the Dial-In configuration settings for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const FourthOctet = 1
Const ThirdOctet = 256
Const SecondOctet = 65536
Const FirstOctet = 16777216

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

blnMsNPAllowDialin = objUser.Get("msNPAllowDialin")
WScript.Echo "Remote Access Permission (Dial-in or VPN)"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "Control access through Remote Access Policy"
    Err.Clear
Else
    If blnMsNPAllowDialin = True Then
        WScript.Echo "Allow access (msNPAllowDialin)"
    Else
        WScript.Echo "Deny access (msNPAllowDialin)"
    End If
End If
WScript.Echo VbCr

arrMsNPSavedCallingStationID = objUser.GetEx("msNPSavedCallingStationID")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No Caller-ID specified."
    Err.Clear
Else
    WScript.Echo "Verify Caller ID (msNPSavedCallingStationID): "
    For Each strValue in arrMsNPSavedCallingStationID
        WScript.echo strValue
    Next

    objUser.GetEx "msNPCallingStationID"
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Calling station ID(s) specified but not assigned."
        Err.Clear
    Else
        WScript.echo "Calling station ID(s) assigned."
    End If

End If
WScript.Echo VbCr

intMsRADIUSServiceType = objUser.Get("msRADIUSServiceType")
WScript.Echo "Callback Options"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No Callback"
    Err.Clear
Else
    strMsRADIUSCallbackNumber = objUser.Get("msRADIUSCallbackNumber")
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Set by caller (Routing and Remote Access Service only)"
        Err.Clear

    strMsRASSavedCallbackNumber = objUser.Get("msRASSavedCallbackNumber")
    If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Unused value of " & strMsRASSavedCallbackNumber & _
            " appears in the Always Callback to field."
    Else
        Err.Clear
    End If
Else
    WScript.Echo "Always Callback to: " & _
        strMsRADIUSCallbackNumber & " (msRADIUSCallbackNumber)"
    End If
End If
WScript.Echo VbCr

intMsRASSavedFramedIPAddress = objUser.Get("msRASSavedFramedIPAddress")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No static IP address assigned."
    Err.Clear
Else
    If sgn(intMsRASSavedFramedIPAddress) = -1 Then
        intIP = intMsRASSavedFramedIPAddress
        WScript.StdOut.Write 256 + (int(intIP/FirstOctet)) & "."
        intFirstRemainder = intIP mod FirstOctet
        WScript.StdOut.Write 256 + (int(intFirstRemainder/SecondOctet)) & "."
        intSecondRemainder = intFirstRemainder mod SecondOctet
        WScript.StdOut.Write 256 + (int(intSecondRemainder/ThirdOctet)) & "."
        intThirdRemainder = intSecondRemainder mod ThirdOctet
        WScript.Echo 256 + (int(intThirdRemainder/FourthOctet))
    Else
        intIP = intMsRASSavedFramedIPAddress
        WScript.StdOut.Write  int(intIP/FirstOctet) & "."
        intFirstRemainder = intIP mod FirstOctet
        WScript.StdOut.Write  int(intFirstRemainder/SecondOctet) & "."
        intSecondRemainder = intFirstRemainder mod SecondOctet
        WScript.StdOut.Write  int(intSecondRemainder/ThirdOctet) & "."
        intThirdRemainder = intSecondRemainder mod ThirdOctet
        WScript.Echo int(intThirdRemainder/FourthOctet)
    End If

    objUser.Get "msRADIUSFramedIPAddress"
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Static IP address specified but not assigned."
        Err.Clear
    Else
        WScript.Echo "Static IP Address assigned."
    End If

End If
WScript.Echo VbCr

arrMsRASSavedFramedRoute = objUser.GetEx("msRASSavedFramedRoute")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No static Routes specified."
    Err.Clear
Else
    WScript.echo "Static Routes (msRASSavedFramedRoute):"
    WScript.Echo vbTab & "CIDR 0.0.0.0 Metric"
    For Each strValue in arrMsRASSavedFramedRoute
        WScript.echo vbTab & strValue
    Next

    objUser.GetEx "msRADIUSFramedRoute"
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Static Routes specified but not assigned."
        Err.Clear
    Else
        WScript.echo "Static Routes assigned."
    End If
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Locating All the Disabled User Accounts in Active Directory

Description
Returns a list of all disabled user accounts in the fabrikam.com domain.

For more information about searching Active Directory, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_ACCOUNTDISABLE = 2

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
    "<GC://dc=fabrikam,dc=com>;(objectCategory=User)" & _
        ";userAccountControl,distinguishedName;subtree"
Set objRecordSet = objCommand.Execute

intCounter = 0
While Not objRecordset.EOF
    intUAC=objRecordset.Fields("userAccountControl")
    If intUAC AND ADS_UF_ACCOUNTDISABLE Then
        WScript.echo objRecordset.Fields("distinguishedName") & " is disabled"
        intCounter = intCounter + 1
    End If
    objRecordset.MoveNext
Wend

WScript.Echo VbCrLf & "A total of " & intCounter & " accounts are disabled."

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a User Account

Description
Moves a user account from one OU to another.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://ou=sales,dc=na,dc=fabrikam,dc=com")
objOU.MoveHere _
    "LDAP://cn=BarrAdam,OU=hr,dc=na,dc=fabrikam,dc=com", vbNullString

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Moving a User Account to a New Domain

Description
Uses the MoveHere method of IADsContainer to move a user account to another domain. Note that there are a number of restrictions associated with performing this type of move operation. For details, see the Directory Services Platform SDK.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU = GetObject("LDAP://ou=management,dc=na,dc=fabrikam,dc=com")
objOU.MoveHere _
    "LDAP://cn=AckermanPilar,OU=management,dc=fabrikam,dc=com", vbNullString

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying User Profile Paths

Description
Changes the server name portion of the user profile path to \\fabrikam for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strCurrentProfilePath = objUser.Get("profilePath")
intStringLen = Len(strCurrentProfilePath)
intStringRemains = intStringLen - 11
strRemains = Mid(strCurrentProfilePath, 12, intStringRemains)
strNewProfilePath = "\\fabrikam" & strRemains
objUser.Put "profilePath", strNewProfilePath
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Preventing a User From Changing His or Her Password

Description
Enables the User Cannot Change Password option, which prevents the user from changing their password.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const ADS_ACEFLAG_OBJECT_TYPE_PRESENT = &H1
Const CHANGE_PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}"
Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
Set objSD = objUser.Get("ntSecurityDescriptor")
Set objDACL = objSD.DiscretionaryAcl
arrTrustees = array("nt authority\self", "EVERYONE")

For Each strTrustee in arrTrustees
  Set objACE = CreateObject("AccessControlEntry")
    objACE.Trustee = strTrustee
  objACE.AceFlags = 0
  objACE.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT
  objACE.Flags = ADS_ACEFLAG_OBJECT_TYPE_PRESENT
  objACE.ObjectType = CHANGE_PASSWORD_GUID
  objACE.AccessMask = ADS_RIGHT_DS_CONTROL_ACCESS
  objDACL.AddAce objACE
Next

objSD.DiscretionaryAcl = objDACL
objUser.Put "nTSecurityDescriptor", objSD
objUser. SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Account Page Information for a User Account

Description
Returns basic account information for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=Myerken,ou=Management,dc=NA,dc=fabrikam,dc=com")

strUserPrincipalName = objUser.Get("userPrincipalName")
strSAMAccountName = objUser.Get("sAMAccountName")
strUserWorkstations = objUser.Get("userWorkstations")

Set objDomain = GetObject("LDAP://dc=NA,dc=fabrikam,dc=com")
strDC = objDomain.Get("dc")

WScript.echo "User Principal Name: " & strUserPrincipalName
WScript.echo "SAM Account Name: " & strSAMAccountName
WScript.echo "User Workstations: " & strUserWorkstations
WScript.echo "dc: " & strDC

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Address Page Information for a User Account

Description
Returns address-related attribute values for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strStreetAddress = objUser.Get("streetAddress")
strLocalityName = objUser.Get("l")
strStreetName = objUser.Get("st")
strPostalCode = objUser.Get("postalCode")
strCountryName = objUser.Get("c")
arrPostOfficeBox = objUser.GetEx("postOfficeBox")

WScript.echo "Street Address: " & strStreetAddress
WScript.echo "Locality: " & strLocalityName
WScript.echo "Street: " & strStreetName
WScript.echo "Postal Code: " & strPostalCode
WScript.echo "Country: " & strCountryName

WScript.echo "Post Office Boxes:"
For Each strValue in arrPostOfficeBox
    WScript.echo vbTab & vbTab & strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading COM+ Information for a User Account

Description
Returns COM+ information for the MyerKen Active Directory user account.

For more information about the COM+ attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
strMsCOMUserPartitionSetLink = objUser.Get("msCOM-UserPartitionSetLink")
WScript.Echo "ms-COMUserPartitionSetLink: " & strMsCOMUserPartitionSetLink

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Information from the Object Page for a User Account

Description
Returns information about the MyerKen user account object in Active Directory.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("GC://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strWhenCreated = objUser.Get("whenCreated")
strWhenChanged = objUser.Get("whenChanged")

Set objUSNChanged = objUser.Get("uSNChanged")
dblUSNChanged = _
    Abs(objUSNChanged.HighPart * 2^32 + objUSNChanged.LowPart)

Set objUSNCreated = objUser.Get("uSNCreated")
dblUSNCreated = _
    Abs(objUSNCreated.HighPart * 2^32 + objUSNCreated.LowPart)

objUser.GetInfoEx Array("canonicalName"), 0
arrCanonicalName = objUser.GetEx("canonicalName")

WScript.echo "Canonical Name of object:"
For Each strValue in arrCanonicalName
    WScript.echo vbTab & strValue
Next
WScript.Echo vbCr

WScript.Echo "Object class: " & objUser.Class & vbCrLf
WScript.echo "When Created: " & strWhenCreated & " (Created - GMT)"
WScript.echo "When Changed: " & strWhenChanged & " (Modified - GMT)"
WScript.Echo VbCrLf
WScript.Echo "USN Changed: " & dblUSNChanged & " (USN Current)"
WScript.Echo "USN Created: " & dblUSNCreated & " (USN Original)"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Security Permissions for a User Account

Description
Returns security permissions for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SE_DACL_PROTECTED = &H1000

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

Set objNtSecurityDescriptor = objUser.Get("ntSecurityDescriptor")

intNtSecurityDescriptorControl = objNtSecurityDescriptor.Control

WScript.Echo "Permissions Tab"
WScript.StdOut.WriteLine "Allow inheritable permissions from the parent to"
WScript.StdOut.Write "propogate to this object and all child objects "
If (intNtSecurityDescriptorControl And SE_DACL_PROTECTED) Then
    Wscript.Echo "is disabled."
Else
    WScript.Echo "is enabled."
End If
WScript.Echo VbCr

Set objDiscretionaryAcl = objNtSecurityDescriptor.DiscretionaryAcl
DisplayAceInformation objDiscretionaryAcl, "DACL"

Sub DisplayAceInformation(SecurityStructure, strType)
    Const ADS_ACETYPE_ACCESS_ALLOWED = &H0
    Const ADS_ACETYPE_ACCESS_DENIED = &H1
    Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &H5
    Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
    intAceCount = 0
    For Each objAce In SecurityStructure
        strTrustee = Mid(objAce.Trustee,1,12)
        If StrComp(strTrustee, "NT AUTHORITY", 1) <> 0 Then
            intAceCount = intAceCount + 1
            WScript.Echo strType & " permission entry: " & intAceCount
            WScript.Echo "Name: " & objAce.Trustee

            intAceType = objAce.AceType
            If (intAceType = ADS_ACETYPE_ACCESS_ALLOWED Or _
                intAceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT) Then
                WScript.Echo "Type: Allow Access"
            ElseIf (intAceType = ADS_ACETYPE_ACCESS_DENIED Or _
                intAceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) Then
                WScript.StdOut.Write "Type: Deny Acess"
            Else
                WScript.Echo "Acess Type Unknown."
            End If
            ReadBitsInAccessMask(objAce.AccessMask)
            WScript.Echo VbCr
        End If
    Next
End Sub

Sub ReadBitsInAccessMask(AccessMask)
    Const ADS_RIGHT_DELETE = &H10000
    Const ADS_RIGHT_READ_CONTROL = &H20000
    Const ADS_RIGHT_WRITE_DAC = &H40000
    Const ADS_RIGHT_WRITE_OWNER = &H80000
    Const ADS_RIGHT_DS_CREATE_CHILD = &H1
    Const ADS_RIGHT_DS_DELETE_CHILD = &H2
    Const ADS_RIGHT_ACTRL_DS_LIST = &H4
    Const ADS_RIGHT_DS_SELF = &H8
    Const ADS_RIGHT_DS_READ_PROP = &H10
    Const ADS_RIGHT_DS_WRITE_PROP = &H20
    Const ADS_RIGHT_DS_DELETE_TREE = &H40
    Const ADS_RIGHT_DS_LIST_OBJECT = &H80
    Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

    WScript.Echo VbCrLf & "Standard Access Rights"
    If (AccessMask And ADS_RIGHT_DELETE) Then _
        WScript.Echo vbTab & "-Delete an object."
    If (AccessMask And ADS_RIGHT_READ_CONTROL) Then _
        WScript.Echo vbTab & "-Read permissions."
    If (AccessMask And ADS_RIGHT_WRITE_DAC) Then _
        WScript.Echo vbTab & "-Write permissions."
    If (AccessMask And ADS_RIGHT_WRITE_OWNER) Then _
        WScript.Echo vbTab & "-Modify owner."

    WScript.Echo VbCrLf & "Directory Service Specific Access Rights"
    If (AccessMask And ADS_RIGHT_DS_CREATE_CHILD) Then _
        WScript.Echo vbTab & "-Create child objects."
    If (AccessMask And ADS_RIGHT_DS_DELETE_CHILD) Then _
        WScript.Echo vbTab & "-Delete child objects."
    If (AccessMask And ADS_RIGHT_ACTRL_DS_LIST) Then _
        WScript.Echo vbTab & "-Enumerate an object."
    If (AccessMask And ADS_RIGHT_DS_READ_PROP) Then _
        WScript.Echo vbTab & "-Read the properties of an object."
    If (AccessMask And ADS_RIGHT_DS_WRITE_PROP) Then _
        WScript.Echo vbTab & "-Write the properties of an object."
    If (AccessMask And ADS_RIGHT_DS_DELETE_TREE) Then _
        WScript.Echo vbTab & "-Delete a tree of objects"
    If (AccessMask And ADS_RIGHT_DS_LIST_OBJECT) Then _
        WScript.Echo vbTab & "-List a tree of objects."

    WScript.Echo VbCrLf & "Control Access Rights"
    If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) + _
        (AccessMask And ADS_RIGHT_DS_SELF) = 0 Then
            WScript.Echo "-None"
    Else
        If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) Then _
            WScript.Echo vbTab & "-Extended access rights."
        If (AccessMask And ADS_RIGHT_DS_SELF) Then
            WScript.Echo vbTab & _
                "-Active Directory must validate a property "
            WScript.Echo vbTab & _
                " write operation beyond the schema definition "
            WScript.Echo vbTab & " for the attribute."
        End If
    End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading userAccountControl Values for an Active Directory User Account

Description
Reads values from the userAccountControl of the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objHash = CreateObject("Scripting.Dictionary")

objHash.Add "ADS_UF_SMARTCARD_REQUIRED", &h40000
objHash.Add "ADS_UF_TRUSTED_FOR_DELEGATION", &h80000
objHash.Add "ADS_UF_NOT_DELEGATED", &h100000
objHash.Add "ADS_UF_USE_DES_KEY_ONLY", &h200000
objHash.Add "ADS_UF_DONT_REQUIRE_PREAUTH", &h400000

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

If objUser.IsAccountLocked = True Then
    WScript.echo "ADS_UF_LOCKOUT is enabled"
Else
    WScript.echo "ADS_UF_LOCKOUT is disabled"
End If
wscript.echo VBCRLF

For Each Key In objHash.Keys
    If objHash(Key) And intUAC Then
        WScript.echo Key & " is enabled"
    Else
        WScript.echo Key & " is disabled"
  End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing All Dial-In Properties for a User Account

Description
Clears all Dial-In attribute values for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.PutEx ADS_PROPERTY_CLEAR, "msNPAllowDialin", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msNPCallingStationID", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msNPSavedCallingStationID", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRADIUSServiceType", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRADIUSCallbackNumber", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRASSavedCallbackNumber", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRADIUSFramedIPAddress", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRASSavedFramedIPAddress", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRADIUSFramedRoute", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "msRASSavedFramedRoute", 0

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Requiring a Password Change

Description
Forces a user to change their password the next time they logon.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://CN=myerken,OU=management,DC=Fabrikam,DC=com")
objUser.Put "pwdLastSet", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning All the Attributes of the Active Directory User Class

Description
Returns a list of mandatory and optional attributes for the User class in Active Directory.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUserClass = GetObject("LDAP://schema/user")
Set objSchemaClass = GetObject(objUserClass.Parent)

i = 0
WScript.Echo "Mandatory attributes:"
For Each strAttribute in objUserClass.MandatoryProperties
    i= i + 1
    WScript.StdOut.Write i & vbTab & strAttribute
    Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
    WScript.StdOut.Write " (Syntax: " & objAttribute.Syntax & ")"
    If objAttribute.MultiValued Then
        WScript.Echo " Multivalued"
    Else
        WScript.Echo " Single-valued"
    End If
Next

WScript.Echo VbCrLf & "Optional attributes:"
For Each strAttribute in objUserClass.OptionalProperties
    i=i + 1
    WScript.StdOut.Write i & vbTab & strAttribute
    Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
    WScript.StdOut.Write " [Syntax: " & objAttribute.Syntax & "]"
    If objAttribute.MultiValued Then
        WScript.Echo " Multivalued"
    Else
        WScript.Echo " Single-valued"
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Organization Information

Description
Retrieves user account attributes found on the Organization page of the user account object in Active Directory Users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strTitle = objUser.Get("title")
strDepartment = objUser.Get("department")
strCompany = objUser.Get("company")
strManager = objUser.Get("manager")

strDirectReports = _
  objUser.GetEx("directReports")

WScript.echo "title: " & strTitle
WScript.echo "department: " & strDepartment
WScript.echo "company: " & strCompany
WScript.echo "manager: " & strManager

For Each strValue in strDirectReports
  WScript.echo "directReports: " & strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Organization Information for a User Account

Description
Retrieves organization information (including a list of all direct reports) for the MyerKen user account in Active Directory.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strTitle = objUser.Get("title")
strDepartment = objUser.Get("department")
strCompany = objUser.Get("company")
strManager = objUser.Get("manager")

arrDirectReports = objUser.GetEx("directReports")

WScript.echo "Title: " & strTitle
WScript.echo "Department: " & strDepartment
WScript.echo "Company: " & strCompany
WScript.echo "Manager: " & strManager

WScript.echo "Direct Reports:"
For Each strValue in arrDirectReports
    WScript.echo strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Published Certificates for a User Account

Description
Retrieves a list of all the published certificates assigned to the MyerKen user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes, but supply full path to Certutil.exe
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D
Const ForWriting = 2
Const WshRunning = 0

Set objUser = GetObject _
    ("GC://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.GetInfoEx Array("userCertificate"), 0
arrUserCertificates = objUser.GetEx("userCertificate")

If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No assigned certificates"
    WScript.Quit
Else
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strPath = "."
    intFileCounter = 0

    For Each arrUserCertificate in arrUserCertificates
        strFileName = "file" & intFileCounter
        strFullName = objFSO.BuildPath(strPath, strFileName)
        Set objFile = objFSO.OpenTextFile(strFullName, ForWriting, True)

        For i = 1 To LenB(arrUserCertificate)
            ReDim Preserve arrUserCertificatesChar(i - 1)
            arrUserCertificatesChar(i-1) = Hex(AscB(MidB(arrUserCertificate, i, 3)))
        Next

        intCounter=0
        For Each HexVal in arrUserCertificatesChar
            intCounter=intCounter + 1
            If Len(HexVal) = 1 Then
                objFile.Write(0 & HexVal & " ")
            Else
                objFile.Write(HexVal & " ")
            End If
        Next
        objFile.Close
        Set objFile = Nothing

        Set objExecCmd1 = objShell.Exec _
            ("certutil -decodeHex " & strFileName & " " & strFileName & ".cer")
        Do While objExecCmd1.Status = WshRunning
            WScript.Sleep 100
        Loop
        Set objExecCmd1 = Nothing

        Set objExecCmd2 = objShell.Exec("certutil " & strFileName & ".cer")
        Set objStdOut = objExecCmd2.StdOut
        Set objExecCmd2 = Nothing

        WScript.Echo VbCrLf & "Certificate " & intFileCounter + 1
        While Not objStdOut.AtEndOfStream
            strLine = objStdOut.ReadLine
            If InStr(strLine, "Issuer:") Then
                WScript.Echo Trim(strLine)
                WScript.Echo vbTab & Trim(objStdOut.ReadLine)
            End If
            If InStr(strLine, "Subject:") Then
                Wscript.Echo Trim(strLine)
                WScript.Echo vbTab & Trim(objStdOut.ReadLine)
            End If
            If InStr(strLine, "NotAfter:") Then
                strLine = Trim(strLine)
                WScript.Echo "Expires:"
                Wscript.Echo vbTab & Mid(strLine, 11)
            End If
        Wend

        objFSO.DeleteFile(strFullName)
        objFSO.DeleteFile(strPath & "\" & strFileName & ".cer")

        intFileCounter = intFileCounter + 1
    Next
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Telephone Settings for a User Account

Description
Displays all the telephone attribute values for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strHomePhone = objUser.Get("homePhone")
strPager = objUser.Get("pager")
strMobile = objUser.Get("mobile")
strIpPhone = objUser.Get("ipPhone")
strInfo = objUser.Get("info")
strFacsimileTelephoneNumber = objUser.Get("facsimileTelephoneNumber")

arrOtherHomePhone = objUser.GetEx("otherHomePhone")
arrOtherPager = objUser.GetEx("otherPager")
arrOtherMobile = objUser.GetEx("otherMobile")
arrOtherIpPhone = objUser.GetEx("otherIpPhone")
arrOtherFacsimileTelephoneNumber = _
    objUser.GetEx("otherFacsimileTelephoneNumber")

WScript.Echo "homePhone: " & strHomePhone
WScript.Echo "pager: " & strPager
WScript.Echo "mobile: " & strMobile
WScript.Echo "ipPhone: " & strIpPhone
WScript.Echo "info: " & strInfo
WScript.Echo "facsimileTelephoneNumber: " & strFacsimileTelephoneNumber

WScript.Echo "otherHomePhone:"
For Each strValue in arrOtherHomePhone
    WScript.Echo strValue
Next

WScript.Echo "otherPager:"
For Each strValue in arrOtherPager
    WScript.Echo strValue
Next

WScript.Echo "otherMobile:"
For Each strValue in arrOtherMobile
    WScript.Echo strValue
Next

WScript.Echo "otherIpPhone:"
For Each strValue in arrOtherIpPhone
    WScript.Echo strValue
Next

WScript.Echo "otherFacsimileTelephoneNumber:"
For Each strValue in arrOtherFacsimileTelephoneNumber
    WScript.Echo strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Password Change Attribute

Description
Identifies whether or not a user is allowed to change their password.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
Const CHANGE_PASSWORD_GUID  = _
 "{ab721a53-1e2f-11d0-9819-00aa0040529b}"
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
Set objSD = objUser.Get("nTSecurityDescriptor")
Set objDACL = objSD.DiscretionaryAcl
For Each Ace In objDACL
  If ((Ace.AceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) And _
      (LCase(Ace.ObjectType) = CHANGE_PASSWORD_GUID)) Then
    blnEnabled = True
  End If
Next
If blnEnabled Then
  WScript.Echo "ADS_UF_PASSWD_CANT_CHANGE is enabled"
Else
  WScript.Echo "ADS_UF_PASSWD_CANT_CHANGE is disabled"
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving User Account Account Properties

Description
Retrieves user account attributes found on the Account page of the user account object in Active Directory Users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strUserPrincipalName = objUser.Get("userPrincipalName")
strSAMAccountName = objUser.Get("sAMAccountName")
strUserWorkstations = objUser.Get("userWorkstations")

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")
objDomain.GetInfoEx Array("dc"), 0
strDC = objDomain.Get("dc")

WScript.echo "userPrincipalName: " & strUserPrincipalName
WScript.echo "sAMAccountName: " & strSAMAccountName
WScript.echo "UserWorkstations: " & strUserWorkstations
WScript.echo "dc: " & strDC

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving User Account Address Attributes

Description
Retrieves user account attributes found on the Address page of the user account object in Active Directory users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strStreetAddress = objUser.Get("streetAddress")
strPostOfficeBox = objUser.Get("postOfficeBox")
strLocalityName = objUser.Get("l")
strStreetName = objUser.Get("st")
strPostalCode = objUser.Get("postalCode")
strCountryName = objUser.Get("c")

WScript.Echo "streetAddress: " & strStreetAddress
WScript.Echo "postOfficeBox: " & strPostOfficeBox
WScript.Echo "l: " & strLocalityName
WScript.Echo "st: " & strStreetName
WScript.Echo "postalCode: " & strPostalCode
WScript.Echo "c: " & strCountryName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving User Account Properties

Description
Retrieves user account attributes found on the General Properties page of the user account object in Active Directory users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strGivenName = objUser.Get("givenName")
strInitials = objUser.Get("initials")
strSn = objUser.Get("sn")
strDisplayName = objUser.Get("displayName")
strPhysicalDeliveryOfficeName = _
  objUser.Get("physicalDeliveryOfficeName")
strTelephoneNumber = objUser.Get("telephoneNumber")
strMail = objUser.Get("mail")
strWwwHomePage = objUser.Get("wWWHomePage")

strDescription = objUser.GetEx("description")
strOtherTelephone = objUser.GetEx("otherTelephone")
strUrl = objUser.GetEx("url")

WScript.echo "givenName: " & strGivenName
WScript.echo "initials: " & strInitials
WScript.echo "sn: " & strSn
WScript.echo "displayName: " & strDisplayName
WScript.echo "physicalDeliveryOfficeName: " & _
 strPhysicalDeliveryOfficeName
WScript.echo "telephoneNumber: " & strTelephoneNumber
WScript.echo "mail: " & strMail
WScript.echo "wWWHomePage: " & strWwwHomePage

For Each strValue in strDescription
  WScript.echo "description: " & strValue
Next
For Each strValue in strOtherTelephone
  WScript.echo "otherTelephone: " & strValue
Next
For Each strValue in strUrl
  WScript.echo "url: " & strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving User Profile Properties

Description
Retrieves user account attributes found on the Profile page of the user account object in Active Directory users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strProfilePath = objUser.Get("profilePath")
strScriptPath = objUser.Get("scriptPath")
strHomeDirectory = objUser.Get("homeDirectory")
strHomeDrive = objUser.Get("homeDrive")

WScript.echo "profilePath: " & strProfilePath
WScript.echo "scriptPath: " & strScriptPath
WScript.echo "homeDirectory: " & strHomeDirectory
WScript.echo "homeDrive: " & strHomeDrive

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving User Telephone Properties

Description
Retrieves user account attributes found on the Telephones page of the user account object in Active Directory users and Computers.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfo

strHomePhone = objUser.Get("homePhone")
strPager = objUser.Get("pager")
strMobile = objUser.Get("mobile")
strIpPhone = objUser.Get("ipPhone")
strInfo = objUser.Get("info")
strFacsimileTelephoneNumber = _
  objUser.Get("facsimileTelephoneNumber")

strOtherHomePhone = objUser.GetEx("otherHomePhone")
strOtherPager = objUser.GetEx("otherPager")
strOtherMobile = objUser.GetEx("otherMobile")
strOtherIpPhone = objUser.GetEx("otherIpPhone")
strOtherFacsimileTelephoneNumber = _
  objUser.GetEx("otherFacsimileTelephoneNumber")

WScript.echo "homePhone: " & strHomePhone
WScript.echo "pager: " & strPager
WScript.echo "mobile: " & strMobile
WScript.echo "ipPhone: " & strIpPhone
WScript.echo "info: " & strInfo
WScript.echo "facsimileTelephoneNumber: " & _
 strFacsimileTelephoneNumber

For Each strValue in strOtherHomePhone
  WScript.echo "otherHomePhone: " & strValue
Next
For Each strValue in strOtherPager
  WScript.echo "otherPager: " & strValue
Next
For Each strValue in strOtherMobile
  WScript.echo "otherMobile: " & strValue
Next
For Each strValue in strOtherIpPhone
  WScript.echo "otherIpPhone: " & strValue
Next
For Each strValue in strOtherFacsimileTelephoneNumber
  WScript.echo "otherFacsimileTelephoneNumber: " & strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Searching for a User Account in Active Directory

Description
Subroutine that searches Active Directory to see if a user account with the name testew already exists.

For more information about searching Active Directory, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

CheckForUser("testew")
Sub CheckForUser(samAccountName)
    dtStart = TimeValue(Now())
    strUserName = samAccountName
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Open "Provider=ADsDSOObject;"

    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection

    objCommand.CommandText = _
        "<LDAP://dc=fabrikam,dc=com>;(&(objectCategory=User)" & _
            "(samAccountName=" & strUserName & "));samAccountName;subtree"

    Set objRecordSet = objCommand.Execute

    If objRecordset.RecordCount = 0 Then
        WScript.Echo "sAMAccountName: " & strUserName & " does not exist."
    Else
        WScript.Echo strUserName & " exists."
    End If

    objConnection.Close
    WScript.Echo "Script completed in " & _
        Second(TimeValue(now()) - dtStart) & _
            " second or less."
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting a Password So It Never Expires

Description
Configures the domain password for a user account to ensure that the password will never expire.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000

Set objUser = GetObject _
    ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

If ADS_UF_DONT_EXPIRE_PASSWD AND intUAC Then
    Wscript.Echo "Already enabled"
Else
    objUser.Put "userAccountControl", intUAC XOR _
        ADS_UF_DONT_EXPIRE_PASSWD
    objUser.SetInfo
    WScript.Echo "Password never expires is now enabled"
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting a User’s Password

Description
Configures a new password for a user.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
 ("LDAP://cn=MyerKen,ou=management,dc=fabrikam,dc=com")
objUser.SetPassword "i5A2sj*!"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting an Account Expiration Date

Description
Configures a user account to expire on 3/30/2003.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.AccountExpirationDate = "03/30/2003"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting the Primary Group for a User

Description
Sets the primary group for the MyerKen Active Directory user account to MgmtUniversal.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_APPEND = 3

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

Set objGroup = GetObject _
    ("LDAP://cn=MgmtUniversal,ou=Management,dc=NA,dc=fabrikam,dc=com")
objGroup.GetInfoEx Array("primaryGroupToken"), 0
intPrimaryGroupToken = objGroup.Get("primaryGroupToken")

objGroup.PutEx ADS_PROPERTY_APPEND, _
   "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objGroup.SetInfo
objUser.Put "primaryGroupID", intPrimaryGroupToken

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Unlocking an Active Directory User Account

Description
Unlocks the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.IsAccountLocked = False
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using Flags to Determine Account Status

Description
Uses the userAccountControl to determine whether a user account is enabled or disabled.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_ACCOUNTDISABLE = 2

Set objUser = GetObject _
    ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

If intUAC AND ADS_UF_ACCOUNTDISABLE Then
    Wscript.echo "The account is disabled"
Else
    Wscript.echo "The account is enabled"
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using Flags to Enable a User Account

Description
Uses the userAccountControl to enable a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_ACCOUNTDISABLE = 2

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

If intUAC AND ADS_UF_ACCOUNTDISABLE Then
  objUser.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
  objUser.SetInfo
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing User Account Address Attributes

Description
Configures address-related attributes for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
   ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.Put "streetAddress", "Building 43" & _
  VbCrLf & "One Microsoft Way"
objUser.Put "l", "Redmond"
objUser.Put "st", "Washington"
objUser.Put "postalCode", "98053"
objUser.Put "c", "US"
objUser.Put "postOfficeBox", "2222"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Writing User Account Properties

Description
Configures general attributes for a user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")

objUser.Put "userPrincipalName", "MyerKen@fabrikam.com"
objUser.Put "sAMAccountName", "MyerKen01"
objUser.Put "userWorkstations", "wks1,wks2,wks3"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Adding a User to a Local Group

Description
Adds a user (kenmyer) to the local Administrators group on a computer named MyComputer.

For more information about working with local groups, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")
objGroup.Add(objUser.ADsPath)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Local Group on a Computer

Description
Creates a local group named FinanceUsers on a computer named MyComputer.

For more information about working with local groups, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("group", "FinanceUsers")
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Local Group

Description
Deletes a local group named FinanceUsers from a computer named MyComputer.

For more information about working with local groups, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set objComputer = GetObject("WinNT://" & strComputer & "")
objComputer.Delete "group", "FinanceUsers"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a User from a Local Group

Description
Removes kenmyer from the local Administrators group on a computer named MyComputer.

For more information about working with local groups, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set objGroup = GetObject("WinNT://" & strComputer & "/Adminstrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/kenmyer,user")

objGroup.Remove(objUser.ADsPath)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Local Groups and Their Members

Description
Returns a list of local groups (and their members) found on a computer named atl-win2k-01.

For more information about associating users with local groups, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "atl-win2k-01"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    Wscript.Echo objGroup.Name
    For Each objUser in objGroup.Members
        Wscript.Echo vbTab & objUser.Name
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing All the Local Groups a User Belongs To

Description
Returns a list of all the local groups on the computer atl-win2k-01 that a user named kenmyer belongs to.

For more information about associating users with local groups, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "atl-win2k-01"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    For Each objUser in objGroup.Members
        If objUser.name = "kenmyer" Then
            Wscript.Echo objGroup.Name
        End If
    Next
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing the Local Administrator Password

Description
Binds to the local Administrator account on the computer MyComputer, and changes the password for the account to testpassword.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator, user")
objUser.SetPassword "testpassword"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring a Local User Account Password So It Never Expires

Description
Binds to a local user account on a computer named atl-win2k-01, and configures the account's password so that it never expires.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000

strDomainOrWorkgroup = "Fabrikam"
strComputer = "atl-win2k-01"
strUser = "KenMeyer"

Set objUser = GetObject("WinNT://" & strDomainOrWorkgroup & "/" & _
    strComputer & "/" & strUser & ",User")

objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring a Local User Account So It Never Expires

Description
Binds to the local user account on a computer named atl-win2k-01, and configures the account so that it never expires.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT:// " & strComputer & "/kenmyer ")
objUserFlags = objUser.Get("UserFlags")
objPasswordExpirationFlag = objUserFlags OR ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userFlags", objPasswordExpirationFlag
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Local User Account

Description
Creates a local user account (Admin2) on a computer named MyComputer, and sets the password for the account to test.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "test"
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting a Local User Account

Description
Deletes the local user account Admin2 from a computer named MyComputer.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
strUser = "Admin2"
Set objComputer = GetObject("WinNT://" & strComputer & "")
objComputer.Delete "user", strUser

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Account Expiration Dates for a Windows NT 4.0 Domain

Description
Determines the expiration dates for all the user accounts in a Windows NT 4.0 domain named Fabrikam.

For more information about the AccountExpirationDate attribute used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objDomain = GetObject("WinNT://fabrikam,domain")
objDomain.Filter = Array("User")
For Each objUser In objDomain
   If IsNull(objUser.AccountExpirationDate) Then
       Wscript.Echo objUser.Name, "Account has no expiration date."
   Else
       Wscript.Echo objUser.Name, objUser.AccountExpirationDate
   End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Determining Whether an Account Exists in a Windows NT 4.0 Domain

Description
Subroutine that checks to see if a user account (kenmyer) exists in a Windows NT 4.0 domain named Fabrikam.

For more information about the WinNT provider used to return information from a Windows NT 4.0 domain, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

QueryForUser("kenmyer")
Wscript.Echo "This user account does not exist."

Sub QueryForUser(strUserName)
    Set objDomain = GetObject("WinNT://FABRIKAM")
    objDomain.Filter = Array("user")
    For Each User In objDomain
        If lcase(User.Name) = lcase(strUserName) Then
            WScript.Echo User.Name & " already exists."
            WScript.Quit
        End If
    Next
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Disabling a Local User Account

Description
Disables the local Guest account on a computer named MyComputer.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "MyComputer"
Set objUser = GetObject("WinNT://" & strComputer & "/Guest")
objUser.AccountDisabled = True
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating All the User Accounts in an NT 4.0 Domain

Description
Returns a list of all the user accounts in a Windows NT 4.0 domain named Fabrikam.

For more information about the WinNT provider used to return information from a Windows NT 4.0 domain, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objDomain = GetObject("WinNT://fabrikam,domain")
objDomain.Filter = Array("User")
For Each objUser In objDomain
    Wscript.Echo objUser.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating User Accounts on the Local Computer

Description
Returns a list of all the user accounts found on the local computer.

For more information about working with local user accounts, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | No

Script Code

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set colAccounts = GetObject("WinNT://" & strComputer & "")
colAccounts.Filter = Array("user")
For Each objUser In colAccounts
    Wscript.Echo objUser.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Requiring a Local User to Change His or Her Password

Description
Binds to a local user account on the computer named atl-win2k-01, and configures the account so that the user (kenmyer) must change his password the next time he logs on.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT:// " & strComputer & "/kenmyer ")
objUser.Put "PasswordExpired", 1
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning Attribute Values for a Local User Account

Description
Displays mandatory and optional attributes (and their values) for a local user account named kenmyer on a computer named atl-win2k-01.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT:// " & strComputer & "/kenmyer ")
Set objClass = GetObject(objUser.Schema)

WScript.Echo "Mandatory properties for " & objUser.Name & ":"
For Each property In objClass.MandatoryProperties
    WScript.Echo property, objUser.Get(property)
Next

WScript.Echo "Optional properties for " & objUser.Name & ":"
For Each property In objClass.OptionalProperties
    WScript.Echo property, objUser.Get(property)
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving userAccountControl Values for a Local User Account

Description
Accesses the userAccountControl to retrieve attribute values for the local user account kenmyer on a computer named atl-win2k-01. These attribute values include such things as account status (enabled or disabled), whether the user requires a password and, if so, whether or not that password will ever expire.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_UF_SCRIPT = &H0001
Const ADS_UF_ACCOUNTDISABLE = &H0002
Const ADS_UF_HOMEDIR_REQUIRED = &H0008
Const ADS_UF_LOCKOUT = &H0010
Const ADS_UF_PASSWD_NOTREQD = &H0020
Const ADS_UF_PASSWD_CANT_CHANGE = &H0040
Const ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED = &H0080
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
Const ADS_UF_SMARTCARD_REQUIRED = &H40000
Const ADS_UF_PASSWORD_EXPIRED = &H800000

Set usr = GetObject("WinNT://atl-win2k-01/kenmyer")
flag = usr.Get("UserFlags")

If flag AND ADS_UF_SCRIPT Then
    Wscript.Echo "Logon script will be executed."
Else
    Wscript.Echo "Logon script will not be executed."
End If

If flag AND ADS_UF_ACCOUNTDISABLE Then
    Wscript.Echo "Account is disabled."
Else
    Wscript.Echo "Account is not disabled."
End If

If flag AND ADS_UF_HOMEDIR_REQUIRED Then
    Wscript.Echo "Home directory required."
Else
    Wscript.Echo "Home directory not required."
End If

If flag AND ADS_UF_PASSWD_NOTREQD Then
    Wscript.Echo "Password not required."
Else
    Wscript.Echo "Password required."
End If

If flag AND ADS_PASSWORD_CANT_CHANGE Then
    Wscript.Echo "User cannot change password."
Else
    Wscript.Echo "User can change password."
End If

If flag AND ADS_UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED Then
    Wscript.Echo "Encrypted password allowed."
Else
    Wscript.Echo "Encrypted password not allowed."
End If

If flag AND ADS_UF_DONT_EXPIRE_PASSWD Then
    Wscript.Echo "Password does not expire."
Else
    Wscript.Echo "Password expires."
End If

If flag AND ADS_UF_SMARTCARD_REQUIRED Then
    Wscript.Echo "Smartcard required for logon."
Else
    Wscript.Echo "Smart card not required for logon."
End If

If flag AND ADS_UF_PASSWORD_EXPIRED Then
    Wscript.Echo "Password has expired."
Else
    Wscript.Echo "Password has not expired."
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Setting an Expiration Date for a Local User Account

Description
Binds to a local user account (kenmyer) on a computer named atl-win2k-01, and configures the account to expire on March 1, 2003.

For more information about working with local user accounts, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

strComputer = "atl-win2k-01"
Set objUser = GetObject("WinNT:// " & strComputer & "/kenmyer ")
objUser.AccountExpirationDate = #03/01/2003#
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using WMI to Enumerate Local Groups

Description
Returns information about the local groups found on a computer.

For more information about the Win32_Group class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed and except for the property LocalAccount
Windows 98 | Yes, with WMI installed, and except for the property LocalAccount
Windows 98 | Yes, with WMI installed, and except for the property LocalAccount

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_Group  Where LocalAccount = True")
For Each objItem in colItems
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "Local Account: " & objItem.LocalAccount
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "SID: " & objItem.SID
    Wscript.Echo "SID Type: " & objItem.SIDType
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Using WMI to Enumerate Local User Accounts

Description
Returns information about the local user accounts found on a computer.

For more information about the Win32_UserAccount class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes, except for the property LocalAccount
Windows NT 4.0 | Yes, except for the property LocalAccount, and with WMI installed
Windows 98 | Yes, except for the property LocalAccount, and with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_UserAccount Where LocalAccount = True")
For Each objItem in colItems
    Wscript.Echo "Account Type: " & objItem.AccountType
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Disabled: " & objItem.Disabled
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "Full Name: " & objItem.FullName
    Wscript.Echo "Local Account: " & objItem.LocalAccount
    Wscript.Echo "Lockout: " & objItem.Lockout
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Password Changeable: " & objItem.PasswordChangeable
    Wscript.Echo "Password Expires: " & objItem.PasswordExpires
    Wscript.Echo "Password Required: " & objItem.PasswordRequired
    Wscript.Echo "SID: " & objItem.SID
    Wscript.Echo "SID Type: " & objItem.SIDType
    Wscript.Echo "Status: " & objItem.Status
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the User Logged on to a Remote Computer

Description
Returns the user name of the user currently logged on to a remote computer. To use this script, replace RemoteComputer with the name of the remote computer you want to check.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "RemoteComputer"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
    Wscript.Echo objComputer.UserName
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Logon Session Information

Description
Returns information about logon sessions associated with the user currently logged on to a computer.

For more information about the Win32_LogonSession class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LogonSession")
For Each objItem in colItems
    Wscript.Echo "Authentication Package: " & objItem.AuthenticationPackage
    Wscript.Echo "Logon ID: " & objItem.LogonId
    Wscript.Echo "Logon Type: " & objItem.LogonType
    Wscript.Echo "Start Time: " & objItem.StartTime
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Assigning a New Group Policy Link to an OU

Description
Assigns the Group Policy link Sales Policy to the Sales OU in Active Directory.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objContainer = GetObject _
   ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

strExistingGPLink = objContainer.Get("gPLink")

strGPODisplayName = "Sales Policy"
strGPOLinkOptions = 2
strNewGPLink = "[" & GetGPOADsPath & ";" & strGPOLinkOptions & "]"

objContainer.Put "gPLink", strExistingGPLink & strNewGPLink
objContainer.Put "gPOptions", "0"

objContainer.SetInfo

Function GetGPOADsPath
  Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Provider=ADsDSOObject;"

  Set objCommand = CreateObject("ADODB.Command")
  objCommand.ActiveConnection = objConnection

  objCommand.CommandText = _
  "<LDAP://cn=Policies,cn=System,dc=NA,dc=fabrikam,dc=com>;;" & _
  "distinguishedName,displayName;onelevel"
  Set objRecordSet = objCommand.Execute

  While Not objRecordSet.EOF
    If objRecordSet.Fields("displayName") = strGPODisplayName Then
      GetGPOADsPath = "LDAP://" & objRecordSet.Fields("distinguishedName")
      objConnection.Close
      Exit Function
    End If
    objRecordSet.MoveNext
  Wend
  objConnection.Close
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Changing the Manager of an OU

Description
Assigns the user account AkersKim as manager of the Sales OU in Active Directory.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

objContainer.Put "managedBy", "cn=AkersKim,ou=Sales,dc=NA,dc=fabrikam,dc=com"
objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing COM+ Attributes from a User Account

Description
Removes all information from the msCOM-UserPartitionSetLink attribute of the MyerKen user account in Active Directory.

For more information about clearing attributes using PutEx, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_CLEAR, "msCOM-UserPartitionSetLink", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


TechNet Script Center Template

Clearing the COM+ Partition Link Set of an OU

Description
Removes the COM+ partition link set assigned to the Sales OU in Active Directory.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1
Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

objContainer.PutEx ADS_PROPERTY_CLEAR, "msCOM-UserPartitionSetLink", 0

objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing the General Properties of an OU

Description
Modifies the attribute values found on the General Properties page in Active Directory Users and Computers for an OU named Sales.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1
Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

objContainer.PutEx ADS_PROPERTY_CLEAR, "description", 0
objContainer.PutEx ADS_PROPERTY_CLEAR, "street", 0
objContainer.PutEx ADS_PROPERTY_CLEAR, "l", 0
objContainer.PutEx ADS_PROPERTY_CLEAR, "st", 0
objContainer.PutEx ADS_PROPERTY_CLEAR, "postalCode", 0
objContainer.PutEx ADS_PROPERTY_CLEAR, "c", 0
objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing the Group Policy Links Assigned to an OU

Description
Removes all the Group Policy links assigned to the Sales OU in Active Directory.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")
objContainer.PutEx ADS_PROPERTY_CLEAR, "gPLink", 0
objContainer.PutEx ADS_PROPERTY_CLEAR, "gPOptions", 0
objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an OU

Description
Creates a new organizational unit within Active Directory.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")
Set objOU = objDomain.Create("organizationalUnit", "ou=Management")
objOU.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating an OU in an Existing OU

Description
Creates a new organizational unit (OU2) in an existing organizational unit (OU1).

For more information about scripting OU management, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOU1 = GetObject("LDAP://ou=OU1,dc=na,dc=fabrikam,dc=com")
Set objOU2 = objOU1.Create("organizationalUnit", "ou=OU2")
objOU2.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Deleting an OU

Description
Deletes an organizational unit named HR from the hypothetical domain fabrikam.com.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com")
objDomain.Delete "organizationalUnit", "ou=hr"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating COM+ Partition Sets

Description
Returns a list of Active Directory COM+ partition sets.

For more information about COM+ partition sets, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objCOMPartitionSets = GetObject _
  ("LDAP://cn=ComPartitionSets,cn=System,dc=NA,dc=fabrikam,dc=com")

For Each objPartitionSet in objCOMPartitionSets
  WScript.Echo objPartitionSet.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Identifying the Owner of an OU

Description
Returns the owner of the Sales OU in Active Directory.

For more information about working with Active Directory security descriptor, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

Set objNtSecurityDescriptor = objContainer.Get("ntSecurityDescriptor")

WScript.Echo "Owner Tab"
WScript.Echo "Current owner of this item: " & objNtSecurityDescriptor.Owner

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying the COM+ Partition Set Link of an OU

Description
Assigns the COM+ partition set PartitionSet1 to the Sales OU in Active Directory.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

objContainer.Put "msCOM-UserPartitionSetLink", _
  "cn=PartitionSet1,cn=ComPartitionSets,cn=System,dc=NA,dc=fabrikam,dc=com"

objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Modifying the General Properties of an OU

Description
Modifies the attribute values found on the General Properties page in Active Directory Users and Computers for an OU named Sales.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

objContainer.Put "street", "Building 43" & vbCrLf & "One Microsoft Way"
objContainer.Put "l", "Redmond"
objContainer.Put "st", "Washington"
objContainer.Put "postalCode", "98053"
objContainer.Put "c", "US"

objContainer.PutEx ADS_PROPERTY_UPDATE, _
    "description", Array("Sales staff")

objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading COM+ Partition Information for a Domain

Description
Returns COM+ partition information for the domain na.fabrikam.com.

For more information about COM+ partitions and Active Directory, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objCOMPartitionSets = GetObject _
    ("LDAP://cn=ComPartitionSets,cn=System,dc=NA,dc=fabrikam,dc=com")

For Each objPartitionSet in objCOMPartitionSets
    WScript.Echo objPartitionSet.Name
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading the COM+ Properties of an OU

Description
Returns information about the COM+ properties configured for the Sales OU in Active Directory.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

strMsCOMUserPartitionSetLink = objContainer.Get("msCOM-UserPartitionSetLink")

WScript.Echo "ms-COMUserPartitionSetLink: " & strMsCOMUserPartitionSetLink

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading the Security Descriptor for an OU

Description
Returns the information found on the security descriptor for the Sales OU in Active Directory.

For more information about working with Active Directory security descriptor, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SE_DACL_PROTECTED = &H1000

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

Set objNtSecurityDescriptor = objContainer.Get("ntSecurityDescriptor")

intNtSecurityDescriptorControl = objNtSecurityDescriptor.Control

WScript.Echo "Permissions Tab"
WScript.StdOut.WriteLine "Allow inheritable permissions from the parent to"
WScript.StdOut.Write "propogate to this object and all child objects "
If (intNtSecurityDescriptorControl And SE_DACL_PROTECTED) Then
    Wscript.Echo "is disabled."
Else
    WScript.Echo "is enabled."
End If
WScript.Echo VbCr

Set objDiscretionaryAcl = objNtSecurityDescriptor.DiscretionaryAcl
DisplayAceInformation objDiscretionaryAcl, "DACL"

Sub DisplayAceInformation(SecurityStructure, strType)
    Const ADS_ACETYPE_ACCESS_ALLOWED = &H0
    Const ADS_ACETYPE_ACCESS_DENIED = &H1
    Const ADS_ACETYPE_ACCESS_ALLOWED_OBJECT = &H5
    Const ADS_ACETYPE_ACCESS_DENIED_OBJECT = &H6
    intAceCount = 0
    For Each objAce In SecurityStructure
        strTrustee = Mid(objAce.Trustee,1,12)
        If StrComp(strTrustee, "NT AUTHORITY", 1) <> 0 Then
            intAceCount = intAceCount + 1
            WScript.Echo strType & " permission entry: " & intAceCount
            WScript.Echo "Name: " & objAce.Trustee

            intAceType = objAce.AceType
        If (intAceType = ADS_ACETYPE_ACCESS_ALLOWED Or _
            intAceType = ADS_ACETYPE_ACCESS_ALLOWED_OBJECT) Then
            WScript.Echo "Type: Allow Access"
        ElseIf (intAceType = ADS_ACETYPE_ACCESS_DENIED Or _
            intAceType = ADS_ACETYPE_ACCESS_DENIED_OBJECT) Then
            WScript.StdOut.Write "Type: Deny Acess"
        Else
            WScript.Echo "Acess Type Unknown."
        End If
        ReadBitsInAccessMask(objAce.AccessMask)
        WScript.Echo VbCr
      End If
    Next
End Sub

Sub ReadBitsInAccessMask(AccessMask)
    Const ADS_RIGHT_DELETE = &H10000
    Const ADS_RIGHT_READ_CONTROL = &H20000
    Const ADS_RIGHT_WRITE_DAC = &H40000
    Const ADS_RIGHT_WRITE_OWNER = &H80000
    Const ADS_RIGHT_DS_CREATE_CHILD = &H1
    Const ADS_RIGHT_DS_DELETE_CHILD = &H2
    Const ADS_RIGHT_ACTRL_DS_LIST = &H4
    Const ADS_RIGHT_DS_SELF = &H8
    Const ADS_RIGHT_DS_READ_PROP = &H10
    Const ADS_RIGHT_DS_WRITE_PROP = &H20
    Const ADS_RIGHT_DS_DELETE_TREE = &H40
    Const ADS_RIGHT_DS_LIST_OBJECT = &H80
    Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

    WScript.Echo VbCrLf & "Standard Access Rights"
    If (AccessMask And ADS_RIGHT_DELETE) Then _
        WScript.Echo vbTab & "-Delete an object."
    If (AccessMask And ADS_RIGHT_READ_CONTROL) Then _
        WScript.Echo vbTab & "-Read permissions."
    If (AccessMask And ADS_RIGHT_WRITE_DAC) Then _
        WScript.Echo vbTab & "-Write permissions."
    If (AccessMask And ADS_RIGHT_WRITE_OWNER) Then _
        WScript.Echo vbTab & "-Modify owner."

    WScript.Echo VbCrLf & "Directory Service Specific Access Rights"
    If (AccessMask And ADS_RIGHT_DS_CREATE_CHILD) Then _
      WScript.Echo vbTab & "-Create child objects."
    If (AccessMask And ADS_RIGHT_DS_DELETE_CHILD) Then _
        WScript.Echo vbTab & "-Delete child objects."
    If (AccessMask And ADS_RIGHT_ACTRL_DS_LIST) Then _
        WScript.Echo vbTab & "-Enumerate an object."
    If (AccessMask And ADS_RIGHT_DS_READ_PROP) Then _
        WScript.Echo vbTab & "-Read the properties of an object."
    If (AccessMask And ADS_RIGHT_DS_WRITE_PROP) Then _
        WScript.Echo vbTab & "-Write the properties of an object."
    If (AccessMask And ADS_RIGHT_DS_DELETE_TREE) Then _
        WScript.Echo vbTab & "-Delete a tree of objects"
    If (AccessMask And ADS_RIGHT_DS_LIST_OBJECT) Then _
        WScript.Echo vbTab & "-List a tree of objects."

    WScript.Echo VbCrLf & "Control Access Rights"
    If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) + _
        (AccessMask And ADS_RIGHT_DS_SELF) = 0 Then
          WScript.Echo "-None"
      Else
      If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) Then _
          WScript.Echo vbTab & "-Extended access rights."
      If (AccessMask And ADS_RIGHT_DS_SELF) Then
          WScript.Echo vbTab & "-Active Directory must validate a property "
          WScript.Echo vbTab & " write operation beyond the schema definition "
          WScript.Echo vbTab & " for the attribute."
      End If
    End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading the System Access Control List of an OU

Description
Returns information found on the System Access Control List (SACL) for the Sales OU in Active Directory.

For more information about working with Active Directory security descriptor, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const SE_SACL_PROTECTED = &H2000
Const ADS_SECURITY_INFO_OWNER = &H1
Const ADS_SECURITY_INFO_GROUP = &H2
Const ADS_OPTION_SECURITY_MASK =&H3
Const ADS_SECURITY_INFO_DACL = &H4
Const ADS_SECURITY_INFO_SACL = &H8

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

objContainer.SetOption ADS_OPTION_SECURITY_MASK, ADS_SECURITY_INFO_OWNER _
  Or ADS_SECURITY_INFO_GROUP Or ADS_SECURITY_INFO_DACL _
  Or ADS_SECURITY_INFO_SACL

Set objNtSecurityDescriptor = objContainer.Get("ntSecurityDescriptor")

intNtSecurityDescriptorControl = objNtSecurityDescriptor.Control

WScript.Echo "Auditing Tab"
WScript.StdOut.WriteLine "Allow inheritable auditing entries from" & _
  "the parent to "
WScript.StdOut.Write "propogate to this object and all child objects "
If (intNtSecurityDescriptorControl And SE_SACL_PROTECTED) Then
  Wscript.Echo "is disabled."
Else
  WScript.Echo "is enabled."
End If
WScript.Echo VbCr

Set objSacl = objNtSecurityDescriptor.SystemAcl
DisplayAceInformation objSacl, "SACL"

Sub DisplayAceInformation(SecurityStructure, strType)
  Const ADS_ACETYPE_SYSTEM_AUDIT = &H2
  Const ADS_ACETYPE_SYSTEM_AUDIT_OBJECT = &H7

  intAceCount = 0
  For Each objAce In SecurityStructure
    strTrustee = Mid(objAce.Trustee,1,12)
    If StrComp(strTrustee, "NT AUTHORITY", 1) <> 0 Then
      intAceCount = intAceCount + 1
      WScript.Echo strType & " permission entry: " & intAceCount
      WScript.Echo "Name: " & objAce.Trustee

      intAceType = objAce.AceType
      WScript.Echo "ACETYPE IS: " & intAceType
      If (intAceType = ADS_ACETYPE_SYSTEM_AUDIT or _
       intAceType = ADS_ACETYPE_SYSTEM_AUDIT_OBJECT) Then
        WScript.StdOut.Write "Type: Success or Failure Audit"
      Else
        WScript.StdOut.Write "Audit Type Unknown."
      End If
      ReadBitsInAccessMask(objAce.AccessMask)
      WScript.Echo VbCr
    End If
  Next
End Sub

Sub ReadBitsInAccessMask(AccessMask)
  Const ADS_RIGHT_DELETE = &H10000
  Const ADS_RIGHT_READ_CONTROL = &H20000
  Const ADS_RIGHT_WRITE_DAC = &H40000
  Const ADS_RIGHT_WRITE_OWNER = &H80000
  Const ADS_RIGHT_DS_CREATE_CHILD = &H1
  Const ADS_RIGHT_DS_DELETE_CHILD = &H2
  Const ADS_RIGHT_ACTRL_DS_LIST = &H4
  Const ADS_RIGHT_DS_SELF = &H8
  Const ADS_RIGHT_DS_READ_PROP = &H10
  Const ADS_RIGHT_DS_WRITE_PROP = &H20
  Const ADS_RIGHT_DS_DELETE_TREE = &H40
  Const ADS_RIGHT_DS_LIST_OBJECT = &H80
  Const ADS_RIGHT_DS_CONTROL_ACCESS = &H100

  WScript.Echo VbCrLf & "Standard Access Rights"
  If (AccessMask And ADS_RIGHT_DELETE) Then _
    WScript.Echo vbTab & "-Delete an object."
  If (AccessMask And ADS_RIGHT_READ_CONTROL) Then _
    WScript.Echo vbTab & "-Read permissions."
  If (AccessMask And ADS_RIGHT_WRITE_DAC) Then _
    WScript.Echo vbTab & "-Write permissions."
  If (AccessMask And ADS_RIGHT_WRITE_OWNER) Then _
    WScript.Echo vbTab & "-Modify owner."

  WScript.Echo VbCrLf & "Directory Service Specific Access Rights"
  If (AccessMask And ADS_RIGHT_DS_CREATE_CHILD) Then _
    WScript.Echo vbTab & "-Create child objects."
  If (AccessMask And ADS_RIGHT_DS_DELETE_CHILD) Then _
    WScript.Echo vbTab & "-Delete child objects."
  If (AccessMask And ADS_RIGHT_ACTRL_DS_LIST) Then _
    WScript.Echo vbTab & "-Enumerate an object."
  If (AccessMask And ADS_RIGHT_DS_READ_PROP) Then _
    WScript.Echo vbTab & "-Read the properties of an object."
  If (AccessMask And ADS_RIGHT_DS_WRITE_PROP) Then _
    WScript.Echo vbTab & "-Write the properties of an object."
  If (AccessMask And ADS_RIGHT_DS_DELETE_TREE) Then _
    WScript.Echo vbTab & "-Delete a tree of objects"
  If (AccessMask And ADS_RIGHT_DS_LIST_OBJECT) Then _
    WScript.Echo vbTab & "-List a tree of objects."

  WScript.Echo VbCrLf & "Control Access Rights"
  If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) + _
    (AccessMask And ADS_RIGHT_DS_SELF) = 0 Then
    WScript.Echo "-None"
  Else
    If (AccessMask And ADS_RIGHT_DS_CONTROL_ACCESS) Then _
      WScript.Echo vbTab & "-Extended access rights."
    If (AccessMask And ADS_RIGHT_DS_SELF) Then
      WScript.Echo vbTab & "-Active Directory must validate a property "
      WScript.Echo vbTab & " write operation beyond the schema definition "
      WScript.Echo vbTab & " for the attribute."
    End If
  End If
End Sub

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing an OU Manager

Description
Removes the manager entry for the Active Directory OU named Sales. When this group is run, the OU will no longer have an assigned manager.

For more information about modifying attributes using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")
objContainer.PutEx ADS_PROPERTY_CLEAR, "managedBy", 0
objContainer.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning the Attributes of the organizationalUnit Class

Description
Returns both the mandatory and optional attributes or the organizationalUnit class (as found in the Active Directory schema). This script must be run under CScript.

For more information about the organizationalUnit class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objOrganizationalUnitClass = _
  GetObject("LDAP://schema/organizationalUnit")
Set objSchemaClass = GetObject(objOrganizationalUnitClass.Parent)

i = 0
WScript.Echo "Mandatory attributes:"
For Each strAttribute in objOrganizationalUnitClass.MandatoryProperties
  i= i + 1
  WScript.StdOut.Write i & vbTab & strAttribute
  Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
  WScript.StdOut.Write " (Syntax: " & objAttribute.Syntax & ")"
  If objAttribute.MultiValued Then
    WScript.Echo " Multivalued"
  Else
    WScript.Echo " Single-valued"
  End If
Next

WScript.Echo VbCrLf & "Optional attributes:"
For Each strAttribute in objOrganizationalUnitClass.OptionalProperties
  i= i + 1
  WScript.StdOut.Write i & vbTab & strAttribute
  Set objAttribute = objSchemaClass.GetObject("Property",  strAttribute)
  WScript.StdOut.Write " [Syntax: " & objAttribute.Syntax & "]"
  If objAttribute.MultiValued Then
    WScript.Echo " Multivalued"
  Else
    WScript.Echo " Single-valued"
  End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning the General Properties of an OU

Description
Returns information found on the General Properties page in Active Directory Users and Computers for an OU named Sales.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

strStreetAddress = objContainer.Get("street")
strLocalityName = objContainer.Get("l")
strStreetName = objContainer.Get("st")
strPostalCode = objContainer.Get("postalCode")
strCountryName = objContainer.Get("c")

strDescription = objContainer.GetEx("description")

For Each strValue in strDescription
  WScript.echo "description: " & strValue
Next

WScript.echo "streetAddress: " & strStreetAddress
WScript.echo "l: " & strLocalityName
WScript.echo "st: " & strStreetName
WScript.echo "postalCode: " & strPostalCode
WScript.echo "c: " & strCountryName

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning Group Policy Information for an OU

Description
Returns the values found on the Group Policy page in Active Directory Users and Computers for the Sales OU.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objContainer = GetObject _
  ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

strGpLink = objContainer.Get("gPLink")
intGpOptions = objContainer.Get("gPOptions")

If strGpLink <> " " Then
  arrGpLinkItems = Split(strGpLink,"]")
  For i = UBound(arrGPLinkItems) to LBound(arrGpLinkItems) + 1 Step -1
    arrGPLink = Split(arrGpLinkItems(i-1),";")
    strDNGPLink = Mid(arrGPLink(0),9)
    WScript.Echo GetGPOName
    Select Case arrGPLink(1)
      Case 0
        WScript.Echo "No Override is cleared and the GPO is enabled."
      Case 1
        WScript.Echo "No Override is cleared and the GPO is disabled."
      Case 2
        WScript.Echo "No Override is checked and the GPO is enabled."
      Case 3
        WScript.Echo "No Override is checked and the GPO is disabled."
    End Select
  Next
  WScript.Echo VbCrLf
End If

If intGpOptions = 1 Then
  WScript.Echo "Block Policy Inheritance is checked."
Else
  WScript.Echo "Block Policy Inheritance is not checked."
End If

Function GetGPOName
  Set objConnection = CreateObject("ADODB.Connection")
  objConnection.Open "Provider=ADsDSOObject;"

  Set objCommand = CreateObject("ADODB.Command")
  objCommand.ActiveConnection = objConnection

  objCommand.CommandText = _
  "<LDAP://cn=Policies,cn=System,dc=NA,dc=fabrikam,dc=com>;;" & _
  "distinguishedName,displayName;onelevel"
  Set objRecordSet = objCommand.Execute

  While Not objRecordSet.EOF
    If objRecordSet.Fields("distinguishedName") = strDNGPLink Then
      GetGPOName = objRecordSet.Fields("displayName")
      objConnection.Close
      Exit Function
    End If
    objRecordSet.MoveNext
  Wend
  objConnection.Close
End Function

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning Managed By Information for an OU

Description
Returns information about the account assigned as managed of the Sales OU in Active Directory.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next

Set objContainer = GetObject _
   ("LDAP://ou=Sales,dc=NA,dc=fabrikam,dc=com")

strManagedBy = objContainer.Get("managedBy")

If IsEmpty(strManagedBy) = TRUE Then
    WScript.Echo "No user account is assigned to manage " & _
    "this OU."
Else
    Set objUser = GetObject("LDAP://" & strManagedBy)
    strPhysicalDeliveryOfficeName = _
      objUser.Get("physicalDeliveryOfficeName")
    strStreetAddress = objUser.Get("streetAddress")
    strLocalityName = objUser.Get("l")
    strStateProvince = objUser.Get("st")
    strCountryName = objUser.Get("c")
    strTelephoneNumber = objUser.Get("telephoneNumber")
    strFacsimileTelephoneNumber = _
      objUser.Get("facsimileTelephoneNumber")

    WScript.Echo "managedBy: " & strManagedBy
    WScript.echo "physicalDeliveryOfficeName: " & _
      strPhysicalDeliveryOfficeName
    WScript.echo "streetAddress: " & strStreetAddress
    WScript.echo "l: " & strLocalityName
    WScript.echo "state/province: " & strStateProvince
    WScript.echo "c: " & strCountryName
    WScript.echo "telephoneNumber: " & strTelephoneNumber
    WScript.echo "facsimileTelephoneNumber: " & _
      strFacsimileTelephoneNumber
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Returning the Properties of an OU Object

Description
Returns information found on the Object page in Active Directory Users and Computers for the Sales OU.

For more information about reading attribute values using ADSI, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objContainer = GetObject _
   ("GC://ou=Sales,dc=NA,dc=fabrikam,dc=com")

strWhenCreated = objContainer.Get("whenCreated")
strWhenChanged = objContainer.Get("whenChanged")

Set objUSNChanged = objContainer.Get("uSNChanged")
dblUSNChanged = _
    Abs(objUSNChanged.HighPart * 2^32 + objUSNChanged.LowPart)

Set objUSNCreated = objContainer.Get("uSNCreated")
dblUSNCreated = _
    Abs(objUSNCreated.HighPart * 2^32 + objUSNCreated.LowPart)

objContainer.GetInfoEx Array("canonicalName"), 0
arrCanonicalName = objContainer.GetEx("canonicalName")

WScript.echo "CanonicalName of object:"
For Each strValue in arrCanonicalName
    WScript.echo vbTab & strValue
Next
WScript.Echo vbCr

WScript.Echo "Object class: " & objContainer.Class & vbCrLf
WScript.echo "whenCreated: " & strWhenCreated & " (Created - GMT)"
WScript.echo "whenChanged: " & strWhenChanged & " (Modified - GMT)"
WScript.Echo VbCrLf
WScript.Echo "uSNChanged: " & dblUSNChanged & " (USN Current)"
WScript.Echo "uSNCreated: " & dblUSNCreated & " (USN Original)"

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Clearing Terminal Services Properties for a User Account

Description
Clears the Terminal Services userParameters attribute for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
   ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.PutEx ADS_PROPERTY_CLEAR, "userParameters", 0
objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Environment Properties for a User Account

Description
Configures the Terminal Services environment properties for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const Enabled = 1
Const Disabled = 0
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.ConnectClientDrivesAtLogon = Enabled
objUser.ConnectClientPrintersAtLogon = Enabled
objUser.DefaultToMainPrinter = Enabled
objUser.TerminalServicesInitialProgram = "cmd"
objUser.TerminalServicesWorkDirectory = "c:\temp"

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Profile Properties for a User Account

Description
Configures Terminal Services profile attributes for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const Enabled = 1
Const Disabled = 0
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.TerminalServicesProfilePath = ""
objUser.TerminalServicesHomeDirectory = ""
objUser.TerminalServicesHomeDrive = ""
objUser.AllowLogon = Enabled

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Configuring Terminal Services Session Properties for a User Account

Description
Configures Terminal Services session attributes for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const Enabled = 1
Const Disabled = 0
Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

objUser.MaxDisconnectionTime = 2880
objUser.MaxConnectionTime = 1440
objUser.MaxIdleTime = 180
objUser.BrokenConnectionAction = Enabled
objUser.ReconnectionAction = Enabled

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enabling Remote Control Settings for a User Account

Description
Configures the EnableRemoteControl attribute for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const Disable = 0
Const EnableInputNotify = 1
Const EnableInputNoNotify = 2
Const EnableNoInputNotify = 3
Const EnableNoInputNoNotify = 4

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objUser.EnableRemoteControl = EnableNoInputNoNotify

objUser.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Terminal Services Environment Properties for a User Account

Description
Returns Terminal Services environment properties for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intConnectClientDrivesAtLogon = objUser.ConnectClientDrivesAtLogon
intConnectClientPrintersAtLogon = objUser.ConnectClientPrintersAtLogon
intDefaultToMainPrinter = objUser.DefaultToMainPrinter
strTerminalServicesInitialProgram = objUser.TerminalServicesInitialProgram
strTerminalServicesWorkDirectory = objUser.TerminalServicesWorkDirectory

WScript.echo "ConnectClientDrivesAtLogon: " & intConnectClientDrivesAtLogon
WScript.echo "ConnectClientPrintersAtLogon: " & _
    intConnectClientPrintersAtLogon
WScript.echo "DefaultToMainPrinter: " & intDefaultToMainPrinter
WScript.echo "TerminalServicesInitialProgram: " & _
    strTerminalServicesInitialProgram
WScript.echo "TerminalServicesWorkDirectory: " & _
    strTerminalServicesWorkDirectory

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Terminal Services Profile Properties

Description
Returns Terminal Services profile information for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2000 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strTerminalServicesProfilePath = objUser.TerminalServicesProfilePath
strTerminalServicesHomeDirectory = objUser.TerminalServicesHomeDirectory
strTerminalServicesHomeDrive = objUser.TerminalServicesHomeDrive
intAllowLogon = objUser.AllowLogon

WScript.echo "TerminalServicesProfilePath : " & strTerminalServicesProfilePath
WScript.echo "TerminalServicesHomeDirectory: " & _
    strTerminalServicesHomeDirectory
WScript.echo "TerminalServicesHomeDrive: " & strTerminalServicesHomeDrive
WScript.echo "AllowLogon: " & intAllowLogon

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Terminal Services Properties for a User

Description
Retrieve a user's Terminal Services Profile settings using the ADSI Extension for Terminal Services User Configuration. Requires Windows Server 2003.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objUser = GetObject("LDAP://cn=youngrob,ou=r&d,dc=fabrikam,dc=com")

WScript.Echo objUser.Name & " Terminal Services Profile Settings"
WScript.Echo "--------------------------------------------------"

'**********************************************************************
'* Terminal Services Profile tab
'**********************************************************************
WScript.Echo "Allow Logon: " & objUser.AllowLogon

WScript.Echo "Terminal Services Home Directory: " & _
    objUser.TerminalServicesHomeDirectory

WScript.Echo "Terminal Services Home Drive: " & _
    objUser.TerminalServicesHomeDrive

WScript.Echo "Terminal Services Profile Path: " & _
    objUser.TerminalServicesProfilePath

'**********************************************************************
'* Remote control tab
'**********************************************************************
WScript.Echo "Enable Remote Control: " & objUser.EnableRemoteControl

'**********************************************************************
'* Sessions tab
'**********************************************************************
WScript.Echo "Broken Connection Action: " & objUser.BrokenConnectionAction
WScript.Echo "Max Connection Time: " & objUser.MaxConnectionTime
WScript.Echo "Max Disconnection Time: " & objUser.MaxDisconnectionTime
WScript.Echo "Max Idle Time: " & objUser.MaxIdleTime
WScript.Echo "Reconnection Action: " & objUser.ReconnectionAction

'**********************************************************************
'* Environment tab
'**********************************************************************
WScript.Echo "Connect Client Drives At Logon: " & _
    objUser.ConnectClientDrivesAtLogon

WScript.Echo "Connect Client Printers At Logon: " & _
    objUser.ConnectClientPrintersAtLogon

WScript.Echo "Default To Main Printer: " & _
    objUser.DefaultToMainPrinter

WScript.Echo "Terminal Services Initial Program: " & _
    objUser.TerminalServicesInitialProgram

WScript.Echo "Terminal Services Work Directory: " & _
    objUser.TerminalServicesWorkDirectory

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Terminal Services Remote Control Properties for a User Account

Description
Retrieves Terminal Services Remote Control attribute values for the MyerKen user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Const Disable = 0
Const EnableInputNotify = 1
Const EnableInputNoNotify = 2
Const EnableNoInputNotify = 3
Const EnableNoInputNoNotify = 4

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intEnableRemoteControl  = objUser.EnableRemoteControl

Select Case intEnableRemoteControl
    Case Disable  WScript.Echo "Remote control disabled"
    Case EnableInputNotify
        WScript.Echo "Remote control enabled"
        WScript.Echo "User permission required"
        WScript.Echo "Interact with the session"
    Case EnableInputNoNotify
        WScript.Echo "Remote control enabled"
        WScript.Echo "User permission not required"
        WScript.Echo "Interact with the session"
    Case EnableNoInputNotify
        WScript.Echo "Remote control enabled"
        WScript.Echo "User permission required"
        WScript.Echo "View the session"
    Case EnableNoInputNoNotify
        WScript.Echo "Remote control enabled"
        WScript.Echo "User permission not required"
        WScript.Echo "View the session"
End Select

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Terminal Services Session Properties

Description
Retrieves Terminal Services session properties for the MyerKen Active Directory user account.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intMaxDisconnectionTime = objUser.MaxDisconnectionTime
intMaxConnectionTime = objUser.MaxConnectionTime
intMaxIdleTime = objUser.MaxIdleTime
intBrokenConnectionAction = objUser.BrokenConnectionAction
intReconnectionAction  = objUser.ReconnectionAction

WScript.echo "Maximum Disconnection Time : " & intMaxDisconnectionTime
WScript.echo "Maximum Connection Time: " & intMaxConnectionTime
WScript.echo "Maximum Idle Time: " & intMaxIdleTime
WScript.echo "Broken Connection Action: " & intBrokenConnectionAction
WScript.echo "Reconnection Action : " & intReconnectionAction

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Floppy Disk Drive Properties

Description
Returns information about all the floppy disk drives installed on a computer.

For more information about the Win32_FloppyDrive class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_FloppyDrive")
For Each objItem in colItems
    For Each strCapability in objItem.Capabilities
        Wscript.Echo "Capability: " & strCapability
    Next
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Device ID: " & objItem.DeviceID
    Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Wscript.Echo "PNP Device ID: " & objItem.PNPDeviceID
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Computer Health

Description
Uses cooked performance counters and the SWbemRefresher object to monitor three performance counters on a computer. Issues an alert if any of the three counters exceed the specified threshold.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objMemory = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
Set objDiskQueue = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk"). _
        objectSet
Set objQueueLength = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfNet_ServerWorkQueues"). _
        objectSet
objRefresher.Refresh
intHealthStatus = 0
Do
    For each intAvailableBytes in objMemory
        If intAvailableBytes.AvailableMBytes < 4 Then
            intHealthStatus = intHealthStatus + 1
        End If
    Next
    For each intQueueLength in objDiskQueue
        If intQueueLength.CurrentDiskQueueLength > 2 Then
            intHealthStatus = intHealthStatus + 1
        End If
    Next
    For each intServerQueueLength in objQueueLength
        If intServerQueueLength.QueueLength > 4 Then
            intHealthStatus = intHealthStatus + 1
        End If
    Next
    If intHealthStatus > 0 Then
        Wscript.Echo "Unhealthy."
    Else
        Wscript.Echo "Healthy."
    End If
    intHealthStatus = 0
    Wscript.Sleep 10000
    objRefresher.Refresh
Loop

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Monitoring Computer Uptime

Description
Calculates the number of days since a computer was last booted.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | No
Windows NT 4.0 | No
Windows 98 | No

Script Code

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
    dtmConvertedDate.Value = objOS.LastBootUpTime
    dtmLastBootUpTime = dtmConvertedDate.GetVarDate
    dtmSystemUptime = DateDiff("d", dtmLastBootUpTime, Now)
    Wscript.Echo dtmSystemUptime
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Enumerating Network Connections

Description
Retrieves information about all active network connections found on a computer.

For more information about the Win32_NetworkConnection class used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkConnection")
For Each objItem in colItems
    Wscript.Echo "Access Mask: " & objItem.AccessMask
    Wscript.Echo "Caption: " & objItem.Caption
    Wscript.Echo "Connection State: " & objItem.ConnectionState
    Wscript.Echo "Connection Type: " & objItem.ConnectionType
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Display Type: " & objItem.DisplayType
    Wscript.Echo "Local Name: " & objItem.LocalName
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "Persistent: " & objItem.Persistent
    Wscript.Echo "Provider Name: " & objItem.ProviderName
    Wscript.Echo "Remote Name: " & objItem.RemoteName
    Wscript.Echo "Remote Path: " & objItem.RemotePath
    Wscript.Echo "Resource Type: " & objItem.ResourceType
    Wscript.Echo "User Name: " & objItem.UserName
    Wscript.Echo
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Renewing a DHCP Lease

Description
Renews the DHCP lease on a computer.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with WMI installed
Windows 98 | Yes, with WMI installed

Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where DHCPEnabled = True")

For Each objNetAdapter in colNetAdapters
    errRenew = objNetAdapter.RenewDHCPLease
    If errRenew = 0 Then
        Wscript.Echo "DHCP lease renewed."
    Else
        Wscript.Echo "DHCP lease could not be renewed."
    End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Creating a Host Address (A) DNS Record

Description
Creates a host address (A) record on a DNS server.

For more information about the CreateInstanceFromPropertyData method used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | No (however, scripts can be run on a Windows XP computer against a remote DNS server)
Windows 2000 | Yes, with the DNS WMI provider installed
Windows NT 4.0 | No
Windows 98 | No

Script Code

strDNSServer = "atl-dc-03.fabrikam.com"
strContainer = "fabrikam.com"
strOwner = "workstation5.fabrikam.com"
intRecordClass = 1
intTTL = 600
strIPAddress = "192.168.1.100"

strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:\\" & strComputer & "\root\MicrosoftDNS")
Set objItem = objWMIService.Get("MicrosoftDNS_AType")
errResult = objItem.CreateInstanceFromPropertyData _
    (strDNSServer, strContainer, strOwner, intRecordClass, intTTL, strIPAddress)

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Displaying Attributes that are Single Valued and Attributes that are Multi-Valued

Description
Uses a search operation to read the isSingleValued attribute of all schema objects that are attributes. The first list displays all attributes whose isSingleValued attribute is true and the second list displays all attributes whose isSingleValued attribute is false.

Note Consider piping this output to a file:

cscript scriptname.vbs > filename.txt

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
    "<LDAP://CN=Schema,CN=Configuration,DC=fabrikam,DC=com>;" & _
        "(&(objectClass=attributeSchema)(lDAPDisplayName=*));" & _
            "lDAPDisplayName,isSingleValued;onelevel"

Set objRecordSet = objCommand.Execute

WScript.Echo "Single-valued attributes "  & _
    "(by lDAPDisplayName):" & VbCrLf
While Not objRecordSet.EOF
    If objRecordset.Fields("isSingleValued") = TRUE Then
        Wscript.echo objRecordset.Fields("lDAPDisplayName")
    End If
    objRecordSet.MoveNext
Wend

objRecordSet.MoveFirst

WScript.Echo VbCrLf & "Multi-valued attributes " & _
    "(by lDAPDisplayName):" & VbCrLf
While Not objRecordSet.EOF
    If objRecordset.Fields("isSingleValued") = FALSE Then
        Wscript.echo objRecordset.Fields("lDAPDisplayName")
    End If
    objRecordSet.MoveNext
Wend

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Data from a Text File

Description
Demonstration script that reads in a text file and then echoes the contents of that file.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes
Windows 98 | Yes, with Windows Script Host installed

Script Code

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\ping_response.txt", ForReading)
strResponses = objTextFile.ReadAll
Wscript.Echo strResponses
objTextFile.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Removing a User from an Active Directory Security Group

Description
Removes the MyerKen user account from the Active Directory security group Atl-Users.

For more information about deleing objects from Active Directory, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_DELETE = 4

Set objGroup = GetObject _
    ("LDAP://cn=Atl-Users,cn=Users,dc=NA,dc=fabrikam,dc=com")
objGroup.PutEx ADS_PROPERTY_DELETE, _
    "member", Array("cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
objGroup.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving the Active Directory Groups a User Belongs To

Description
Returns a list of all the Active Directory security groups (including the primary group) that include the MyerKen user account as a member.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

intPrimaryGroupID = objUser.Get("primaryGroupID")
arrMemberOf = objUser.GetEx("memberOf")

If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "The memberOf attribute is not set."
Else
    WScript.Echo "Member of: "
    For each Group in arrMemberOf
        WScript.Echo Group
    Next
End If

Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
    "<LDAP://dc=NA,dc=fabrikam,dc=com>;(objectCategory=Group);" & _
        "distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
    If objRecordset.Fields("primaryGroupToken") = intPrimaryGroupID Then
        WScript.Echo "Primary group:"
        WScript.Echo objRecordset.Fields("distinguishedName") & _
            " (primaryGroupID: " & intPrimaryGroupID & ")"
    End If
    objRecordset.MoveNext
Wend

objConnection.Close

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Copying an Active Directory User Account

Description
Retrieves the attributes of an existing user account object and copies the attributes to a new user account object that the script creates.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Const ADS_PROPERTY_UPDATE = 2
Set objOU = GetObject("LDAP://OU=HR,dc=NA,dc=fabrikam,dc=com")
Set objUserCopy = objOU.Create("user", "cn=BarrAdam")
objUserCopy.Put "sAMAccountName", "barradam"
objUserCopy.SetInfo

Set objUserTemplate = _
    GetObject("LDAP://cn=HuffArlene,OU=HR,dc=NA,dc=fabrikam,dc=com")
arrSVAttributes = Array("description", "department", _
    "company", "wWWHomePage")

arrMVAttributes = Array("url", "otherTelephone")

For Each strAttrib in arrSVAttributes
    strValue = objUserTemplate.Get(strAttrib)
    objUserCopy.Put strAttrib, strValue
Next

For Each strAttrib in arrMVAttributes
    arrValue = objUserTemplate.GetEx(strAttrib)
    objUserCopy.PutEx ADS_PROPERTY_UPDATE, strAttrib, arrValue
Next

objUserCopy.SetInfo

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading Dial-In Properties for a User Account

Description
Returns Dial-In attribute values for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND  = &h8000500D

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

blnMsNPAllowDialin = objUser.Get("msNPAllowDialin")
WScript.Echo "Remote Access Permission (Dial-in or VPN)"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "Control access through Remote Access Policy"
    Err.Clear
Else
    If blnMsNPAllowDialin = True Then
        WScript.Echo "Allow access (msNPAllowDialin)"
    Else
        WScript.Echo "Deny access (msNPAllowDialin)"
    End If
End If
WScript.Echo VbCr

arrMsNPSavedCallingStationID = objUser.GetEx("msNPSavedCallingStationID")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No Caller-ID specified."
    Err.Clear
Else
    WScript.Echo "Verify Caller ID (msNPSavedCallingStationID): "
    For Each strValue in arrMsNPSavedCallingStationID
        WScript.echo strValue
    Next

    objUser.GetEx "msNPCallingStationID"
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Calling station ID(s) specified but not assigned."
        Err.Clear
    Else
        WScript.echo "Calling station ID(s) assigned."
  End If

End If
WScript.Echo VbCr

intMsRADIUSServiceType = objUser.Get("msRADIUSServiceType")
WScript.Echo "Callback Options"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No Callback"
    Err.Clear
Else
    strMsRADIUSCallbackNumber = objUser.Get("msRADIUSCallbackNumber")
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Set by caller (Routing and Remote Access Service only)"
        Err.Clear

    strMsRASSavedCallbackNumber = objUser.Get("msRASSavedCallbackNumber")
    If Err.Number <> E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Unused value of " & strMsRASSavedCallbackNumber & _
            " appears in the Always Callback to field."
    Else
        Err.Clear
    End If
    Else
        WScript.Echo "Always Callback to: " & _
            strMsRADIUSCallbackNumber & " (msRADIUSCallbackNumber)"
    End If
End If
WScript.Echo VbCr

intMsRASSavedFramedIPAddress = objUser.Get("msRASSavedFramedIPAddress")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No static IP address assigned."
    Err.Clear
Else
    hexMsRASSavedFramedIPAddress = Hex(intMsRASSavedFramedIPAddress)
    WScript.StdOut.Write "IP Address in Hex (msRASSavedFramedIPAddress): "
    For i = 1 to 8 Step 2
        If i < 6 Then
            WScript.StdOut.Write Mid(hexMsRASSavedFramedIPAddress,i,2) & "."
        Else
            WScript.Echo Mid(hexMsRASSavedFramedIPAddress,i,2)
        End If
    Next

    objUser.Get "msRADIUSFramedIPAddress"
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Static IP address specified but not assigned."
        Err.Clear
    Else
        WScript.Echo "Static IP Address assigned."
    End If

End If
WScript.Echo VbCr

arrMsRASSavedFramedRoute = objUser.GetEx("msRASSavedFramedRoute")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
    WScript.Echo "No static Routes specified."
    Err.Clear
Else
    WScript.echo "Static Routes (msRASSavedFramedRoute):"
    WScript.Echo vbTab & "CIDR 0.0.0.0 Metric"
    For Each strValue in arrMsRASSavedFramedRoute
        WScript.echo vbTab & strValue
    Next

    objUser.GetEx "msRADIUSFramedRoute"
    If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
        WScript.Echo "Static Routes specified but not assigned."
        Err.Clear
    Else
        WScript.echo "Static Routes assigned."
    End If
End If

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Reading userAccountControl Values for an Active Directory User Account

Description
Reads values from the userAccountControl of the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objHash = CreateObject("Scripting.Dictionary")

objHash.Add "ADS_UF_SMARTCARD_REQUIRED", &h40000
objHash.Add "ADS_UF_TRUSTED_FOR_DELEGATION", &h80000
objHash.Add "ADS_UF_NOT_DELEGATED", &h100000
objHash.Add "ADS_UF_USE_DES_KEY_ONLY", &h200000
objHash.Add "ADS_UF_DONT_REQUIRE_PREAUTH", &h400000

Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")
intUAC = objUser.Get("userAccountControl")

If objUser.IsAccountLocked = True Then
    WScript.Echo "ADS_UF_LOCKOUT is enabled"
Else
    WScript.Echo "ADS_UF_LOCKOUT is disabled"
End If
Wscript.Echo VBCRLF

For Each Key In objHash.Keys
    If objHash(Key) And intUAC Then
        WScript.Echo Key & " is enabled"
    Else
        WScript.Echo Key & " is disabled"
  End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving Telephone Settings for a User Account

Description
Displays all the telephone attribute values for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
  ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strHomePhone = objUser.Get("homePhone")
strPager = objUser.Get("pager")
strMobile = objUser.Get("mobile")
strIpPhone = objUser.Get("ipPhone")
strInfo = objUser.Get("info")
strFacsimileTelephoneNumber = objUser.Get("facsimileTelephoneNumber")

arrOtherHomePhone = objUser.GetEx("otherHomePhone")
arrOtherPager = objUser.GetEx("otherPager")
arrOtherMobile = objUser.GetEx("otherMobile")
arrOtherIpPhone = objUser.GetEx("otherIpPhone")
arrOtherFacsimileTelephoneNumber = _
  objUser.GetEx("otherFacsimileTelephoneNumber")

WScript.echo "homePhone: " & strHomePhone
WScript.echo "pager: " & strPager
WScript.echo "mobile: " & strMobile
WScript.echo "ipPhone: " & strIpPhone
WScript.echo "info: " & strInfo
WScript.echo "facsimileTelephoneNumber: " & strFacsimileTelephoneNumber

WScript.echo "otherHomePhone:"
For Each strValue in arrOtherHomePhone
    WScript.echo strValue
Next
WScript.echo "otherPager:"
For Each strValue in arrOtherPager
    WScript.echo strValue
Next
WScript.echo "otherMobile:"
For Each strValue in arrOtherMobile
    WScript.echo strValue
Next
WScript.echo "otherIpPhone:"
For Each strValue in arrOtherIpPhone
    WScript.echo strValue
Next
WScript.echo "otherFacsimileTelephoneNumber:"
For Each strValue in arrOtherFacsimileTelephoneNumber
    WScript.echo strValue
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving userAccountControl Attributes

Description
Uses the userAccountControl to identify whether or not a user account is locked, and whether or not that account is enabled.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

Set objHash = CreateObject("Scripting.Dictionary")

objHash.Add "ADS_UF_SMARTCARD_REQUIRED", &h40000
objHash.Add "ADS_UF_TRUSTED_FOR_DELEGATION", &h80000
objHash.Add "ADS_UF_NOT_DELEGATED", &h100000
objHash.Add "ADS_UF_USE_DES_KEY_ONLY", &h200000
objHash.Add "ADS_UF_DONT_REQUIRE_PREAUTH", &h400000

Set objUser = GetObject _
  ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")
objUser.GetInfoEx Array("userAccountControl"), 0

intUAC = objUser.Get("userAccountControl")

If objUser.IsAccountLocked = True Then
  WScript.echo "ADS_UF_LOCKOUT is enabled"
Else
  WScript.echo "ADS_UF_LOCKOUT is disabled"
End If

For Each Key In objHash.Keys
  If objHash(Key) And intUAC Then
    WScript.Echo Key & " is enabled"
  Else
    WScript.Echo Key & " is disabled"
  End If
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Retrieving User Profile Information for a User Account

Description
Returns user profile information for the MyerKen Active Directory user account.

For more information about the user account attributes used in this script, click here.

Supported Platforms

Windows Server 2003 | Yes
Windows XP | Yes
Windows 2000 | Yes
Windows NT 4.0 | Yes, with Active Directory Client Extensions installed
Windows 98 | Yes, with Active Directory Client Extensions installed

Script Code

On Error Resume Next
Set objUser = GetObject _
    ("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com")

strProfilePath = objUser.Get("profilePath")
strScriptPath = objUser.Get("scriptPath")
strHomeDirectory = objUser.Get("homeDirectory")
strHomeDrive = objUser.Get("homeDrive")

WScript.echo "Profile Path: " & strProfilePath
WScript.echo "Script Path: " & strScriptPath
WScript.echo "Home Directory: " & strHomeDirectory
WScript.echo "Home Drive: " & strHomeDrive

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.


Listing Local User Account Information Using WMI

Description
Uses WMI to return information about all the local user accounts on a computer.

For more information about the Win32_Account class used in this script, click here.

Supported Platforms

Windows XP | Yes
Windows .NET Server | Yes
Windows 2000 | Yes
Windows NT 4.0 | No
Windows 98 | No

Script Code

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery _
    ("Select * from Win32_Account Where LocalAccount = True")
For Each objItem in colItems
    Wscript.Echo "Description: " & objItem.Description
    Wscript.Echo "Domain: " & objItem.Domain
    Wscript.Echo "Install Date: " & objItem.InstallDate
    Wscript.Echo "Local Account: " & objItem.LocalAccount
    Wscript.Echo "Name: " & objItem.Name
    Wscript.Echo "SID: " & objItem.SID
    Wscript.Echo "SID Type: " & objItem.SIDType
    Wscript.Echo "Status: " & objItem.Status
Next

For online peer support, join the microsoft.public.windows.server.scripting community on the msnews.microsoft.com news server. To provide feedback or report bugs in sample scripts or the Scripting Guide, please contact Microsoft TechNet.

Disclaimer

This sample script is not supported under any Microsoft standard support program or service. The sample script is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.