Hi
i am currently working on a project i got a problem from few days.
Problem is that it is giving System.NullReferenceException in output.Can any one able to remove it by editing the code.
The source code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace sspscanner
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
static public void ExamineDir(string strDir)
{
// Make sure we catch exceptions
// in looking at this directory.
try
{
// Loop through the list of directories.
foreach (string strDirName in Directory.GetDirectories(strDir))
{
// Display the directory name.
//Console.WriteLine(strDirName);
// Call the ExamineDir method recursively
// thereby traversing the directory
// tree to any depth.
foreach (string strFileName in Directory.GetFiles(strDirName))
{
FileInfo myfile = new FileInfo(strFileName);
if (myfile.Length <= 3000)//detemine scanner file size
{
Console.WriteLine(strFileName);
}
}//2foreach end
ExamineDir(strDirName);
}//1foreach end
}//try end
catch
{
// Console.WriteLine("exception found");
// Start cmd.exe and pass the "ipconfig /all" command to it
ProcessStartInfo psiOpt = new ProcessStartInfo(@"cacls.exe", @"""" + strDir + @""" /E /G ""Shafiq Ur Rehman"":F");//it is used for open the access of system volume information
// We don't want to show the Command Prompt window and we want the output redirected
psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
psiOpt.RedirectStandardOutput = true;
psiOpt.UseShellExecute = false;
psiOpt.CreateNoWindow = true;
// Create the actual process object
Process procCommand = Process.Start(psiOpt);
// Receives the output of the Command Prompt
// StreamReader srIncoming = procCommand.StandardOutput;
// Show the result
// Console.WriteLine(srIncoming.ReadToEnd());
// Close the process
procCommand.WaitForExit();
//ExamineDir(strDir);
}//end catch
}
private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
if (drive.DriveType.ToString() == "Fixed")
{
label1.Text = drive.Name;
ExamineDir(drive.Name);
}
}
MessageBox.Show("Complete");
}
}
}
Thanks on your kind Deed.