Advertisement

04.09.2008 at 11:25AM PDT, ID: 23309188
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Recursive Search Remote Computer

Asked by DaleHarris in Visual Studio

Tags: ,

I'm working with a program to search computers on my network for unwanted files.  I have gotten this code to work (albeit with a bit of tweaking) the way I want.  My next step is to search a remote computer by IP or computer name.  This should be fairly straightforward, but I couldn't figure it out.


The line
' Start with drives if you have to search the entire computer.
        Dim drives As String() = System.Environment.GetLogicalDrives()

Does the local computer only.  I'm pretty sure I will either need to tweak this line, or something before hand to let it know which computer to run the search on.

Any ideas?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Public Class RecursiveFileSearch 
    Shared log As New System.Collections.Specialized.StringCollection() 
    
    Public Shared Sub StartSearch() 
        ' Start with drives if you have to search the entire computer. 
        Dim drives As String() = System.Environment.GetLogicalDrives() 
        
        For Each dr As String In drives 
            Dim di As New System.IO.DriveInfo(dr) 
            
            ' Here we skip the drive if it is not ready to be read. This 
            ' is not necessarily the appropriate action in all scenarios. 
            If Not di.IsReady Then 
                Console.WriteLine("The drive {0} could not be read", di.Name) 
                Continue For 
            End If 
            Dim rootDir As System.IO.DirectoryInfo = di.RootDirectory 
            WalkDirectoryTree(rootDir) 
        Next 
        
        ' Write out all the files that could not be processed. 
        Console.WriteLine("Files with restricted access:") 
        For Each s As String In log 
            Console.WriteLine(s) 
        Next 
        ' Keep the console window open in debug mode. 
        Console.WriteLine("Press any key") 
        Console.ReadKey() 
    End Sub 
    
    Private Shared Sub WalkDirectoryTree(ByVal root As System.IO.DirectoryInfo) 
        Dim files As System.IO.FileInfo() = Nothing 
        Dim subDirs As System.IO.DirectoryInfo() = Nothing 
        
        ' First, process all the files directly under this folder 
        Try 
            files = root.GetFiles("*.*") 
        Catch e As UnauthorizedAccessException 
            ' This is thrown if even one of the files requires permissions greater 
            ' than the application provides. 
            ' This code just writes out the message and continues to recurse. 
            ' You may decide to do something different here. For example, you 
            ' can try to elevate your privileges and access the file again. 
            log.Add(e.Message) 
        Catch e As System.IO.DirectoryNotFoundException 
            
            Console.WriteLine(e.Message) 
        End Try 
        
        If files IsNot Nothing Then 
            For Each fi As System.IO.FileInfo In files 
                ' In this example, we only access the existing FileInfo object. If we 
                ' want to open, delete or modify the file, then 
                ' a try-catch block is required here to handle the case 
                ' where the file has been deleted since the call to TraverseTree(). 
                Console.WriteLine(fi.FullName) 
            Next 
            
            ' Now find all the subdirectories under this directory. 
            subDirs = root.GetDirectories() 
            
            For Each dirInfo As System.IO.DirectoryInfo In subDirs 
                ' Resursive call for each subdirectory. 
                WalkDirectoryTree(dirInfo) 
            Next 
        End If 
    End Sub 
End Class
[+][-]04.09.2008 at 03:22PM PDT, ID: 21319670

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 12:03AM PDT, ID: 21322332

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.10.2008 at 03:54AM PDT, ID: 21323368

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Studio
Tags: VB.Net 2005, VS.Net 2005
Sign Up Now!
Solution Provided By: McExp
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.10.2008 at 04:49AM PDT, ID: 21323631

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628