The next series of Tips will involve the Microsoft Scripting Runtime Library (Scrrun.dll). This Library is, in my humble opinion, one of the most useful and practical Libraries ever created. With the Scripting Runtime Library, you can retrieve information related to Drives, Folders, Files, and Text Files and set/retrieve certain Attributes of Drives, Folders, Files, and Text Files. Through Methods exposed by this Library, you can also manipulate these Objects. Because of the extensive functionality exposed by this Library, I have broken it down into several Components which will be the subject matter for the next series of Tips. Our first related Tip will show you how to retrieve specific and vital information for all Drives on your PC, or for a single Drive of your choosing. The code is fairly intuitive, and I have inserted Comments wherever I thought they would be appropriate. This code was used on a Pentium 4 PC with a CD ROM Drive, DVD Drive, Floppy Drive, a single non-partitioned Fixed Disk, and a small Flash Drive in a USB Port. Should you have any questions concerning this Tip, please feel free to ask. Without further adieu, the Scripting Runtime Library Tip #1: -
On Error GoTo ErrorHandler
-
On Error Resume Next 'Critical Line of code
-
-
'Must set a Reference to the Microsoft Scripting Runtime Library (Scrrun.dll)
-
-
'declare appropriate Object Variables
-
Dim fso As FileSystemObject, drv As Drive, drvSingle As Drive
-
-
'Create an Instance of the FileSystemObject using 1 of 2 Methods
-
Set fso = New Scripting.FileSystemObject
-
'OR
-
'Set fso = CreateObject("Scripting.FileSystemObject")
-
-
Debug.Print "--------------------------------------------"
-
'Loop through all Drives on the PC
-
For Each drv In fso.Drives
-
Debug.Print "Drive Letter: " & drv.DriveLetter
-
Debug.Print " Available Space: " & Format$(drv.AvailableSpace, "#,#,#,#") & " bytes"
-
Debug.Print " Drive Type: " & fDetermineDriveType(drv.DriveType)
-
Debug.Print " File System: " & drv.FileSystem
-
Debug.Print " Free Space: " & Format$(drv.FreeSpace, "#,#,#,#") & " bytes"
-
Debug.Print " Is Drive Ready?: " & IIf(drv.IsReady, "Yes", "No")
-
Debug.Print " Drive Path: " & drv.Path
-
Debug.Print " Root Folder: " & drv.RootFolder
-
Debug.Print " Drive Serial Number: " & drv.SerialNumber
-
Debug.Print " Drive Share Name: " & drv.ShareName & IIf(Nz(drv.ShareName) = "", _
-
"Unavailable", drv.ShareName)
-
Debug.Print " Total Size of Drive: " & Format(drv.TotalSize, "#,#,#,#") & " bytes"
-
Debug.Print " Volume Name of Drive: " & IIf(Nz(drv.VolumeName) = "", "Unavailable", _
-
drv.VolumeName)
-
Debug.Print "--------------------------------------------"
-
Next
-
-
'For a Single Drive, from this point on
-
Set drvSingle = fso.Drives("C:")
-
-
Debug.Print "--------------------------------------------"
-
Debug.Print "Drive Letter: " & drvSingle.DriveLetter & " (Single Drive)"
-
Debug.Print " Available Space: " & Format$(drvSingle.AvailableSpace, "#,#,#,#") & _
-
" bytes"
-
Debug.Print " Drive Type: " & fDetermineDriveType(drvSingle.DriveType)
-
Debug.Print " File System: " & drvSingle.FileSystem
-
Debug.Print " Free Space: " & Format$(drvSingle.FreeSpace, "#,#,#,#") & " bytes"
-
Debug.Print " Is Drive Ready?: " & IIf(drvSingle.IsReady, "Yes", "No")
-
Debug.Print " Drive Path: " & drvSingle.Path
-
Debug.Print " Root Folder: " & drvSingle.RootFolder
-
Debug.Print " Drive Serial Number: " & drvSingle.SerialNumber
-
Debug.Print " Drive Share Name: " & drvSingle.ShareName & _
-
IIf(Nz(drvSingle.ShareName) = "", "Unavailable", drvSingle.ShareName)
-
Debug.Print " Total Size of Drive: " & Format(drvSingle.TotalSize, "#,#,#,#") & _
-
" bytes"
-
Debug.Print " Volume Name of Drive: " & IIf(Nz(drvSingle.VolumeName) = "", "Unavailable", _
-
drvSingle.VolumeName)
-
Debug.Print "--------------------------------------------"
-
Private Function fDetermineDriveType(intDriveType As Integer) As String
-
'Interprets the Numeric Value returned by the Type Property and
-
'returns a String representing the Drive Type
-
Select Case intDriveType
-
Case 0
-
fDetermineDriveType = "Unknown"
-
Case 1
-
fDetermineDriveType = "Removable"
-
Case 2
-
fDetermineDriveType = "Fixed"
-
Case 3
-
fDetermineDriveType = "Remote"
-
Case 4
-
fDetermineDriveType = "CD ROM"
-
Case 5
-
fDetermineDriveType = "RAM Disk"
-
Case Else
-
fDetermineDriveType = "Unknown"
-
End Select
OUTPUT: - --------------------------------------------
-
Drive Letter: A
-
Available Space: 833,536 bytes
-
Drive Type: Removable
-
File System: FAT
-
Free Space: 833,536 bytes
-
Is Drive Ready?: Yes
-
Drive Path: A:
-
Root Folder: A:\
-
Drive Serial Number: 1284401684
-
Drive Share Name: Unavailable
-
Total Size of Drive: 1,457,664 bytes
-
Volume Name of Drive: Unavailable
-
--------------------------------------------
-
Drive Letter: C
-
Available Space: 49,298,620,416 bytes
-
Drive Type: Fixed
-
File System: NTFS
-
Free Space: 49,298,620,416 bytes
-
Is Drive Ready?: Yes
-
Drive Path: C:
-
Root Folder: C:\
-
Drive Serial Number: 350880761
-
Drive Share Name: Unavailable
-
Total Size of Drive: 61,483,933,696 bytes
-
Volume Name of Drive: Dezii
-
--------------------------------------------
-
Drive Letter: D
-
Drive Type: CD ROM
-
Is Drive Ready?: No
-
Drive Path: D:
-
Drive Share Name: Unavailable
-
--------------------------------------------
-
Drive Letter: E
-
Drive Type: CD ROM
-
Is Drive Ready?: No
-
Drive Path: E:
-
Drive Share Name: Unavailable
-
--------------------------------------------
-
Drive Letter: F
-
Available Space: 10,195,968 bytes
-
Drive Type: Fixed
-
File System: FAT
-
Free Space: 10,195,968 bytes
-
Is Drive Ready?: Yes
-
Drive Path: F:
-
Root Folder: F:\
-
Drive Serial Number: -2137813243
-
Drive Share Name: Unavailable
-
Total Size of Drive: 32,472,576 bytes
-
Volume Name of Drive: FlashDisk
-
--------------------------------------------
-
--------------------------------------------
-
Drive Letter: C (Single Drive)
-
Available Space: 49,298,620,416 bytes
-
Drive Type: Fixed
-
File System: NTFS
-
Free Space: 49,298,620,416 bytes
-
Is Drive Ready?: Yes
-
Drive Path: C:
-
Root Folder: C:\
-
Drive Serial Number: 350880761
-
Drive Share Name: Unavailable
-
Total Size of Drive: 61,483,933,696 bytes
-
Volume Name of Drive: Dezii
-
--------------------------------------------
7 8773
Hello, ADezii.
IMHO "Windows Script Host Object Model" library (\WINDOWS\system32\wshom.ocx) is even more useful.
It has all (or almost all) useful classes of "Microsoft Scripting Runtime" as well as a bunch of other very useful ones. - network
- windows registry functions
- a very useful shell exec method allowing to run an application and get access to its stdin/stdout/stderr as well as to terminate it
- creating shortcuts
- etc
Regards,
Fish
Hello, ADezii.
IMHO "Windows Script Host Object Model" library (\WINDOWS\system32\wshom.ocx) is even more useful.
It has all (or almost all) useful classes of "Microsoft Scripting Runtime" as well as a bunch of other very useful ones. - network
- windows registry functions
- a very useful shell exec method allowing to run an application and get access to its stdin/stdout/stderr as well as to terminate it
- creating shortcuts
- etc
Regards,
Fish
Hello FishVal and thanks for the info, I never realized that it was quite that extensive. When I am done with this series of Tips relating to the Scripting Runtime could I perhaps interest you in creating a Tip(s) relating to the implementation of the "Windows Script Host Object Model"? I'm sure that it would generate a lot of interest. If you agree, I'll even show you the Top Secret 'Tip Creator Handshake' that only Mary, NeoPa, and I are privy to. (LOL).
Just one drawback from using Scripting. There are some antivirus programs (like Kaspersky AV) that have an ability to block scripting in Access. In such case, Access application just stops running. So if you intend to distribute your application, you would rather consider not using Scripting, as powerful as it is, unless there is no other option.
Just one drawback from using Scripting. There are some antivirus programs (like Kaspersky AV) that have an ability to block scripting in Access. In such case, Access application just stops running. So if you intend to distribute your application, you would rather consider not using Scripting, as powerful as it is, unless there is no other option.
Excellant point dima69, one that I was not aware of, and one to definately consider should you decide to use it. Within these AV Utilities, is there an option to specifically turn off the Component that would normally block Scripting?
Excellant point dima69, one that I was not aware of, and one to definately consider should you decide to use it. Within these AV Utilities, is there an option to specifically turn off the Component that would normally block Scripting?
I know that in Kaspersky AV there is an option that can be changed to enable Scripting. Don't remember about the others.
Hello, ADezii
Hello FishVal and thanks for the info, I never realized that it was quite that extensive. When I am done with this series of Tips relating to the Scripting Runtime could I perhaps interest you in creating a Tip(s) relating to the implementation of the "Windows Script Host Object Model"?
You certainly could. Just let me know, please, in advance when "Runtime Scripting" saga will come to a head. :)
Regards,
Fish
Hello, ADezii
You certainly could. Just let me know, please, in advance when "Runtime Scripting" saga will come to a head. :)
Regards,
Fish
Thanks FishVal, I figure 4 more Tips involving the Scripting Runtime, namely: Folders, Files, Text File manipulation, and the File System Object itself. This should give you plenty of time for the 'Grandaddy of all Tips'! (LOL). See you around and thanks for the assistance.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Karl Irvin |
last post by:
To use the Textstream object, I had to set a Reference to the Microsoft
Scripting Runtime.
This works good with A2000
Is the Scripting Runtime included with A2002 and A2003 so the Reference...
|
by: Karl Irvin |
last post by:
To use the Textstream object, I had to set a Reference to the Microsoft
Scripting Runtime.
This works good with A2000
Is the Scripting Runtime included with A2002 and A2003 so the Reference...
|
by: Howard Kaikow |
last post by:
Historically, auntie virus software has issued false positives against code
using the Scripting Runtime.
Does .NET have a native replacement for the Scripting runtime?
For example, is there...
|
by: PaulieS |
last post by:
Hi all.
Am migrating a customer from IIS5 on W2K server to IIS6 on W2K3.
Zipped all the websites and unzipped them to the identical locations
on new server. Used IISMT to migrate metabase.
...
|
by: john d |
last post by:
I have an IIS 5.0 server with a Virtual Directory called test. This virtual
directory points to a share on the network, \\server1\share\ and uses a valid
domain account in the "Connect As" field....
|
by: anidmarty |
last post by:
Hey
I'm a Sysadmin and my users are getting this error on my production box.
It works fine on the dev box.
There is a script that is run that generates this error.
Production is clustered...
|
by: ADezii |
last post by:
This is the 2nd Tip in a series of Tips on the Microsoft Scripting Runtime Library. The 1st Tip related to Drives, while this Tip will concentrate on the Folders (Directories) in your PC and various...
|
by: ADezii |
last post by:
This is the 3rd in a series of Tips dealing specifically with the Microsoft Scripting Runtime Library. In this Tip, we'll show you how to return specific Properties relating to Files, as well as...
|
by: ADezii |
last post by:
This is the last in a series of Tips involving the Microsoft Scripting Runtime Library and deals with creating, opening, writing to, reading from, and closing Text Files via this Library. At this...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |