Scripting QTP - CH11 - Shell32
Scripting QTP - CH11 - Shell32
Shell32.FolderItem.GetFolder Property..................................................................... 25
Shell32.FolderItem.GetLink Property........................................................................ 26
Shell32.FolderItem.IsBrowsable Property ................................................................. 26
Shell32.FolderItem.IsFileSystem Property ................................................................ 27
Shell32.FolderItem.IsFolder Property........................................................................ 27
Shell32.FolderItem.IsLink Property .......................................................................... 27
Shell32.FolderItem.ModifyDate Property.................................................................. 27
Shell32.FolderItem.Name Property ........................................................................... 27
Shell32.FolderItem.Parent Property........................................................................... 28
Shell32.FolderItem.Path Property.............................................................................. 28
Shell32.FolderItem.Size Property.............................................................................. 28
Shell32.FolderItem.Type Property ............................................................................ 28
Shell32.FolderItem.InvokeVerb Method ................................................................... 29
Shell32.FolderItem.Verbs Method ............................................................................ 30
SHELL32.FOLDERITEMS, SHELL.FOLDERITEMS2, SHELL.FOLDERITEMS3 OBJECTS.......... 32
Shell32.FolderItems.Count Property ......................................................................... 32
Shell32.FolderItems.Item Method ............................................................................. 32
Shell32.FolderItems2.InvokeVerbEx Method............................................................ 33
Shell32.FolderItems3.Verbs Property........................................................................ 33
Shell32.FolderItems3.Filter Method .......................................................................... 33
SHELL32.FOLDERITEMVERB OBJECT .............................................................................. 35
Shell32.FolderItemVerb.Name Property.................................................................... 35
Shell32.FolderItemVerb.DoIt Method ....................................................................... 36
SHELL32.FOLDERITEMVERBS OBJECT ............................................................................ 36
Shell32.FolderItemVerbs.Count Property.................................................................. 37
Shell32.FolderItemVerbs.Item Method ..................................................................... 37
SHELL32.ISHELLDISPATCH INTERFACE AND SHELL OBJECT ............................................ 37
Shell32.Shell.Parent Property.................................................................................... 37
Shell32.AddToRecent Method .................................................................................. 37
Shell32.CanStartStopService Method........................................................................ 38
Shell32.CascadeWindows Method ............................................................................ 38
Shell32.ControlPanelItem Method ............................................................................ 39
Shell32.EjectPC Method ........................................................................................... 40
Shell32.Explore Method ........................................................................................... 40
Shell32.ExplorerPolicy Method ................................................................................ 41
Shell32.FileRun Method ........................................................................................... 42
Shell32.FindComputer Method ................................................................................. 42
Shell32.FindFiles Method ......................................................................................... 43
Shell32.FindPrinter Method ...................................................................................... 44
Shell32.GetSetting Method ....................................................................................... 45
Shell32.GetSystemInformation Method .................................................................... 45
Shell32.Help Method ................................................................................................ 46
Shell32.IsRestricted Method ..................................................................................... 47
Shell32.IsServiceRunning Method ............................................................................ 48
Shell32.MinimizeAll Method.................................................................................... 48
Shell32.NameSpace Method ..................................................................................... 49
Shell32.Open Method ............................................................................................... 49
Shell32.RefreshMenu Method................................................................................... 50
Shell32.ServiceStop Method ..................................................................................... 50
Shell32.ShellExecute Method ................................................................................... 50
Shell32.SetTime Method........................................................................................... 51
DiskQuotaControl The NTFS file system allows an administrator to manage disk usage on a
shared volume by allocating a specified amount of disk space, or quota
Disk quotas are an integral part of the NTFS file system. When a file or a folder is
created on a volume formatted with NTFS, that item is assigned an owner (typically
the user who created the item). NTFS obtains the user ID of the file owner and
stores that information in the file or folder's Standard Information attribute. This
attribute tallies all the disk space allocated to the file or folder. NTFS then locates
the quota entry for that user and determines whether the new allocation of disk
space causes the user to exceed the assigned quota. If it does, NTFS then takes
the appropriate steps, which can include logging an entry in the System event log
or preventing the user from creating the file or folder. As the file or folder changes
size, NTFS updates the quota control entry to reflect the total disk space used by
the user.
Disk quotas are not configured on a computer-wide basis, but are instead tied to
individual NTFS volumes. Each drive has separate quota settings, and the actions
you take on one volume do not affect the other volumes.
When managing disk quotas on a computer, the actions you take on one volume do
not affect the other volumes in any way. If you allocate User A 50 MB of disk space
on drive C, this does not also give User A 50 MB of disk space on drives D and E. If
you disable disk quotas on drive D, quotas remain enabled on drives C and E.
Microsoft.DIDiskQuotaUser Object
Each user on the volume that is managed by the DiskQuotaControl object has a
DIDiskQuotaUser object associated with it. This object allows a client to manage
an individual user's settings. There are several ways to obtain a user's
DIDiskQuotaUser object:
The DIDiskQuotaUser objects for all users with quotas on the volume are
exposed as a collection and can be enumerated. A discussion of how to
enumerate DIDiskQuotaUser objects is found below.
When you add a new user, the AddUser method returns the user's
DIDiskQuotaUser object.
If you have the user's name, the FindUser method returns the user's
DIDiskQuotaUser object.
The DIDiskQuotaUser objects for all users with a quota on the volume are
exposed as a collection. The DiskQuotaControl object exports a standard
enumerator method that allows you to enumerate the collection of
DIDiskQuotaUser objects.
DIDiskQuotaUser.AccountContainerName Property
DIDiskQuotaUser.AccountStatus Property
DIDiskQuotaUser.DisplayName Property
This property contains the user's "friendly name." Its value is not
necessarily defined.
DIDiskQuotaUser.ID Property
The ID property retrieves an identifier (ID) that uniquely identifies the user.
Data Type
Integer value that uniquely identifies the user's DIDiskQuotaUser object
within a particular DiskQuotaControl process.
DIDiskQuotaUser.LogonName Property
DIDiskQuotaUser.QuotaLimit Property
The QuotaLimit property sets or retrieves the user's current quota limit, in
bytes.
Data Type
Integer value that specifies or receives the user's current quota limit, in bytes.
DIDiskQuotaUser.QuotaLimitText Property
The QuotaLimitText property sets or retrieves the user's current quota limit,
in bytes.
Data Type
String value that contains the user's current quota limit.
DIDiskQuotaUser.QuotaThreshold Property
DIDiskQuotaUser.QuotaThresholdText Property
DIDiskQuotaUser.QuotaUsed Property
The QuotaUsed property retrieves the user's current disk usage, in bytes.
Data Type
Integer value that is set to the amount of disk space currently in use. If NTFS
file compression is enabled, QuotaUsed reflects the amount of disk space that
the data would require in an uncompressed state.
DIDiskQuotaUser.QuotaUsedText Property
The QuotaUsedText property retrieve the user's current disk usage as a text
string.
Data Type
String value that is set to the amount of disk space currently in use. If NTFS
file compression is enabled, this property reflects the amount of disk space that
the data would require in an uncompressed state.
DIDiskQuotaUser.Invalidate Method
object.Invalidate()
Return Value
No return value.
This method clears the user information stored in the object's cache. The
next time a request is made for quota-related information, the object
retrieves the information from the NTFS volume and refreshes the cache.
DiskQuotaControl Object
The NTFS file system allows an administrator to manage disk usage on a shared
volume by allocating a specified amount of disk space, or quota limit, to each user.
The DiskQuotaControl object allows an administrator to manage a volume's disk
quota properties. For instance, you can use this object to set the default quota
limit that will be automatically assigned to all new users.
Manage the folder structure to make files easy for users to locate.
Ensure that the proper versions of specific files are installed and updated when
necessary.
Track files and folders, periodically culling files and folders that are no longer
used.
Move files and folders from one location to another as circumstances dictate.
Create and manage shared folders to provide access to files from anywhere
within the organization.
DiskQuotaControl.DefaultQuotaLimit Property
Example
Option Explicit
Dim oShell, oSpFoldersColl
Set oShell = CreateObject("WScript.Shell")
Set oSpFoldersColl = oShell.SpecialFolders
MsgBox oSpFoldersColl.Count
DiskQuotaControl.DefaultQuotaLimitText Property
DiskQuotaControl.DefaultQuotaThreshold Property
bytes.
DiskQuotaControl.DefaultQuotaThresholdText Property
DiskQuotaControl.LogQuotaLimit Property
DiskQuotaControl.LogQuotaThreshold Property
indicates whether a system event log entry will be made when a user exceeds
his or her assigned quota threshold.
Data Type
This property is set to TRUE if a system event log entry is made when the user
exceeds his or her quota warning threshold, or FALSE otherwise.
DiskQuotaControl.QuotaFileIncomplete Property
DiskQuotaControl.QuotaFileRebuilding Property
DiskQuotaControl.QuotaState Property
The QuotaState property sets or retrieves the state of the volume's disk
quotas.
Data Type
Integer, The property can be set to one of the QuotaStateConstants defined in
Table 1 on page 61
DiskQuotaControl.UserNameResolution Property
DiskQuotaControl.AddUser Method
object.AddUser (sLogonName)
Arguments
Parameter Description
Required. String value that contains the user's logon name. Use the
sLogonName UserNameResolution property to specify how the name is to be
resolved.
Return Value
No return value.
The NTFS file system automatically creates a user quota entry when a user
first writes to the volume.
Entries that are created in this way are assigned the default warning
threshold and hard quota limit values for the volume.
This method allows you to create a user quota entry before a user writes
information to the volume. It returns a DIDiskQuotaUser object that can
be used to assign a warning threshold or quota limit value that differs from
the default settings for the volume.
If the user already exists, no new entry is created. The method returns the
DIDiskQuotaUser object associated with the existing entry.
DiskQuotaControl.DeleteUser Method
Syntax
object.DeleteUser (oUser)
Arguments
Parameter Description
Required. Object expression that evaluates to the user's
oUser
DIDiskQuotaUser object.
Return Value
No return value.
This method fails if the user owns any storage on the volume. Before you
delete a user from a volume, all storage for that user must be deleted, be
moved to another volume, or have its ownership transferred to another
user.the default settings for the volume.
DiskQuotaControl.FindUser Method
The FindUser method finds a user's entry, by name, in the volume's quota file.
Syntax
object.FindUser (sLogonName)
Arguments
Parameter Description
sLogonName Required. String value that contains the user's logon name.
DiskQuotaControl.GiveUserNameResolutionPriority
Method
object.GiveUserNameResolutionPriority (oUser)
Arguments
Parameter Description
Required. Object expression that evaluates to the user's
oUser
DIDiskQuotaUser object.
Return Value
No return value.
DiskQuotaControl.Initialize Method
Arguments
Parameter Description
Required. String value that contains the fully qualified path of the volume
sPath
to be initialized.
bReadWrite Required. Boolean value that specifies how the volume is to be opened.
Return Value
No return value.
DiskQuotaControl.InvalidateSidNameCache Method
object.InvalidateSidNameCache
Return Value
No return value.
Users' names and associated security IDs are stored in a cache. You can
clear this cache by calling InvalidateSidNameCache.
If you subsequently create a new user object, the information will have to be
obtained from the domain controller, and the cache will have to be
reestablished.
DiskQuotaControl.ShutdownNameResolution Method
object.ShutdownNameResolution
Return Value
No return value.
The security identifier (SID) name resolver translates SID to user names on
a background thread.
This thread is shut down automatically when the associated quota control
object is destroyed. However, there are some cases when the thread is no
longer needed, but the object is not yet ready to be destroyed.
A typical example is when no further processing is taking place, but clients
are still holding references to the object.
The ShutdownNameResolution method allows you to terminate the
resolver thread and free the associated resources without destroying the
quota control object.
When you shut down the resolver thread, asynchronous name resolution
DiskQuotaControl.TranslateLogonNameToSID Method
object.TranslateLogonNameToSID (logonname)
Arguments
Parameter Description
logonname Required. String value that specifies the user's logon name.
Return Value
No return value.
The returned SID string can be passed to the FindUser method in place of
a logon name.
When a call to the FindUser( logonname) method fails, it could be due to a
mismatch between the form (Security Account Manager [SAM]
compatible vs. User Principal Name [UPN]) of the logon name provided
and the form stored in the SID-name cache. In such cases, the logon name
can be converted to a SID and the call to FindUser repeated. FindUser
recognizes a SID string and will bypass the SID-name cache lookup.
Name-to-SID translation can be a slow process when compared to lookups
in the SID-name cache. Therefore, it is recommended that FindUser first
be called with a logon name.
Example
the logon name can be translated to a SID string using
TranslateLogonNameToSID then passed again to FindUser.
Function Find(ByVal oDQC, ByVal sName)
On Error Resume Next
Set Find = oDQC.FindUser(sName)
If Err.Number <> 0 Then
Err.Clear
Set Find = oDQC.FindUser(dqc.TranslateLogonNameToSID(sName))
End If
End Function
Set oDQC = Nothing
The Folder object represents a Shell folder. It contains properties and methods
Shell32.Folder.ParentFolder Property
Note Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following code implements the ParentFolder property to retrieve the
Folder object.
Option Explicit
Private Const ssfPROGRAMS = 2
Dim oShell32, oFolder, oParentFolder
'--- Creating a shell application object
Set oShell32 = CreateObject("Shell.Application")
Set oFolder = oShell32.NameSpace(ssfPROGRAMS)
'--- Checking Folder object validation
If (Not oFolder Is Nothing) Then
'--- Retrieving the parent folder object
Set oParentFolder = oFolder.ParentFolder '--- usually "Start Menu".
Msgbox oParentFolder.Title
End If
Set oParentFolder = Nothing : Set oFolder = Nothing : Set oShell32 = Nothing
Shell32.Folder.Title Property
Note Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following example uses Title to retrieve the title of the folder holding the
Shell32.Folder.CopyHere Method
object.CopyHere(vItem, vOptions)
Arguments
Parameter Description
Required. Specifies the item or items to copy. This can be a string that
vItem
represents a file name, a FolderItem object, or a FolderItems object.
Optional. Specifies options for the copy operation. This value can be zero
vOptions or a combination of the of the SHFILEOPSTRUCT structure values
described in Table 5 on page 62
Return Value
No return value.
Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following example uses CopyHere to copy the Autoexec.bat file from the
root directory to the C:\Windows directory
Option Explicit
Private Const FOF_FILESONLY = 128
Private Const FOF_NOCONFIRMATION = 16
Dim oShell32, oFolder
'--- Creating the shell application file
Set oShell32 = CreateObject("Shell.Application")
Set oFolder = ShellApp.NameSpace("C:\Windows")
If Not oFolder Is Nothing Then
'--- Copy to folder all files under temp with
'--- flag for use regular expression and
'--- flag to avoid confirmation dialog
oFolder.CopyHere "C:\temp\*.*", FILESONLY + FOF_NOCONFIRMATION
End If
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing
Shell32.Folder.GetDetailsOf Method
object.GetDetailsOf(vItem, iColumn)
Arguments
Parameter Description
Required. Specifies the item or items to copy. This can be a string that
vItem
represents a file name, a FolderItem object, or a FolderItems object.
Required. An Integer value that specifies the information to be retrieved.
The information available for an item depends on the folder in which it is
iColumn displayed. This value corresponds to the zero-based column number that
is displayed in a Shell view. For an item in the file system, this can be one
of the Details Options Values in Table 6 on page 63
Return Value
String containing the retrieved detail.
Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following example uses GetDetailsOf to retrieve the type of the file named
Clock.avi.
Option Explicit
Private Const colInfoTip = -1
Dim oShell32, oFolder, oFolderItem
Dim sInfo
'--- Creating the shell application file
Set oShell32 = CreateObject("Shell.Application")
'--- Retrieving a folder object using the namespace method
Set oFolder = oShell32.NameSpace("C:\Windows")
'--- Checking Folder validation
If not oFolder is nothing then
'--- Retrieving the file item object
Set oFolderItem = oFolder.ParseName("clock.avi")
'--- Checking file item validation
If (Not oFolderItem Is Nothing) then
'--- Retrieving the info tip information for the item.
sInfo = oFolder.GetDetailsOf(oFolderItem, colInfoTip)
MsgBox sInfo, 0, "Info Tip Information"
End if
Set oFolderItem = Nothing
End if
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing : Set oFolderItem = Nothing
Shell32.Folder.Items Method
object.Items()
Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following example uses Items to determine the number of items in the
C:\Program Files folder.
Option Explicit
Dim oShell32, oFolder, oFolderItem
Dim nCount
'--- Creating the shell application file
Set oShell32 = CreateObject("Shell.Application")
'--- Retrieving a folder object using the namespace method
Set oFolder = oShell32.NameSpace(CSIDL_PROGRAM_FILES)
'--- Checking Folder validation
If not oFolder is nothing then
'--- Retrieving all files items object
Set oFolderItems = oFolder.Items
'--- Checking file item validation
If (Not oFolderItems Is Nothing) then
'--- Retrieving the count iformation.
nCount = oFolderItems.Count
MsgBox nCount, 0, "Number of items under C:\Windows"
End if
Set oFolderItems = Nothing
End if
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing
Shell32.Folder.MoveHere Method
Description
object.MoveHere(vItem, vOptions)
Arguments
Parameter Description
Required. Specifies the item or items to copy. This can be a string that
vItem
represents a file name, a FolderItem object, or a FolderItems object.
Optional. Specifies options for the copy operation. This value can be zero
vOptions or a combination of the of the SHFILEOPSTRUCT structure values
described in Table 5 on page 62
Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following example uses MoveHere to move the all the files in MyTemp from
the root directory of the C:\ drive to the C:\MyTempFolder folder, with a
progress bar.
Option Explicit
Private Const FOF_FILESONLY = 128
Private Const FOF_SIMPLEPROGRESS = 256
Dim sPath
Dim oShell32, oFolder
'--- Creating the shell application file
Set oShell32 = CreateObject("Shell.Application")
'--- Retrieving a folder object using the namespace method
Set oFolder = ShellApp.NameSpace("C:\MyTempFolder")
'--- Checking Folder validation
If Not oFolder Is Nothing Then
'--- Moving to oFolder
sPath = "C:\Program Files\Mercury Interactive\MyTemp\*.*"
oFolder.MoveHere sPath, FOF_FILESONLY + FOF_SIMPLEPROGRESS
End If
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing
Shell32.Folder.NewFolder Method
object.NewFolder(sName, vOptions)
Arguments
Parameter Description
sName Required. A string that specifies the name of the new folder.
vOptions Optional. This value is not currently used.
Return Value
No return value.
Not all methods are implemented for all folders. For example, the
ParseName method is not implemented for the Control Panel folder
(CSIDL_CONTROLS). If you attempt to call an unimplemented method, a
0x800A01BD (decimal 445) error is raised.
Example
The following example uses NewFolder to create the new folder C:\TestFolder.
Option Explicit
Dim oShell32, oFolder
'--- Creating the shell application file
Set oShell32 = CreateObject("Shell.Application")
'--- Retrieving a folder object using the namespace method
Set oFolder = ShellApp.NameSpace("C:\Windows")
'--- Checking Folder validation
If not oFolder is nothing then
'--- Creating a new folder
oFolder.NewFolder("TestFolder")
End if
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing
Shell32.Folder.ParseName Method
object.ParseName(sName)
Arguments
Parameter Description
sName Required. A string that specifies the name of the item.
Return Value
An object reference to the FolderItem object.
Shell32.Folder2.OfflineStatus Property
Description
The OfflineStatus property contains Contains the offline status of the folder.
Data Type
Integer that is set to one of the Shell32.OfflineFolderStatus values described in
Table 4 on page 61
Shell32.Folder2.Self Property
The Self property contains Contains the offline status of the folder.
Data Type
Integer that is set to one of the Shell32.OfflineFolderStatus values described in
Table 4 on page 61
C:\Windows folder.
Option Explicit
Private Const CSIDL_WINDOWS = 36
Dim oShell32, oFolder, oFolderItem
'--- Creating the shell application file
Set oShell32 = CreateObject("Shell.Application")
'--- Retrieving a folder object using the namespace method
Set oFolder = oShell32.NameSpace(CSIDL_WINDOWS)
'--- Checking Folder validation
If Not oFolder Is Nothing Then
Set oFolderItem = oFolder.Self
If (Not oFolderItem Is Nothing) Then
'Add code here.
End if
End if
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing : Set oFolderItem = Nothing
Shell32.Folder2.DismissedWebViewBarricade Method
object.DismissedWebViewBarricade()
Call this method after the Web view barricade is dismissed by the user
Shell32.Folder2.Synchronize Method
Description
The Synchronize method sychronizes all offline files.
Syntax
object.Synchronize ()
Shell32.FolderItem Object
Shell32.FolderItem.GetFolder Property
The GetFolder property contains the item's Folder object, If the item is a
folder.
Shell32.FolderItem.GetLink Property
The GetLink property contains the item's ShellLinkObject object, If the item
is a shortcut
Shell32.FolderItem.IsBrowsable Property
Shell32.FolderItem.IsFileSystem Property
The IsFileSystem property indicates if the item is part of the file system.
Shell32.FolderItem.IsFolder Property
Shell32.FolderItem.IsLink Property
Shell32.FolderItem.ModifyDate Property
The ModifyDate property sets or retrieves the date and time that a file was
last modified. ModifyDate can be used to retrieve the data and time that a
folder was last modified, but cannot set it.
Data Type
Date that specifies or receives the date and time that the item was last
modified.
Shell32.FolderItem.Name Property
Data Type
String that specifies or receives the item's name.
Shell32.FolderItem.Parent Property
Shell32.FolderItem.Path Property
The Path property contains the item's full path and name.
Data Type
String that receives the item's full path and name.
Shell32.FolderItem.Size Property
Shell32.FolderItem.Type Property
Shell32.FolderItem.InvokeVerb Method
object.InvokeVerb (vVerb)
Arguments
Parameter Description
Optional. A string that specifies the verb to be executed. It must be one
vVerb of the values returned by the item's FolderItemVerb.Name property. If
no verb is specified, the default verb will be invoked.
Return Value
No return value.
Example2
The following example uses InvokeVerb to invoke the verb "properties".
Option Explicit
Private Const CSIDL_WINDOWS = 36
Dim oShell32, oFolder, oFolderItem
'--- Creating a shell application object
Set oShell32 = CreateObject("Shell.Application")
Set oFolder = oShell32.NameSpace(CSIDL_WINDOWS)
'--- Checking Folder object validation
If (Not oFolder Is Nothing) Then
'--- Retrieve the FolderItem object
Set oFolderItem = oFolder.Self
'--- Validation...
If (Not oFolderItem Is Nothing) Then
'--- Invoking the verb 'Properties'
oFolderItem.InvokeVerb("Properties")
End if
Set oFolderItem = nothing
End If
'--- Cleaning objects
Set oFolder = Nothing : Set oShell32 = Nothing
Shell32.FolderItem.Verbs Method
Description
The Verbs method retrieves the item's FolderItemVerbs object. This object is
object.Verbs()
Return Value
An object reference to the FolderItemVerbs object.
Shell32.FolderItems.Count Property
Shell32.FolderItems.Item Method
The Item method retrieves the FolderItem object for a specified item in the
collection.
Syntax
object.Item(nIndex)
Arguments
Parameter Description
Optional. Specifies the zero-based index of the item to retrieve. This
nIndex
value must be less than the value of the Count property.
Return Value
An object reference to the FolderItem object.
Shell32.FolderItems2.InvokeVerbEx Method
Description
The InvokeVerbEx method executes a verb on a collection of FolderItem
objects. This method is an extension of the InvokeVerb method, allowing
additional control of the operation through a set of flags.
Syntax
Arguments
Parameter Description
Optional. Variant with the verb string that corresponds to the command
vVerb
to be executed. If no verb is specified, the default verb is executed.
Optional. Variant that consists of a string with one or more arguments to
vArgs the command specified by vVerb. The format of this string depends on
the particular verb.
Return Value
No return value.
Shell32.FolderItems3.Verbs Property
The Verbs property retrieves the list of verbs common to all the folder items.
Data Type
Collection of FolderItemVerbs to be returned.
Shell32.FolderItems3.Filter Method
The Filter method sets a wildcard filter to apply to the items returned.
Syntax
Arguments
Parameter Description
Required. This parameter can be one of the flags listed in SHCONTF
grfFlags
Enumerated Type Values.
bstrFilter Required. Contains a filter string.
Return Value
No return value.
Shell32.FolderItemVerb Object
Shell32.FolderItemVerb.Name Property
Shell32.FolderItemVerb.DoIt Method
The DoIt method Executes a verb on the FolderItem associated with the verb.
Syntax
object.DoIt ()
Return Value
No return value.
Shell32.FolderItemVerbs Object
Shell32.FolderItemVerbs.Count Property
Description
The Count property contains the number of items in the collection.
Data Type
Integer that receives the Count property.
Shell32.FolderItemVerbs.Item Method
The Item method retrieves the FolderItemVerb object for a specified item in
the collection.
Syntax
object.Item (nIndex)
Arguments
Parameter Description
Required. Specifies the zero-based index of the item to retrieve. This
nIndex
value must be less than the value of the Count property
Return Value
Object that receives the FolderItemVerb object.
The Shell object represents the objects in the Shell. Methods are provided to
control the Shell and to execute commands within the Shell. There are also
methods to obtain other Shell-related objects.
Shell32.Shell.Parent Property
Shell32.AddToRecent Method
Description
The AddToRecent method determines if the current user can start and stop the
named service.
Syntax
Arguments
Parameter Description
Required. Variant that specifies the file to add to the list of recently used
varFile
documents.
Optional. String that contains the name of the category in which to place
bstrCategory
the file.
Return Value
No return value..
Shell32.CanStartStopService Method
The CanStartStopService method determines if the current user can start and
stop the named service.
Syntax
object.CanStartStopService (sServiceName)
Arguments
Parameter Description
sServiceName Required. String that contains the name of the service.
Return Value
Returns True if the user can start and stop the service, or False otherwise.
Example
The following example shows the proper usage of CanStartStopService inside a
public function
Public Function fCanStartStopService(ByVal sServiceName)
Dim oShell32
Set oShell32 = CreateObject("Shell.Application")
fCanStartStopService = oShell32.CanStartStopService(sServiceName)
Set oShell32 = nothing
End function
Shell32.CascadeWindows Method
Description
The CascadeWindows method Cascades all of the windows on the desktop.
This method has the same effect as right-clicking the taskbar and selecting
Cascade Windows.
Syntax
object.CascadeWindows ()
Return Value
No return value.
Shell32.ControlPanelItem Method
object.ControlPanelItem (sDir)
Arguments
Parameter Description
Required. Specifies the Control Panel application's file name. All Control
sDir
Panel applications have the .cpl extension.
Return Value
No return value.
Example
The following example uses ControlPanelItem to run the Control Panel's
Display Properties item.
Option Explicit
Dim oShell32
'--- Creating a shell application object
Set oShell32 = CreateObject("Shell.Application")
oShell32.ControlPanelItem("desk.cpl")
'--- Cleaning objects
Set oShell32 = Nothing
Shell32.EjectPC Method
The EjectPC method ejects the computer from its docking station. This is the
same as clicking the Start menu and selecting Eject PC, if your computer
supports this command.
Syntax
object.EjectPC()
Return Value
No return value.
Shell32.Explore Method
object.Explore(vDir)
Arguments
Parameter Description
vDir Required. Specifies the folder to be displayed. This can be a string that
specifies the path of the folder or one of the ShellSpecialFolderConstants
values.
Example
The following example shows Explore in use.
Option Explicit
Private Const CSIDL_PERSONAL = 5
Dim oShell32
'--- Creating a shell application object
Set oShell32 = CreateObject("Shell.Application")
oShell32.Explore(CSIDL_PERSONAL)
'--- Cleaning objects
Set oShell32 = Nothing
Shell32.ExplorerPolicy Method
object.ExplorerPolicy (bstrPolicyName)
Arguments
Parameter Description
bstrPolicyName Required. String that specifies the name of the Internet Explorer policy.
Return Value
Variant that receives the value of the specified Internet Explorer policy.
Shell32.FileRun Method
object.FileRun()
Return Value
No return value.
Shell32.FindComputer Method
object.FindComputer ()
Return Value
No return value.
Shell32.FindFiles Method
The FindFiles method Displays the Find: All Files dialog box. This is the same
as clicking the Start menu, selecting Find, and then selecting Files or Folders.
Syntax
object.FindFiles ()
Return Value
No return value.
Shell32.FindPrinter Method
The FindPrinter method displays the Find Printer dialog box to allow the user
to find a printer.
Syntax
Arguments
Parameter Description
sName Optional. String that contains the printer name.
sLocation Optional. String that contains the printer location.
sModel Optional. String that contains the printer model.
Return Value
No return value.
If you assign strings to one or more of the optional parameters, they are
displayed as default values in the associated edit control when the Find
Printer dialog box is displayed.
The user can either accept or override these values. If no value is assigned
to a parameter, the associated edit box is empty and the user must enter a
value.
Shell32.GetSetting Method
object.GetSetting (nSetting)
Arguments
Parameter Description
Required. A value of type Integer that specifies the current Shell
nSetting settings to retrieve. The SHGetSetSettings Enumerated Type described
on Table 10 on page 66.
Return Value
Boolean that returns true if the setting exists, or false otherwise.
Shell32.GetSystemInformation Method
object.GetSystemInformation (sName)
Arguments
Parameter Description
Return Value
Returns the requested system information value. The return type depends on
what system information is requested.
Shell32.Help Method
The Help method displays the Microsoft Windows Help and Support Center. This
method has same effect as clicking the Start menu and selecting Help and
Support.
Syntax
object.Help ()
Return Value
No return value.
Shell32.IsRestricted Method
The IsRestricted method retrieves the registry's data value for a given group's
restriction value.
Syntax
Arguments
Parameter Description
sGroup Required. The group (key) name under which to check for the restriction.
sRestriction Required. The restriction whose data value is to be retrieved.
Return Value
The value of the restriction. If the specified restriction is not found, the return
value is 0.
IsRestricted first looks for a registry key name matching sGroup under the
following key.
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies
Shell32.IsServiceRunning Method
object.IsServiceRunning (sServiceName)
Arguments
Parameter Description
sServiceName Required. String that contains the service's name.
Return Value
Returns true if the service specified by sServiceName is running, or false
otherwise.
Example
The following example shows the proper usage of IsServiceRunning inside a
public function
Public Function fIsServiceRunning(ByVal sServiceName)
Dim oShell32
Set oShell32 = CreateObject("Shell.Application")
fIsServiceRunning = oShell32.IsServiceRunning(sServiceName)
Set oShell32 = nothing
End function
Shell32.MinimizeAll Method
The Help method Minimizes all of the windows on the desktop. This method has
the same effect as right-clicking the taskbar and selecting Minimize All Windows
on older systems or clicking the Show Desktop icon in the Quick Launch area of
the taskbar in Microsoft Windows 2000 or Windows XP.
Syntax
object.MinimizeAll ()
Return Value
No return value.
Shell32.NameSpace Method
The NameSpace method creates and returns a Folder object for the specified
folder.
Syntax
object.NameSpace (vDir)
Arguments
Parameter Description
Required. Specifies the folder for which to create the Folder object. This
can be a string that specifies the path of the folder or one of the
vDir
Shell32.ShellSpecialFolderConstants values in Table 7–
Shell32.ShellSpecialFolderConstants Values on page 65.
Return Value
Object reference to the Folder object for the specified folder. If the folder is not
successfully created, this value returns null.
Example
The following example shows NameSpace in use.
Public Function fGetShellNameSpace(ByVal vDir, ByRef sTitle)
Dim oShell32, oFolder
Set oShell32 = CreateObject("Shell.Application")
Set oFolder = objShell.NameSpace(vDir)
If (Not objFolder Is Nothing) then
sTitle = oFolder.Title
End If
set oFolder = Nothing
set oShell32 = Nothing
End function
Shell32.Open Method
object.Open (vDir)
Arguments
Parameter Description
Required. Specifies the folder for which to create the Folder object. This
can be a string that specifies the path of the folder or one of the
vDir
Shell32.ShellSpecialFolderConstants values in Table 7–
Shell32.ShellSpecialFolderConstants Values on page 65.
Return Value
No return value.
Shell32.RefreshMenu Method
The RefreshMenu method refreshes the contents of the Start menu. Used only
with systems preceeding Microsoft Windows XP.
Syntax
object.RefreshMenu ()
Return Value
No return value.
Remarks
The functionality that RefreshMenu provides is handled automatically under
Windows XP or later. Do not call this method under that operating system.
Shell32.ServiceStop Method
Arguments
Parameter Description
sServiceName Required. String that contains the service's name.
Required. Variant that is set to true to have the service started by the
vPersistent service control manager when ServiceStart is called. To leave the
service configuration unchanged, set vPersistent to false.
Return Value
Returns true if successful, or false otherwise.
Shell32.ShellExecute Method
object.ShellExecute(sFile,vArguments,vDirectory,vOperation,vShow)
Arguments
Parameter Description
Required. String that contains the name of the file on which
sFile
ShellExecute will perform the action specified by vOperation.
vArguments Optional. Variant that contains the parameter values for the operation.
Optional. Variant that contains the fully qualified path of the directory
vDirectory that contains the file specified by sFile. If this parameter is not specified,
the current working directory is used.
Optional. Variant that specifies the operation to be performed. It should
be set to one of the verb strings that is supported by the file. For a
vOperation
discussion of verbs, see the Remarks section. If this parameter is not
specified, the default operation is performed.
Optional. Variant that recommends how the window that belongs to the
vShow application that performs the operation should be displayed initially. The
application can ignore this recommendation.
vShow can take one of the following values. If this parameter is not specified,
the application uses its default value.
Value Description
0 Open the application with a hidden window.
Open the application with a normal window. If the window is minimized or
1
maximized, the system restores it to its original size and position.
2 Open the application with a minimized window.
3 Open the application with a maximized window.
Open the application with its window at its most recent size and position. The
4
active window remains active.
5 Open the application with its window at its current size and position.
Open the application with a minimized window. The active window remains
7
active.
Open the application with its window in the default state specified by the
10
application.
Remarks
This method is equivalent to launching one of the commands associated with
a file's shortcut menu. Each command is identified by a verb string. The
supported verbs vary from file to file. The most commonly supported verb is
"open", which is also usually the default verb. Others might be supported
only by certain types of files.
Shell32.SetTime Method
The SetTime method Displays the Date and Time Properties dialog box. This
method has the same effect as right-clicking the clock in the taskbar status area
and selecting Adjust Date/Time.
Syntax
object.SetTime ()
Shell32.ShowBrowserBar Method
Professional
The ShowBrowserBar method stops a named service.
Syntax
Arguments
Parameter Description
Required. String that contains the string form of the class identifier
(CLSID) of the browser bar to be displayed. The object must be
sCLSID
registered as an Explorer Bar object with a CATID_InfoBand
component category.
Required. Variant that is set to true to show the browser bar, or false
vShow
to hide it.
Return Value
Variant. Returns true if successful, or false otherwise.
You can display one of the standard Explorer Bars by setting sCLSID to its
CLSID string. The standard Explorer Bars and their CLSID strings are as
follows.
Explorer Bar CLSID string
Favorites {EFA24E61-B078-11d0-89E4-00C04FC9E26E}
Folders {EFA24E64-B078-11d0-89E4-00C04FC9E26E}
History {EFA24E62-B078-11d0-89E4-00C04FC9E26E}
Search {30D02401-6A81-11d0-8274-00C04FD5AE38}
Shell32.ShutdownWindows Method
Displays the Shut Down Windows dialog box. This is the same as clicking the
Start menu and selecting Shut Down.
Syntax
object.ShutdownWindows ()
Return Value
No return value.
Shell32.TileHorizontally Method
object.TileHorizontally()
Return Value
No return value.
Shell32.TileVertically Method
The TileHorizontally method Tiles all of the windows on the desktop vertically.
This method has the same effect as right-clicking the taskbar and selecting Tile
Windows Vertically..
Syntax
object.TileVertically ()
Return Value
No return value.
Shell32.ToggleDesktop Method
object.ShowBrowserBar ( )
Return Value
No return value.
Remarks
This method behaves like the toggle desktop icon on the quick launch bar. It
hides all open windows and shows the desktop, or hides the desktop and
shows all open windows.
The ToggleDesktop method does not display any user interface, it just
invokes the toggle action.
This methos is similar to MinimizeAll
Shell32.TrayProperties Method
The TrayProperties method Displays the Taskbar and Start Menu Properties
dialog box. This method has the same effect as right-clicking the taskbar and
selecting Properties.
Syntax
object.TrayProperties()
Return Value
No return value.
Figure 16 – Task
Shell32.UndoMinimizeAll Method
object.UndoMinimizeAll ()
Return Value
No return value.
Shell32.Windows Method
The Windows method Creates and returns a ShellWindows object. This object
represents a collection of all of the open windows that belong to the Shell.
Syntax
object.Windows ()
Return Value
Object reference to the ShellWindows object.
Shell32.WindowsSecurity Method
object.WindowsSecurity ( )
Return Value
No return value.
Remarks
Using this method provides the same results as pressing CTRL+ALT+DELETE
or using the security option that is on the Start menu when you connect
using Microsoft Terminal Server.
This method will work only when connected via a terminal session to
Shell32.ShellLinkObject Object
The Shell object represents the objects in the Shell. Methods are provided to
control the Shell and to execute commands within the Shell. There are also
methods to obtain other Shell-related objects.
Shell32.ShellLinkObject.Target Property
Shell32.ShellFolderItem Object
This object extends the FolderItem object. In addition to the properties and
methods supported by FolderItem, ShellFolderItem has two additional methods.
Shell32.ShellFolderItem.ExtendedProperty Method
object.ExtendedProperty ( sPropName )
Arguments
Parameter Description
Required. String value that specifies the property. See the Remarks
sPropName
section for details.
Return Value
Variant. Returns the value of the property, if it exists for the specified item. The
value will have full typingfor example, dates will be returned as dates, not
strings.
Remarks
This method returns a zero-length string if the property is valid but does not
exist for the specified item, or an OLE error code otherwise.
There are two ways to specify a property. The first is to assign the property's
Q&A
Option Explicit
Const CSIDL_COMMON_ADMINTOOLS = &H2f
Dim oShell, oFolder, oItem
Dim nRow : nRow = 1
Option Explicit
Const CSIDL_MYMUSIC = 13
Dim oShell, oFolder, oItem
Dim nRow : nRow = 1
'--- Creating an entry in local datasheet
DataTable.LocalSheet.AddParameter "ITEM_NAME", ""
'--- Creating a new shell application object
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.Namespace(CSIDL_MYMUSIC)
'--- Retrieving collection of items
For Each oItem in oFolder.Items
Datatable.LocalSheet.SetCurrentRow nRow
DataTable("ITEM_NAME", dtLocalSheet) = oItem.Name
nRow = nRow + 1
Next
Set oShell = Nothing
Option Explicit
Const CSIDL_COMMON_DESKTOPDIR = 25
Dim oShell, oFolder, oFolderItem
Dim nRow : nRow = 1
'--- Creating an entry in local datasheet
DataTable.LocalSheet.AddParameter "ITEM_NAME", ""
'--- Creating a new shell application object
Set oShell = CreateObject("Shell.Application")
Option Explicit
Dim oComp
Dim sInfo
Set oComp = CreateObject("Shell.LocalMachine")
sInfo = "Computer name: " & oComp.MachineName & vbCrLf
sInfo = sInfo & "Shutdown allowed: " & oComp.IsShutdownAllowed & vbCrLf
sInfo = sInfo & "Friendly UI enabled: " & oComp.IsFriendlyUIEnabled & vbCrLf
sInfo = sInfo & "Guest access mode: " & oComp.IsGuestAccessMode & vbCrLf
sInfo = sInfo & "Guest account enabled: " & oComp.IsGuestEnabled(0) & vbCrLf
sInfo = sInfo & "Multiple users enabled: " & oComp.IsMultipleUsersEnabled & vbCrLf
sInfo = sInfo & "Offline files enabled: " & oComp.IsOfflineFilesEnabled & vbCrLf
sInfo = sInfo & "Remote conn. enabled: " & oComp.IsRemoteConnectionsEnabled & vbCrLf
sInfo = sInfo & "Undock enabled: " & oComp.IsUndockEnabled & vbCrLf
MsgBox sInfo, 0, "Local Computer Information"
Set oComp = Nothing
Option Explicit
Const CSIDL_FAVORITES = 6
Set oShell32, oShell, oFolder, oFolderItem, oURLShortcut
Dim sDesktopFld
'--- Creating a application object
Set oShell32 = CreateObject("Shell.Application")
Set oFolder = oShell32.Namespace(CSIDL_FAVORITES)
'--- Using the favorites folder for the path.
Set oFolderItem = oFolder.Self
sDesktopFld = oFolderItem.Path
'--- Creating a shell folder to use the URLShortcut object
Set oShell = CreateObject("WScript.Shell")
Set oURLShortcut = oShell.CreateShortcut(sDesktopFld & "\MSDN Site.url")
oURLShortcut.TargetPath = "http://msdn.microsoft.com"
oURLShortcut.Save
'--- Cleaning
Set oURLShortcut = Nothing : Set oShell = Nothing : Set oComp = Nothing
QuotaStateConstants Values
Constant Value Description
dqStateDisable 0 Disk quotas are disabled.
dqStateTrack 1 Disk quotas are disabled.
UserNameResolutionConstants Values
Constant Val Description
dqResolveNone 0 Do not resolve user name information.
dqResolveSync 1 Wait while resolving name information.
dqResolveAsync 2 Do not wait while resolving name information. The OnUserNameChanged
event fires when the name is resolved.
QuotaStateConstants Values
Constant Value Description
dqAcctResolved 0 Account information is resolved.
dqAcctUnavailable 1 Account information is unavailable.
dqAcctDeleted 2 Account has been deleted.
dqAcctInvalid 3 Account is invalid.
dqAcctUnknown 4 Account cannot be found.
Shell32.OfflineFolderStatus Values
Constant Value Description
OFS_DIRTYCACHE 3 Server is online with unsynchronized changes.
OFS_INACTIVE -1 Offline caching is not enabled for this folder.
OFS_OFFLINE 1 Server is offline.
OFS_ONLINE 0 Server is online.
OFS_SERVERBACK 2 Server is offline but can be reached.
SHFILEOPSTRUCT Values
Constant Value Description
FOF_SILENT 4 Do not display a progress dialog box.
Give the file being operated on a new name in a move,
FOF_RENAMEONCOLLISION 8 copy, or rename operation if a file with the target
name already exists.
Respond with "Yes to All" for any dialog box that is
FOF_NOCONFIRMATION 16
displayed.
FOF_ALLOWUNDO 64 Preserve undo information, if possible.
Perform the operation on files only if a wildcard file
FOF_FILESONLY 128
name (*.*) is specified.
Display a progress dialog box but do not show the file
FOF_SIMPLEPROGRESS 256
names.
Do not confirm the creation of a new directory if the
FOF_NOCONFIRMMKDIR 512
operation requires one to be created.
Shell32.ShellSpecialFolderConstants Values
Constant Val Description
The file system directory that is used to store administrative
tools for an individual user. The Microsoft Management
CSIDL_ADMINTOOLS 48
Console (MMC) will save customized consoles to this
directory, and it will roam with the user.
Shell32.ShellFolderViewOptions Values
Constant Val Description
SFVVO_SHOWALLOBJECTS 1 The Show All Files option is enabled.
The Hide File Extensions for Known File Types option is
SFVVO_SHOWEXTENSIONS 2
disabled.
The Display Compressed Files and Folders with Alternate
SFVVO_SHOWCOMPCOLOR 8
Color option is enabled.
SFVVO_SHOWSYSFILES 32 The Do Not Show Hidden Files option is enabled.
SFVVO_WIN95CLASSIC 64 The Classic Style option is enabled.
SFVVO_DOUBLECLICKINWEBVIEW 128 The Double-Click to Open an Item option is enabled.
SFVVO_DESKTOPHTML 512 The Active Desktop View as Web Page option is enabled.
option.
The state of the Show encrypted or compressed NTFS
SSF_SHOWCOMPCOLOR
files in color option.
The state of the Hide extensions for known file types
SSF_SHOWEXTENSIONS
option.
The state of the Show pop-up description for folder and
SSF_SHOWINFOTIP
desktop items option.
SSF_SHOWSTARTPAGE Not used.
SHCOLUMNID Values
PID Property Name Data Type
2 Title String
3 Subject String
4 Author String
5 Keywords String
6 Comments String
7 Template String
8 Last Saved By String