Solved

Scripting not working

Posted on 2014-01-07
5
562 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help parsing JSON in my VB.Net application 4 43
asp.net mvc input file 2 32
Need a complete list of ASP.NET page load events 3 26
Run time Error 4 34
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now