|
using System;
using System.IO;
using LukeSw.IO;
namespace FileLockerApplication
{
class Program
{
static void Main()
{
Console.WriteLine("Registering the application.");
try
{
FileLocker.Register();
}
catch (Exception e)
{
Console.WriteLine("Cannot register - cannot modify the registry.");
Console.WriteLine(e);
return;
}
Console.Write("Enter the filename: ");
string file = Console.ReadLine();
if (string.IsNullOrEmpty(file))
{
Console.WriteLine("Entered an empty string. Exiting.");
return;
}
try
{
Console.WriteLine("Creating/opening the file.");
using (FileStream fs = File.Open(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
Console.Write("You can try to delete the file. Then press the enter.");
Console.ReadLine();
using (FileLocker fl = new FileLocker(file))
{
Console.Write("Windows Explorer has been notifies about used file. Try to delete it now.");
Console.Write("Press enter to cancel the notification.");
Console.ReadLine();
}
}
}
catch (Exception e)
{
Console.WriteLine("Cannot create or lock the file.");
Console.WriteLine(e);
}
finally
{
Console.WriteLine("Unregistering the application.");
try
{
FileLocker.Unregister();
}
catch (Exception e)
{
Console.WriteLine("Cannot unregister - cannot modify the registry.");
Console.WriteLine(e);
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.