The path is not of a legal form - SystemArgumentException error

  • Thread starter Thread starter John2000k
  • Start date Start date
J

John2000k

Guest
Hello.

I'm building an application(anti-virus) which searches for files in various folders of the computer. It contains a database of MD5 hashes(virus hashes) which is used to compare them with the ones present of the computer. I'm using a backgroundworker to do the task(scan process), however it seems that my software doesn't get access(most likely) to various folders like the Windows folder/system32 folder, etc. I'm the system administrator, I've tried running it that way, also I've changed the application's manifest from "invoker" to "requireAdministrator" with no luck. Other folders (like desktop, etc) work fine with the code below:

Code for BackgroundWorker_DoWork:



Dim worker As System.ComponentModel.BackgroundWorker = CType(sender, System.ComponentModel.BackgroundWorker)
Dim folder As String = "" & TextBox1.Text & ""
Try
For Each file As String In My.Computer.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories)
Try
Dim scanbox As New TextBox
Dim read As String = My.Computer.FileSystem.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory & "viruslist.txt")
scanbox.Text = read.ToString
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
Dim f As FileStream = New FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
f = New FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
md5.ComputeHash(f)
Dim hash As Byte() = md5.Hash
Dim buff As StringBuilder = New StringBuilder
Dim hashByte As Byte
For Each hashByte In hash
buff.Append(String.Format("{0:X2}", hashByte))
Next

If scanbox.Text.Contains(buff.ToString) Then
AddListItem(ListBox1, "" & file & " - Virus")
AddListItem2(ListBox2, "" & file & "")
End If
Catch ex As Exception
End Try
SetLabelText_ThreadSafe(Me.Label1, "" & file & "")
If (BackgroundWorker1.CancellationPending = True) Then

e.Cancel = True
Exit For
End If
SetLabelText_ThreadSafe(Me.Label1, "Scanning: " & file & "")
int = int + 1
SetLabelText_ThreadSafe(Me.Label2, "Number Of Files Scanned: " & int & " Out Of " & filecount & "")
Dim pct As Integer = CInt(int / filecount * 100)
BackgroundWorker1.ReportProgress(pct)
Next file
Catch ex As UnauthorizedAccessException
End Try


I get the error on this one :

For Each file As String In My.Computer.FileSystem.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories)


On debug, the error is like that:

Exception thrown: 'System.ArgumentException' in mscorlib.dll An exception of type 'System.ArgumentException' occurred in mscorlib.dll but was not handled in user code The path is not of a legal form.

I use a listbox to first list the files waiting to be scanned by the software, and the listing works fine, even for the Windows folder. The problem is that it does not check through them, resulting in the "SystemArgumentException" error.





Continue reading...
 
Back
Top