Solved

Scripting not working

Posted on 2014-01-07
5
574 Views
Last Modified: 2014-01-07
It seems that FileSystemObject doesn't exist anymore. Can someone help me fix this piece of code?

Imports Scripting

    Public Function getSystemUID() As String
        Dim enumerator As IEnumerator
        Dim clsid As New Guid("0D43FE01-F093-11CF-8940-00A0C9054228")
        Dim obj2 As FileSystemObject = DirectCast(Activator.CreateInstance(Type.GetTypeFromCLSID(clsid)), FileSystemObject)
        Dim str As String = ""
        Try
            enumerator = obj2.Drives.GetEnumerator
            Do While enumerator.MoveNext
                Dim current As drive = DirectCast(enumerator.Current, Drive)
                If ((current.DriveType = DriveTypeConst.Fixed) And current.IsReady) Then
                    str = (str & current.FileSystem)
                    Return (str & Conversions.ToString(current.SerialNumber))
                End If
            Loop
        Finally
            If TypeOf enumerator Is IDisposable Then
                TryCast(enumerator, IDisposable).Dispose()
            End If
        End Try
        Return str
    End Function

Open in new window

0
Comment
Question by:MacroShadow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:s_chilkury
ID: 39763139
Are you getting any specific error?

If so, please post that error here.
0
 
LVL 27

Author Comment

by:MacroShadow
ID: 39763164
Scripting doesn't import (doesn't show-up in intellisense and is underlined in red indicating an error (no correction suggestions)).

And since it won't import Scripting, FileSystemObject, drive and DriveTypeConst cause "is not declared. it may be inaccessible due to its protection level".
0
 
LVL 9

Assisted Solution

by:s_chilkury
s_chilkury earned 50 total points
ID: 39763173
You should add the Scripting from the reference to your project and then the Imports Scripting (with red error will disappear)
0
 
LVL 27

Author Comment

by:MacroShadow
ID: 39763305
You should add the Scripting from the reference to your project

Where would I find it?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 450 total points
ID: 39763307
As s_chilkury pointed to, you need to reference the Microsoft Scripting Runtime, but you probably already know that if you were using these classes in VB6.

However, the old reference to the Microsoft Scripting Runtime that you were used to does not appear by default in the .NET. You need to make sure to use the COM tab in the references window in order to see it and activate the reference. Depending on the version of Visual Studio that you use, if there is a CheckBox besides the dll, you need to take care of activating the CheckBox. Simply clicking OK after selecting the reference is not enough.

This being said since you are moving to .NET, try to use .NET classes instead of the old stuff you were using, specially for files, directories and drives.

.NET as a lot of classes to work with these, and since they are specialized, they offer much more possibilities.

Most of them are in the System.IO namespace.

You might want to give a look at FileInfo, DirectoryInfo and DriveInfo is you want to get information and work minimally with specific files (DriveInfo would take the place of Drive in your code, and if look at its properties, you see that you get a lot more right there).

If you want to work with the file system in general, then the File and Directory classes are your best bet.

If you want to read and write files, then come to the store. If you are going for text files, then StreamReader and StreamWrite are the workhorses. If you are into binary files, then BinaryReader and BinaryWrite. You might prefer XmlReader and XmlWriter.

These are the one used most often, there are a few others. Since each is designed for a specific type of work, they do a lot more than the simple TextStream of the FileSystemInfo stuff.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question