//这里的WshShell是一个接口,但是这里居然可以用new??
//WshShell shell = new WshShell();
//IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("快捷方式安装的路径" +"快捷方式的名称"+ ".lnk");
//快捷方式安装路径,可以是下面几种路径:
//(1)Environment.GetFolderPath(Environment.SpecialFolder.Desktop),表示在桌面安装快捷方式
//(2)Environment.GetFolderPath(Environment.SpecialFolder.Programs),表示在开始菜单程序中添加快捷方式
//注意,可以在“快捷方式名称”前加上一个路径,这样在开始,程序中生成时加的路径将会是一个组的形式出现
//一定要确保创建快捷方式的路径是一个有效的路径,否则运行时会报错
//====
//快捷方式的名称:
//是指我们指定的要生成快捷方式的名称
//======
//(1)Arguments Property |
//快捷方式指向应用程序接受命令行参数串;格式视具体的应用程序而异;
//
//Description Property |
//创建快捷方式图标的描述性信息(当鼠标停留在快捷方式时给出的提示信息)
//
//(2)FullName Property (WshShortcut Object) |
//The FullName property contains a read-only string value indicating the fully qualified path to the shortcut's target.
//这个属性包含一个只读的字符串值,这个值表示快捷方式目标程序的完全限定路径;
//
//(3)Hotkey Property |
//指定当前快捷方式运行的快捷键
//The syntax of strHotkey is:[KeyModifier]KeyName
// KeyModifier
// Can be any one of the following: ALT+, CTRL+, SHIFT+, EXT+.
// Note:
// EXT+ means "Extended key." — it appears here in case a new type of SHIFT-key
// is added to the character set in the future.
// KeyName
// a ... z, 0 ... 9, F1 F12, ...
// The KeyName is not case-sensitive.
//
//(4)IconLocation Property |
//A string that locates the icon. The string should contain a fully qualified path and an index associated with the icon.
//一个定位图标的字符串。这个字符串应该包含该图标的完整限定路径和索引
//NOTE
//In Windows, EXE and DLL files can contain one or more icons,
//在Windows操作系统中,EXE和DLL文件可以包含一个或更多的图标,
//which are counted from 0.
//这些图标从0开始计数。
//Alternatively, you can use icon libraries such as Moricons.dll and Shell32.dll in the Windows folder or in the \System subfolder.
//另外,你可以使用Windows目录或System子目录下的图标库,例如:Moricons.dll和Shell32.dll。
//Keep in mind, however, that the location of those files depends on the operating system.
//然而,请注意,这些图标库文件是依赖于具体的操作系统的。
//In Windows 2000, the files are in the \System32 subfolder,
//在Windows 2000操作系统中,这些文件是在\System32子目录下,
//and in Windows 95 and Windows 98 they're in the Windows folder and the \System subfolder.
//而,在Windows 95和 Windows 98操纵系统中,他们分别在Windows目录和\System子目录下
//You can also assign the path to a .bmp or .ico file to the IconLocation property.
//你也可以用一个.ico或.bmp文件的路径赋值给IconLocation属性。
//
//(5)RelativePath Property |
//快捷方式所在目录的相对路径。
//如:所在目录路径为“C:\aa\bb\cc\a.lnk”,那么a.lnk的相对路径就是“C:\aa\bb\cc\”
//主要作用是,可以简化CreateShortcut方法中的路径。
//
//(6)TargetPath Property |
//This property is for the shortcut's target path only.
//这个属性是用于给出快捷方式的目标应用程序的路径。
//Any arguments to the shortcut must be placed in the Argument's property.
//任何要传递给目标程序的参数,都要放在Argument属性中。
//
//(7)WindowStyle Property |
//The WindowStyle property returns an integer.
//The following table lists the available settings for intWindowStyle.
//1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
//3 Activates the window and displays it as a maximized window.
//7 Minimizes the window and activates the next top-level window.
//
//(8)WorkingDirectory Property
//Assign a working directory to a shortcut, or identifies the working directory used by a shortcut.
//Applications use this directory to store temporary files and other files.
try
{
WshShell shell = new WshShell();//可能是.net对com的封装可以对个做出正确的反应
string desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(System.IO.Path.Combine(desktopDir, "test.lnk"));
shortcut.Description = "This is test";
shortcut.TargetPath = @"C:\Windows\System32\wscript.exe";
string currentAppDir = Application.StartupPath;
string currentIcoLibFilePath = @"C:\Windows\System32\Moricons.dll";// System.IO.Path.Combine(currentAppDir, "SomeLibWithIcons.dll");
shortcut.IconLocation = currentIcoLibFilePath + ",1";
shortcut.Save();
}
catch (Exception allE)
{
MessageBox.Show(allE.ToString());
}
//WshShell shell = new WshShell();
//IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut("快捷方式安装的路径" +"快捷方式的名称"+ ".lnk");
//快捷方式安装路径,可以是下面几种路径:
//(1)Environment.GetFolderPath(Environment.SpecialFolder.Desktop),表示在桌面安装快捷方式
//(2)Environment.GetFolderPath(Environment.SpecialFolder.Programs),表示在开始菜单程序中添加快捷方式
//注意,可以在“快捷方式名称”前加上一个路径,这样在开始,程序中生成时加的路径将会是一个组的形式出现
//一定要确保创建快捷方式的路径是一个有效的路径,否则运行时会报错
//====
//快捷方式的名称:
//是指我们指定的要生成快捷方式的名称
//======
//(1)Arguments Property |
//快捷方式指向应用程序接受命令行参数串;格式视具体的应用程序而异;
//
//Description Property |
//创建快捷方式图标的描述性信息(当鼠标停留在快捷方式时给出的提示信息)
//
//(2)FullName Property (WshShortcut Object) |
//The FullName property contains a read-only string value indicating the fully qualified path to the shortcut's target.
//这个属性包含一个只读的字符串值,这个值表示快捷方式目标程序的完全限定路径;
//
//(3)Hotkey Property |
//指定当前快捷方式运行的快捷键
//The syntax of strHotkey is:[KeyModifier]KeyName
// KeyModifier
// Can be any one of the following: ALT+, CTRL+, SHIFT+, EXT+.
// Note:
// EXT+ means "Extended key." — it appears here in case a new type of SHIFT-key
// is added to the character set in the future.
// KeyName
// a ... z, 0 ... 9, F1 F12, ...
// The KeyName is not case-sensitive.
//
//(4)IconLocation Property |
//A string that locates the icon. The string should contain a fully qualified path and an index associated with the icon.
//一个定位图标的字符串。这个字符串应该包含该图标的完整限定路径和索引
//NOTE
//In Windows, EXE and DLL files can contain one or more icons,
//在Windows操作系统中,EXE和DLL文件可以包含一个或更多的图标,
//which are counted from 0.
//这些图标从0开始计数。
//Alternatively, you can use icon libraries such as Moricons.dll and Shell32.dll in the Windows folder or in the \System subfolder.
//另外,你可以使用Windows目录或System子目录下的图标库,例如:Moricons.dll和Shell32.dll。
//Keep in mind, however, that the location of those files depends on the operating system.
//然而,请注意,这些图标库文件是依赖于具体的操作系统的。
//In Windows 2000, the files are in the \System32 subfolder,
//在Windows 2000操作系统中,这些文件是在\System32子目录下,
//and in Windows 95 and Windows 98 they're in the Windows folder and the \System subfolder.
//而,在Windows 95和 Windows 98操纵系统中,他们分别在Windows目录和\System子目录下
//You can also assign the path to a .bmp or .ico file to the IconLocation property.
//你也可以用一个.ico或.bmp文件的路径赋值给IconLocation属性。
//
//(5)RelativePath Property |
//快捷方式所在目录的相对路径。
//如:所在目录路径为“C:\aa\bb\cc\a.lnk”,那么a.lnk的相对路径就是“C:\aa\bb\cc\”
//主要作用是,可以简化CreateShortcut方法中的路径。
//
//(6)TargetPath Property |
//This property is for the shortcut's target path only.
//这个属性是用于给出快捷方式的目标应用程序的路径。
//Any arguments to the shortcut must be placed in the Argument's property.
//任何要传递给目标程序的参数,都要放在Argument属性中。
//
//(7)WindowStyle Property |
//The WindowStyle property returns an integer.
//The following table lists the available settings for intWindowStyle.
//1 Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position.
//3 Activates the window and displays it as a maximized window.
//7 Minimizes the window and activates the next top-level window.
//
//(8)WorkingDirectory Property
//Assign a working directory to a shortcut, or identifies the working directory used by a shortcut.
//Applications use this directory to store temporary files and other files.
try
{
WshShell shell = new WshShell();//可能是.net对com的封装可以对个做出正确的反应
string desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(System.IO.Path.Combine(desktopDir, "test.lnk"));
shortcut.Description = "This is test";
shortcut.TargetPath = @"C:\Windows\System32\wscript.exe";
string currentAppDir = Application.StartupPath;
string currentIcoLibFilePath = @"C:\Windows\System32\Moricons.dll";// System.IO.Path.Combine(currentAppDir, "SomeLibWithIcons.dll");
shortcut.IconLocation = currentIcoLibFilePath + ",1";
shortcut.Save();
}
catch (Exception allE)
{
MessageBox.Show(allE.ToString());
}