|
|
|
|
|||||||||||||
|
ASP Kitchen: ASP.NET Articles: Accessing Drive Information Using ASP.NET Accessing Drive Information Using ASP.NETA Classic ASP article previously demonstrated how to use the Scripting.FileSystemObject object to access information on the drives attached to a web server. The code displays a list of drives attached to the machine, the drive type and whether the drive is available for use. Sample output from the script is shown below:
Following a great deal of experimentation, I have now converted the code presented in this article to be compatible with ASP.NET. Two different methods are described: using the Scripting.FileSystemObject object, and using Windows Management Instrumentation (WMI). Displaying Drive Information - Using Scripting.FileSystemObjectThe first attempt I made at converting the script to ASP.NET was to simply run through the Classic ASP VBScript version of the script line by line and simply fix any of the compilation errors I was sure Id encounter due to differences between VBScript and VB.NET. This worked well, with the main issues I encountered being:
The ASP.NET version of the script is shown below:
Although this script works, it relies on using the legacy Scripting.FileSystemObject object. I therefore decided to see if there was an alternative to the Scripting.FileSystemObject object within the .NET Framework. Displaying Drive Information - Using Windows Management InstrumentationBrowsing through the .NET Framework SDK it became apparent that the most appropriate alternative to using the Scripting.FileSystemObject object was to use Windows Management Instrumentation (WMI). WMI contains extensive facilities for managing Windows and the applications running on Windows machines. Amongst these are facilities for finding out about drives attached to the machine. The Directory.GetLogicalDrives method returns an array containing a list of the drive letters of drives attached to the machine. Once the drives have been determined, it is then possible to determine the drive type by retrieving the value of the DriveType property of the Win32_LogicalDisk WMI class. The WMI version of the script is shown below. The entire script should be saved as an .aspx page, although you could of course turn it into a control:
A list of drive type constants is available from the Microsoft website. The final part of the classic ASP script determined whether or not the drive was ready for use. Using WMI, this could potentially be determined by looking at the Availability, Status or StatusInfo properties. Unfortunately, all three of these properties are not defined in my development environment, so I have been unable to add this functionality to the script (a list of disk properties accessible to WMI can be displayed using this script in this section). Security SettingsDepending on the security settings on your server, you may not be able to access information using the System.Management namespace. To change this, you may need to add the following to the system.web part of the web.config file: <authentication mode="Windows"></authentication> <identity impersonate="true"></identity> Displaying a Complete Listing of Drive PropertiesDriveType is only one of a number of properties that can be returned for a drive. A complete list of properties is to be found on the Microsoft website. Alternatively, the following script will display a list of properties for a given drive:
Note that to get this script working, you may need to copy System.Management.dll to your web applications /bin folder. You might also need to modify permissions on the web files using the code, as well as altering security in IIS. There could be security implications in doing this, so do so at your own risk. Further reading
Author detailsBrett Burridge spent two years working in the University of Essex Computing Service, before moving to The Internet Applications Group in the Autumn of 1999, where he developed e-Business applications for a range of corporate clients and dot-com start ups. Brett is presently employed as an Internet developer and technical writer through his own company, Winnersh Triangle Web Solutions Limited. The company produces a number of innovative products, including the popular ASP Documentation Tool, Index Server Companion, .NET Documentation Tool and SQL Documentation Tool. As well as the ASPAlliance, Brett has written articles for Ariadne.ac.uk and ASPToday. Contact Brett by emailing
Article history"Accessing Drive Information Using ASP.NET" published on ASPAlliance.com on 20 March 2002. ASP Kitchen: ASP.NET Articles: Accessing Drive Information Using ASP.NET | |||||||||||||||
| Copyright © 2000-2003 ASPAlliance.com Page Rendered at
5/17/2008 7:34:09 AM |
|||||||||||||||