C # language has a lot to learn, here we mainly introduce C # Setup shortcuts, including the introduction of building shortcuts and flexible shortcuts to simplify the operation and so on.
First, we create a WshShell instance object, and then use the object's CreateShortcut method to create an instance object of the Iwshshortcut interface, passed to the CreateShortcut The parameter of the method is the full path of the shortcut that will be created, including the name of the shortcut. Next, we're going to set the value of the associated property for the Iwshshortcut instance object.
A. C # set the properties of a shortcut
1.TargetPath: This property is used only for the location of the target where C # sets the shortcut. In Code #01, the shortcut you want to create points to this application.
2.WorkingDirectory: This property specifies the working directory of the application, and when the user does not specify a specific directory, the target application of the shortcut will use the directory specified by the attribute to load or save the file.
3.WindowStyle: This property specifies that the window of the target application for the shortcut is a normal (original) state, minimized, or maximized.
4.Description: This property sets additional instructions for setting or reading the shortcut.
5.IconLocation: This property is used to specify the location of the shortcut's chart, and its value contains a full path and an index value. In Code #01, the icon for the shortcut is set to the 165th icon contained in the Shell32.dll file in the system folder.
Two. Generate shortcuts
CreateShortcut just creates a Iwshshortcut instance object that doesn't generate any shortcuts for you, and when it's all ready, you have to call the Iwshshortcut.save method to generate the shortcut file.
Three. Simplify operation with shortcuts
Imagine that your application supports a combination of command-line arguments, such as: App/out:output.txt/sortby:date/desc
And you want to simply press CTRL+ALT+F11 to start this function directly, you need to use the Iwshshortcut Arguments and Hotkey two attributes:
shortcut.Arguments = "/out:output.txt /sortby:date /desc";
shortcut.Hotkey = "CTRL+ALT+F11";
Note: The value of the Hotkey property cannot contain spaces.
You can handle command-line arguments as usual in your application:
class Program
{
static void Main(string[] args)
{
foreach (string arg in args)
{
Console.WriteLine(arg);
}
}
}
// Output:
//
// /out:output.txt
// /sortby:date
// /desc