Solved

Scripting not working

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

636 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