次の方法で共有


Item Property (Windows Script Host)

Exposes a specified item from a collection.

                      Object.Item(natIndex) 

Arguments

  • Object
    The result of the EnumNetworkDrive or EnumPrinterConnections methods, or the object returned by the Environment or SpecialFolders properties.

  • natIndex
    Item to retrieve.

Remarks

Item is the default property for each collection. For EnumNetworkDrive and EnumPrinterConnections collections, index is an integer; for the Environment and SpecialFolders collections, index is a string.

WshShell.SpecialFolders.Item (strFolderName) returns "Empty" in VBScript and "undefined" in JScript if the requested folder (strFolderName) is not available.

The following table lists special folders along with the version of Windows that supports them.

Applies To:

WshArguments Object| WshEnvironment Object| WshSpecialFolders Object

Folder

Windows version

AllUsersDesktop

Windows 2000

AllUsersStartMenu

Windows 2000

AllUsersPrograms

Windows 2000

AllUsersStartup

Windows 2000

Desktop

Windows 98/ME, Windows 2000

Favorites

Windows 98/ME, Windows 2000

Fonts

Windows 98/ME, Windows 2000

My Documents

Windows 98/ME, Windows 2000

NetHood

Windows 98/ME, Windows 2000

PrintHood

Windows 98/ME, Windows 2000

Programs

Windows 98/ME, Windows 2000

Recent

Windows 98/ME, Windows 2000

SendTo

Windows 98/ME, Windows 2000

Start Menu

Windows 98/ME, Windows 2000

StartupB

Windows 2000

Templates

Windows 2000

Example

The following code displays network mapping information for the drives and printers.

<package>
   <job id="vbs">
      <script language="VBScript">
         Set WshNetwork = WScript.CreateObject("WScript.Network")
         Set oDrives = WshNetwork.EnumNetworkDrives
         Set oPrinters = WshNetwork.EnumPrinterConnections
         WScript.Echo "Network drive mappings:"
         For i = 0 to oDrives.Count - 1 Step 2
            WScript.Echo "Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1)
         Next
         WScript.Echo 
         WScript.Echo "Network printer mappings:"
         For i = 0 to oPrinters.Count - 1 Step 2
            WScript.Echo "Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1)
         Next
      </script>
   </job>

   <job id="js">
      <script language="JScript">
         var WshNetwork = WScript.CreateObject("WScript.Network");
         var oDrives = WshNetwork.EnumNetworkDrives();
         var oPrinters = WshNetwork.EnumPrinterConnections();
         WScript.Echo();
         WScript.Echo("Network drive mappings:");
         for(i = 0; i < oDrives.length; i += 2){
            WScript.Echo("Drive " + oDrives.Item(i) + " = " + oDrives.Item(i + 1));
         }
         WScript.Echo();
         WScript.Echo("Network printer mappings:");
         for(i = 0; i < oPrinters.length; i += 2){
            WScript.Echo("Port " + oPrinters.Item(i) + " = " + oPrinters.Item(i + 1));
         }
      </script>
   </job>
</package>

See Also

Reference

EnumNetworkDrives Method

EnumPrinterConnections Method

Environment Property

SpecialFolders Property