Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scripting not working

Posted on 2014-01-07
5
Medium Priority
?
600 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 200 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 1800 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

Industry Leaders: 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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

722 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