List Items in the My Computer Folder using VBScript (WSH)


The following VBScript runs at WSH (Window Scripting Host). It is used to list the items in “My Computer” folder. The Object “Shell.Application” is required for this to work.

1
2
3
4
5
6
7
8
9
10
11
Const MY_COMPUTER = &H11&
 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
WScript.Echo objFolderItem.Path
 
Set colItems = objFolder.Items
For Each objItem in colItems
    WScript.Echo objItem.Name
Next
Const MY_COMPUTER = &H11&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
WScript.Echo objFolderItem.Path

Set colItems = objFolder.Items
For Each objItem in colItems
    WScript.Echo objItem.Name
Next

The output is something like:

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

::{20D04FE0-3AEA-1069-A2D8-08002B30309D}
OS (C:)
Data (D:)
Temp (E:)
DVD RW Drive (F:)
CD Drive (H:)

***** script completed - exit code: 0 *****

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
161 words
Last Post: The Halting Problem
Next Post: VBScript Malware Demo using FileSystemObject

The Permanent URL is: List Items in the My Computer Folder using VBScript (WSH)

Leave a Reply