Solved

Scripting not working

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

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 26

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

12 Experts available now in Live!

Get 1:1 Help Now