Why does this code not work.......


J

Jim

Hello,

I am writing an application to list all the sites viewed via internet
explorer and have created the following routine to read the history files to
a temporary file which is then used by the application. It seems to work
fine for the first file in the list, but then it blows up with an invalid
argument error when attempting to execute myProcess for the second file...
can someone tell me why this is happening?

Thanks!

Jim

Sub CreateTmpFile()
' INDEXFILES is an array loaded with all filenames on the
' computer which are index.dat internet explorer history files

Dim bHidden As Boolean = False

' Display an appropriate message
lblMessage.Text = "Scanning web viewing history files ...."
Application.DoEvents()

' now for the real time saver, creating a
' unique file name in .NET
sTempFN = "SomeFile.txt"

' Show the progress bar
ProgressBar1.Maximum = UBound(IndexFiles)

' loop through all the temporary file names
For x As Integer = 1 To UBound(IndexFiles)
' set the file name and the command line args
Dim myProcess As New Process
myProcess.StartInfo.FileName = "command.com"
myProcess.StartInfo.Arguments = "/c find " + Chr(34) + "://" +
Chr(34) + " " + Chr(34) + IndexFiles(x) + Chr(34) + " >> " + Chr(34) +
sTempFN + Chr(34)

' start the process in a hidden window
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()

' if the process doesn't complete within
' 20 seconds, kill it
myProcess.WaitForExit(20000)
If Not myProcess.HasExited Then
myProcess.Kill()
End If
myProcess = Nothing

' Increment the progress bar
ProgressBar1.Value = x
Next

' Check that the temporary file exists
Dim dir As New DirectoryInfo(sTempFN)
If Not dir.Exists Then
'MsgBox("For some odd reason, " & sTempFN & " does not exist:" +
vbCrLf + vbCrLf + sTempFN + vbCrLf + vbCrLf + "Unfortunately, no surfing
history can be tracked.", vbOKOnly, "Exiting (code=0)")
End If
dir = Nothing
End Sub
 
Ad

Advertisements

S

scorpion53061

Jim,

Put a try ...Catch ex as Exception in and do a trace, take note of the
line the error occurred and report the error that is given.
 
J

Jim

I figured out that the error is occurring in the Process.Start function. Is
there another way, within VB.NET to perform the same task as the DOS FIND
command that is being shelled to via the Process in my example?

Thanks!

Jim
 
S

scorpion53061

find "hope" *.txt =

This would search for any text file (.txt) that contains the text hope
in the current directory.

find /c "REM" c:\autoexec.bat =

Are you using a console app? If so use the Console.WriteLine command.



This would find any "REM" statement in the autoexec.bat.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top