Time to delete |
Written by Harry Fairhead | |||||||
Saturday, 11 July 2009 | |||||||
Page 2 of 6
Getting startedStart a new C# project called “TimeDelete”. You should be able to use any Express or full edition of Visual Studio as no recent .NET features are used. For the same reason conversion to any other language is very easy. Switch to the form editor and add three buttons with the captions “Install/Repair Time delete”. “Delete Time Expired Files” and “Exit”.
The first code to create is the installation procedure which simply adds a shortcut to the correct directory targeting the running version of the program. We need the location of the Send To directory for the current user and the current directory where the executable is stored – and both are remarkably easy to get, with the help of the Environment class: private void button1_Click( Now we are ready to create the shortcut – but there is a problem. Even though there are lots of helpful classes in the .NET Framework there doesn’t seem to be one that lets you work with shortcuts. There are a number of solutions to this problem, including using pInvoke to call low-level API functions, but arguably the simplest is to use an ActiveX class library that is generally available as part of the Scripting support (for both JScript and VBScript). To use it first load a reference to a COM object - Windows Script Host Object – and add: using IWshRuntimeLibrary; Now we can create a shortcut in exactly the same way that we would using VBScript or JScript. First create a WhsShell object: WshShellClass WshS = new WshShellClass(); At this point we have added a shortcut that adds the TimeDelete option to the SendTo menu. Before moving on to the next stage it’s worth creating the code for the Exit button but the button that actually does the delete is easier to understand after a description how the rest of the program works: private void button2_Click( The new SendTo menu item <ASIN:0735621632> <ASIN:0321485890> <ASIN:0321245660>
|
|||||||
Last Updated ( Saturday, 11 July 2009 ) |