473,887 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Microsoft Scripting Runtime #1

ADezii
8,834 Recognized Expert Expert
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:
Expand|Select|Wrap|Line Numbers
  1. On Error GoTo ErrorHandler
  2. On Error Resume Next    'Critical Line of code
  3.  
  4. 'Must set a Reference to the Microsoft Scripting Runtime Library (Scrrun.dll)
  5.  
  6. 'declare appropriate Object Variables
  7. Dim fso As FileSystemObject, drv As Drive, drvSingle As Drive
  8.  
  9. 'Create an Instance of the FileSystemObject using 1 of 2 Methods
  10. Set fso = New Scripting.FileSystemObject
  11.                 'OR
  12. 'Set fso = CreateObject("Scripting.FileSystemObject")
  13.  
  14. Debug.Print "--------------------------------------------"
  15. 'Loop through all Drives on the PC
  16. For Each drv In fso.Drives
  17.   Debug.Print "Drive Letter: " & drv.DriveLetter
  18.   Debug.Print "  Available Space: " & Format$(drv.AvailableSpace, "#,#,#,#") & " bytes"
  19.   Debug.Print "  Drive Type: " & fDetermineDriveType(drv.DriveType)
  20.   Debug.Print "  File System: " & drv.FileSystem
  21.   Debug.Print "  Free Space: " & Format$(drv.FreeSpace, "#,#,#,#") & " bytes"
  22.   Debug.Print "  Is Drive Ready?: " & IIf(drv.IsReady, "Yes", "No")
  23.   Debug.Print "  Drive Path: " & drv.Path
  24.   Debug.Print "  Root Folder: " & drv.RootFolder
  25.   Debug.Print "  Drive Serial Number: " & drv.SerialNumber
  26.   Debug.Print "  Drive Share Name: " & drv.ShareName & IIf(Nz(drv.ShareName) = "", _
  27.                                    "Unavailable", drv.ShareName)
  28.   Debug.Print "  Total Size of Drive: " & Format(drv.TotalSize, "#,#,#,#") & " bytes"
  29.   Debug.Print "  Volume Name of Drive: " & IIf(Nz(drv.VolumeName) = "", "Unavailable", _
  30.                                        drv.VolumeName)
  31.   Debug.Print "--------------------------------------------"
  32. Next
  33.  
  34. 'For a Single Drive, from this point on
  35. Set drvSingle = fso.Drives("C:")
  36.  
  37. Debug.Print "--------------------------------------------"
  38.   Debug.Print "Drive Letter: " & drvSingle.DriveLetter & " (Single Drive)"
  39.   Debug.Print "  Available Space: " & Format$(drvSingle.AvailableSpace, "#,#,#,#") & _
  40.                                       " bytes"
  41.   Debug.Print "  Drive Type: " & fDetermineDriveType(drvSingle.DriveType)
  42.   Debug.Print "  File System: " & drvSingle.FileSystem
  43.   Debug.Print "  Free Space: " & Format$(drvSingle.FreeSpace, "#,#,#,#") & " bytes"
  44.   Debug.Print "  Is Drive Ready?: " & IIf(drvSingle.IsReady, "Yes", "No")
  45.   Debug.Print "  Drive Path: " & drvSingle.Path
  46.   Debug.Print "  Root Folder: " & drvSingle.RootFolder
  47.   Debug.Print "  Drive Serial Number: " & drvSingle.SerialNumber
  48.   Debug.Print "  Drive Share Name: " & drvSingle.ShareName & _
  49.                  IIf(Nz(drvSingle.ShareName) = "", "Unavailable", drvSingle.ShareName)
  50.   Debug.Print "  Total Size of Drive: " & Format(drvSingle.TotalSize, "#,#,#,#") & _
  51.               " bytes"
  52.   Debug.Print "  Volume Name of Drive: " & IIf(Nz(drvSingle.VolumeName) = "", "Unavailable", _
  53.                                        drvSingle.VolumeName)
  54.   Debug.Print "--------------------------------------------"
Expand|Select|Wrap|Line Numbers
  1. Private Function fDetermineDriveType(intDriveType As Integer) As String
  2. 'Interprets the Numeric Value returned by the Type Property and
  3. 'returns a String representing the Drive Type
  4. Select Case intDriveType
  5.   Case 0
  6.     fDetermineDriveType = "Unknown"
  7.   Case 1
  8.     fDetermineDriveType = "Removable"
  9.   Case 2
  10.     fDetermineDriveType = "Fixed"
  11.   Case 3
  12.     fDetermineDriveType = "Remote"
  13.   Case 4
  14.     fDetermineDriveType = "CD ROM"
  15.   Case 5
  16.     fDetermineDriveType = "RAM Disk"
  17.   Case Else
  18.     fDetermineDriveType = "Unknown"
  19. End Select
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. --------------------------------------------
  2. Drive Letter: A
  3.   Available Space: 833,536 bytes
  4.   Drive Type: Removable
  5.   File System: FAT
  6.   Free Space: 833,536 bytes
  7.   Is Drive Ready?: Yes
  8.   Drive Path: A:
  9.   Root Folder: A:\
  10.   Drive Serial Number: 1284401684
  11.   Drive Share Name: Unavailable
  12.   Total Size of Drive: 1,457,664 bytes
  13.   Volume Name of Drive: Unavailable
  14. --------------------------------------------
  15. Drive Letter: C
  16.   Available Space: 49,298,620,416 bytes
  17.   Drive Type: Fixed
  18.   File System: NTFS
  19.   Free Space: 49,298,620,416 bytes
  20.   Is Drive Ready?: Yes
  21.   Drive Path: C:
  22.   Root Folder: C:\
  23.   Drive Serial Number: 350880761
  24.   Drive Share Name: Unavailable
  25.   Total Size of Drive: 61,483,933,696 bytes
  26.   Volume Name of Drive: Dezii
  27. --------------------------------------------
  28. Drive Letter: D
  29.   Drive Type: CD ROM
  30.   Is Drive Ready?: No
  31.   Drive Path: D:
  32.   Drive Share Name: Unavailable
  33. --------------------------------------------
  34. Drive Letter: E
  35.   Drive Type: CD ROM
  36.   Is Drive Ready?: No
  37.   Drive Path: E:
  38.   Drive Share Name: Unavailable
  39. --------------------------------------------
  40. Drive Letter: F
  41.   Available Space: 10,195,968 bytes
  42.   Drive Type: Fixed
  43.   File System: FAT
  44.   Free Space: 10,195,968 bytes
  45.   Is Drive Ready?: Yes
  46.   Drive Path: F:
  47.   Root Folder: F:\
  48.   Drive Serial Number: -2137813243
  49.   Drive Share Name: Unavailable
  50.   Total Size of Drive: 32,472,576 bytes
  51.   Volume Name of Drive: FlashDisk
  52. --------------------------------------------
  53. --------------------------------------------
  54. Drive Letter: C (Single Drive)
  55.   Available Space: 49,298,620,416 bytes
  56.   Drive Type: Fixed
  57.   File System: NTFS
  58.   Free Space: 49,298,620,416 bytes
  59.   Is Drive Ready?: Yes
  60.   Drive Path: C:
  61.   Root Folder: C:\
  62.   Drive Serial Number: 350880761
  63.   Drive Share Name: Unavailable
  64.   Total Size of Drive: 61,483,933,696 bytes
  65.   Volume Name of Drive: Dezii
  66. --------------------------------------------
Jan 31 '08 #1
7 8870
FishVal
2,653 Recognized Expert Specialist
Hello, ADezii.

IMHO "Windows Script Host Object Model" library (\WINDOWS\syste m32\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
Jan 31 '08 #2
ADezii
8,834 Recognized Expert Expert
Hello, ADezii.

IMHO "Windows Script Host Object Model" library (\WINDOWS\syste m32\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).
Feb 1 '08 #3
dima69
181 Recognized Expert New Member
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.
Feb 2 '08 #4
ADezii
8,834 Recognized Expert Expert
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?
Feb 2 '08 #5
dima69
181 Recognized Expert New Member
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.
Feb 2 '08 #6
FishVal
2,653 Recognized Expert Specialist
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
Feb 2 '08 #7
ADezii
8,834 Recognized Expert Expert
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.
Feb 3 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

17
4219
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 won't be broken when my app is opened with those versions. Also is the Scripting Runtime included as part of the A2000 Runtime Engine which some of my customers use.
1
2346
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 won't be broken when my app is opened with those versions. Also is the Scripting Runtime included as part of the A2000 Runtime Engine which some of my customers use.
8
3765
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 the equivalent of a "CompareMethod" for the Collection object as for the Dictionary object?
1
1013
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. Got this error when I tried to run a very basic page... code: <%@ LANGUAGE=vbscript %> <%
4
25275
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. From an IE browser, you can access the virtual directory without a problem. However, when referencing the virtual diretory in an asp page, the following error is received: Microsoft VBScript runtime error '800a004c'
2
15814
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 environment using Microsoft Application Center. This was working before and starting throwing this error about 15 days ago. any help would be much appreciated thanks
0
5163
ADezii
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 methods to retrieve information from and how to manipulate them. The code should be self explanatory and basically documents itself. Should there be any questions related to this Topic, please feel free to ask. 'Accessing Folder Properties Dim...
0
5425
ADezii
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 various Methods to Copy, Move, and Delete them. The code is self explanatory, so I'll jump right in: Dim fso As FileSystemObject, fil As File 'Set fso = New Scripting.FileSystemObject OR Set fso = CreateObject("Scripting.FileSystemObject") ...
0
4471
ADezii
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 time, the Scripting Library cannot deal with the opening and manipulation of Files in Binary Mode, so we will only demonstrate this functionality as it relates to Text Files. The code is fairly straightforward and sparsely commented, so I will not bore...
0
9799
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11173
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10770
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10875
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10432
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.