Pigeon
Pigeon

Reputation: 117

How to monitor Window Explorer active directories?

I am trying to monitor when the user try to access a certain directory like J:/ via window explorer. I read about Directory.GetCurrentDirectory but I really did not understand how to implement into my program. I also read about GetForegroundWindow from here. And I also read this website which I think it is the closest to what I need but his code did not work like I got nothing when I pressed the button to fetch the active windows, even after adding the "Microsoft Internet Control" reference. Using VS 2012 this is how I coded it:

SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();

string filename;

foreach ( SHDocVw.InternetExplorer ie in shellWindows )
{
    filename = Path.GetFileNameWithoutExtension( ie.FullName ).ToLower();

    if ( filename.Equals( "explorer" ) )
         MessageBox.Show( "Hard Drive : {0}", ie.LocationURL );
}

I am writing it wrong? Is there an easier way to do this? And I apologize in advance if I did any rookie mistakes

Upvotes: 1

Views: 198

Answers (1)

Akash KC
Akash KC

Reputation: 16310

Change your if-condition to :

if (filename.Equals("explorer"))
    MessageBox.Show( "Hard Drive : {0}", ie.LocationURL );

Upvotes: 1

Related Questions