سلام بر برنامه نویسان عزیز با یه کد سی شارپ دیگه در خدمتتون هستم.امیدوارم که از این استفاده کافی رو ببرید.خب روی پروژه تون راست کلیک بکنید و Add Reference و در تب مربوط به COM مورد Windows Script Host Object Model رو اضافه کنین.بعد از اون هم کد زیر رو به برنامه تون اضافه کنین.
using IWshRuntimeLibrary;
public static void CreateShortcut(string destination)
{
WshShell wshShell = new WshShell();
object destFolder = (object)destination;
string fileName = Path.Combine(
(string)wshShell.SpecialFolders.Item(ref destFolder),
"Notepad.lnk"
);
IWshShortcut shortcut =
(IWshShortcut)wshShell.CreateShortcut(fileName);
shortcut.TargetPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.System),
"notepad.exe"
);
shortcut.WorkingDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Personal);
shortcut.Description = "Notepad Text Editor";
shortcut.Hotkey = "CTRL+ALT+N";
//configure notepad to always start maximized
shortcut.WindowStyle = 3;
// Configure the shortcut to display the first icon in Notepad.exe.
shortcut.IconLocation = "notepad.exe, 0";
shortcut.Save();
}
نحوه استفاده :
CreateShortcut("Desktop");
CreateShortcut("StartMenu");
public static void CreateShortcut(string destination)
{
WshShell wshShell = new WshShell();
object destFolder = (object)destination;
string fileName = Path.Combine(
(string)wshShell.SpecialFolders.Item(ref destFolder),
"Notepad.lnk"
);
IWshShortcut shortcut =
(IWshShortcut)wshShell.CreateShortcut(fileName);
shortcut.TargetPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.System),
"notepad.exe"
);
shortcut.WorkingDirectory =
Environment.GetFolderPath(Environment.SpecialFolder.Personal);
shortcut.Description = "Notepad Text Editor";
shortcut.Hotkey = "CTRL+ALT+N";
//configure notepad to always start maximized
shortcut.WindowStyle = 3;
// Configure the shortcut to display the first icon in Notepad.exe.
shortcut.IconLocation = "notepad.exe, 0";
shortcut.Save();
}
نحوه استفاده :
CreateShortcut("Desktop");
CreateShortcut("StartMenu");
پیروز و سربلند باشید.