If you right-click a file name in Explorer and select Properties, Windows displays a dialog box with a variety of information about the file, including its size, creation and modification dates, and attributes. It can be a useful technique to find the properties of a file from within a VB6 program. I'll show you how to do that in this tip.
First, you need to declare a UDT, some constants, and an API function in a module in your program.
Public Const SW_SHOW = 5
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
' optional fields
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Declare Function ShellExecuteEx Lib "shell32.dll" _
(ByRef s As SHELLEXECUTEINFO) As Long
Then, all you need to do is declare an instance of the UDT, load it with the required information, and call the function.
Dim shInfo As SHELLEXECUTEINFO
With shInfo
.cbSize = LenB(shInfo)
.lpFile = FullPathAndNameOfFile
.nShow = SW_SHOW
.fMask = SEE_MASK_INVOKEIDLIST
.lpVerb = "properties"
End With
ShellExecuteExshInfo
If you try this for a file that does not exist, Windows pops up a message informing you of this fact. However, there is no runtime error.
Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!



