2009-03-05 4 views
0

Nous avons donc quelques applications (ou plus, on ne sait) écrites par quelqu'un qui a maintenant quitté, ces applications accèdent aux bases de données Microsoft Access stockées sur ce vieux PC de développeurs, qui lit à notre base de données SQL de production. Maintenant, pour suivre tous ces programmes, et à quelle heure ils sont exécutés, je voudrais garder un journal d'un temps d'accès aux fichiers, est-ce possible? Évidemment, si je lis le temps d'accès, je le modifierais. Nous ne pouvons pas compter sur l'heure modifiée, car certaines bases de données Access ne sont que des tables liées à la base de données SQL.Conserver un journal de l'heure d'accès aux fichiers

Préférez faire cela en C#, mais cela n'a pas d'importance. Juste besoin de traquer ce qui fonctionne où, une fois que je les ai trouvés, ils peuvent être modifiés.

Merci.

Répondre

1

http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx

public class Watcher 

{

public static void Main() 
{ 
Run(); 

} 

[PermissionSet(SecurityAction.Demand, Name="FullTrust")] 
public static void Run() 
{ 
    string[] args = System.Environment.GetCommandLineArgs(); 

    // If a directory is not specified, exit program. 
    if(args.Length != 2) 
    { 
     // Display the proper way to call the program. 
     Console.WriteLine("Usage: Watcher.exe (directory)"); 
     return; 
    } 

    // Create a new FileSystemWatcher and set its properties. 
    FileSystemWatcher watcher = new FileSystemWatcher(); 
    watcher.Path = args[1]; 
    /* Watch for changes in LastAccess and LastWrite times, and 
     the renaming of files or directories. */ 
    watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite 
     | NotifyFilters.FileName | NotifyFilters.DirectoryName; 
    // Only watch text files. 
    watcher.Filter = "*.txt"; 

    // Add event handlers. 
    watcher.Changed += new FileSystemEventHandler(OnChanged); 
    watcher.Created += new FileSystemEventHandler(OnChanged); 
    watcher.Deleted += new FileSystemEventHandler(OnChanged); 
    watcher.Renamed += new RenamedEventHandler(OnRenamed); 

    // Begin watching. 
    watcher.EnableRaisingEvents = true; 

    // Wait for the user to quit the program. 
    Console.WriteLine("Press \'q\' to quit the sample."); 
    while(Console.Read()!='q'); 
} 

// Define the event handlers. 
private static void OnChanged(object source, FileSystemEventArgs e) 
{ 
    // Specify what is done when a file is changed, created, or deleted. 
    Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); 
} 

private static void OnRenamed(object source, RenamedEventArgs e) 
{ 
    // Specify what is done when a file is renamed. 
    Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath); 
} 

}

Questions connexes