public SectionResponseEnum Execute(PackageClass packageClass, ActionItem actionItem) { if (ItemProcessed != null) ItemProcessed(this, new InstallEventArgs("Create ShortCut")); try { UnInstallItem unInstallItem = packageClass.UnInstallInfo.BackUpFile(actionItem.Params[Const_Loc].GetValueAsPath(), "CopyFile"); WshShellClass wshShell = new WshShellClass(); // Create the shortcut IWshShortcut myShortcut = (IWshShortcut)wshShell.CreateShortcut(actionItem.Params[Const_Loc].GetValueAsPath()); myShortcut.TargetPath = Path.GetFullPath(actionItem.Params[Const_Target].GetValueAsPath()); myShortcut.WorkingDirectory = Path.GetDirectoryName(myShortcut.TargetPath); myShortcut.Description = actionItem.Params[Const_Description].Value; if (!string.IsNullOrEmpty(actionItem.Params[Const_Icon].Value)) myShortcut.IconLocation = actionItem.Params[Const_Icon].GetValueAsPath(); else myShortcut.IconLocation = actionItem.Params[Const_Target].GetValueAsPath(); myShortcut.Save(); FileInfo info = new FileInfo(actionItem.Params[Const_Loc].GetValueAsPath()); unInstallItem.FileDate = info.CreationTimeUtc; unInstallItem.FileSize = info.Length; packageClass.UnInstallInfo.Items.Add(unInstallItem); } catch (Exception) {} return SectionResponseEnum.Ok; }
private void MakeShortcut(string path, string shortcutDirectory) { var wsh = new WshShellClass(); var shortcut = wsh.CreateShortcut(Path.ChangeExtension(shortcutDirectory, ".lnk")) as IWshShortcut; shortcut.TargetPath = path; shortcut.Save(); }
private void button1_Click(object sender, EventArgs e) { try { WshShellClass WshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortCut = default(IWshRuntimeLibrary.IWshShortcut); shortCut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(folderBrowserDialog1.SelectedPath + "\\" + shortCutNameTextBox.Text + ".lnk"); // shortcut properties shortCut.TargetPath = Application.ExecutablePath; shortCut.WindowStyle = 1; if(snapRadioButton.Checked) { shortCut.Description = "Grab a snap shot from current screen using ScreenGrabber."; // the next line sets a new argument so the program will know next time // that the user only want to grab the screen // which will be read from the command line. shortCut.Arguments = "snap"; } else shortCut.Description = "Launch ScreenGrabber."; shortCut.WorkingDirectory = folderBrowserDialog1.SelectedPath; // the next line gets the first Icon from the executing program shortCut.IconLocation = Application.ExecutablePath + ", 0"; shortCut.Save(); pathLabel.Text = "Shortcut saved successfuly at:" + Environment.NewLine + folderBrowserDialog1.SelectedPath + "\\" + shortCutNameTextBox.Text + ".lnk"; } catch(Exception ex) { MessageBox.Show("There were a problem saving your Shortcut.\n\n"+ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void CreateDirectoryShortcut(string targetPath, string whereToPutItPath) { var name = Path.GetFileName(targetPath); var WshShell = new WshShellClass(); string linkPath = Path.Combine(whereToPutItPath, name) + ".lnk"; if(File.Exists(linkPath)) { File.Delete(linkPath); } var shortcut = (IWshShortcut)WshShell.CreateShortcut(linkPath); try { shortcut.TargetPath = targetPath; //shortcut.Description = "Launch My Application"; //shortcut.IconLocation = Application.StartupPath + @"\app.ico"; } catch (Exception error) { if (targetPath !=System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(targetPath))) throw new ApplicationException("Unfortunately, windows had trouble making a shortcut to remember this project, because of a problem with non-ASCII characters. Sorry!"); throw error; } shortcut.Save(); }
private static bool Create(string shortcutPath, string targetPath, string arguments = "") { if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath)) { Delete(shortcutPath); try { IWshShell wsh = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath); shortcut.TargetPath = targetPath; shortcut.Arguments = arguments; shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); shortcut.Save(); return true; } catch (Exception e) { DebugHelper.WriteException(e); } } return false; }
public static void CreateDirectoryShortcut(string targetPath, string whereToPutItPath) { var name = Path.GetFileName(targetPath); var linkPath = Path.Combine(whereToPutItPath, name) + ".lnk"; var shortLinkPath = ""; if(RobustFile.Exists(linkPath)) RobustFile.Delete(linkPath); #if !__MonoCS__ var wshShell = new WshShellClass(); var shortcut = (IWshShortcut)wshShell.CreateShortcut(linkPath); try { shortcut.TargetPath = targetPath; } catch (Exception) { if (targetPath == Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(targetPath))) throw; // this exception was caused by non-ascii characters in the path, use 8.3 names instead var shortTargetPath = new StringBuilder(MAX_PATH); GetShortPathName(targetPath, shortTargetPath, MAX_PATH); var shortWhereToPutPath = new StringBuilder(MAX_PATH); GetShortPathName(whereToPutItPath, shortWhereToPutPath, MAX_PATH); name = Path.GetFileName(shortTargetPath.ToString()); shortLinkPath = Path.Combine(shortWhereToPutPath.ToString(), name) + ".lnk"; if (RobustFile.Exists(shortLinkPath)) RobustFile.Delete(shortLinkPath); shortcut = (IWshShortcut)wshShell.CreateShortcut(shortLinkPath); shortcut.TargetPath = shortTargetPath.ToString(); } shortcut.Save(); // now rename the link to the correct name if needed if (!string.IsNullOrEmpty(shortLinkPath)) RobustFile.Move(shortLinkPath, linkPath); #else // It's tempting to use symbolic links instead which would work much nicer - iff // the UnixSymbolicLinkInfo class wouldn't cause us to crash... // var name = Path.GetFileName(targetPath); // string linkPath = Path.Combine(whereToPutItPath, name); // var shortcut = new Mono.Unix.UnixSymbolicLinkInfo(linkPath); // if (shortcut.Exists) // shortcut.Delete(); // // var target = new Mono.Unix.UnixSymbolicLinkInfo(targetPath); // target.CreateSymbolicLink(linkPath); RobustFile.WriteAllText(linkPath, targetPath); #endif }
public static void DeleteShortcut(SpecialFolders specialFolder, string name) { WshShell ws = new WshShellClass(); string path = GetShortcutPath(ws, specialFolder, name); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } }
static void Shortcut(String source, String dest, String description="") { WshShell wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(dest); shortcut.Arguments = "."; shortcut.TargetPath = source; shortcut.Save(); }
public static void CreateShortcut(this IEnumerable<DirectoryInfo> directories, string rootFolder) { var wshShellClass = new WshShellClass(); foreach (var directoryInfo in directories) { var shortcut = wshShellClass.CreateShortcut(Path.Combine(rootFolder, string.Format("{0}.lnk", directoryInfo.Name))) as IWshShortcut; shortcut.TargetPath = directoryInfo.FullName; shortcut.Save(); } }
/// <summary> /// Follows a shortcut file programmatically /// </summary> /// <param name="path"></param> /// <returns></returns> public static string ResolveLink(string path) { try { IWshShell wsh = new WshShellClass(); IWshShortcut sc = (IWshShortcut)wsh.CreateShortcut(path); return sc.TargetPath; } catch { } return ""; }
static void Main(string[] args) { if (args.Length == 1) { if (args[0] == "/u") { try { IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StartGlashFish.lnk"); IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StopGlashFish.lnk"); IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MySql.lnk"); } catch(Exception ex) { } } } else { WshShell = new WshShellClass(); // Create the shortcut IWshRuntimeLibrary.IWshShortcut MyShortcut; // Choose the path for the shortcut string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StartGlashFish.lnk"; MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path); // Where the shortcut should point to MyShortcut.TargetPath = @"c:\nolis\appdesigner\startglassfish.exe"; // Description for the shortcut // Create the shortcut at the given path MyShortcut.Save(); WshShell = new WshShellClass(); // Create the shortcut // Choose the path for the shortcut path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StopGlashFish.lnk"; MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path); // Where the shortcut should point to MyShortcut.TargetPath = @"c:\nolis\appdesigner\stopglassfish.exe"; // Description for the shortcut // Create the shortcut at the given path MyShortcut.Save(); path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MySql.lnk"; MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path); // Where the shortcut should point to MyShortcut.TargetPath = @"c:\program files\MySql\MySql server 5.0\bin\MySql.exe"; MyShortcut.Arguments = "mysql -h localhost -u root -p"; // Description for the shortcut // Create the shortcut at the given path MyShortcut.Save(); } }
public static void Main(string[] args) { if (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")) { Console.WriteLine(usage); return; } object envType = "SYSTEM"; IWshEnvironment wshSysEnv = new WshShellClass().get_Environment(ref envType); wshSysEnv["TEST"] = "MyDirectory"; }
public static void CreateShortcut(SpecialFolders specialFolder, string name, string exePath) { WshShell ws = new WshShellClass(); string path = GetShortcutPath(ws, specialFolder, name); WshShortcut shortcut = ws.CreateShortcut(path) as WshShortcut; shortcut.TargetPath = exePath; shortcut.WindowStyle = 1; //shortcut.Hotkey = "CTRL+SHIFT+F"; shortcut.IconLocation = exePath + ", 0"; shortcut.Description = name; shortcut.WorkingDirectory = Path.GetDirectoryName(exePath); shortcut.Save(); }
public static void Make(string mySourcePath, string myDestPath) { //string path = Path.Combine(myDestPath, "sample_shortcut.lnk"); // // ショートカット作成 // IWshShell shell = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(myDestPath); shortcut.TargetPath = mySourcePath; shortcut.Description = "TEST"; shortcut.Save(); }
public static void CreateStartupFolderShortcut() { WshShellClass wshShell = new WshShellClass(); IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Create the shortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(startUpFolderPath, Application.ProductName + ".lnk")); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Save(); }
/// <summary> /// Creates a shortcut programatically, used for testing /// </summary> /// <param name="file"></param> /// <param name="target"></param> /// <param name="arguments"></param> /// <returns></returns> public static bool CreateLink(string file, string target, string arguments) { try { IWshShell wsh = new WshShellClass(); IWshShortcut sc = (IWshShortcut)wsh.CreateShortcut(file); sc.WorkingDirectory = Phantom.libraryPath; sc.TargetPath = Path.Combine(Phantom.libraryPath, target); sc.Arguments = arguments ?? ""; sc.Save(); } catch { } return(false); }
public void createShortcut(string gamePath) { WshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut GameShortcut; string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); GameShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Path.Combine(deskDir,title + ".lnk")); GameShortcut.TargetPath = Path.Combine(gamePath,file); GameShortcut.Description = title; GameShortcut.IconLocation = Path.Combine(gamePath,file); GameShortcut.WorkingDirectory = gamePath; GameShortcut.Save(); }
/// <summary> /// Creates a shortcut programatically, used for testing /// </summary> /// <param name="file"></param> /// <param name="target"></param> /// <param name="arguments"></param> /// <returns></returns> public static bool CreateLink(string file, string target, string arguments) { try { IWshShell wsh = new WshShellClass(); IWshShortcut sc = (IWshShortcut)wsh.CreateShortcut(file); sc.WorkingDirectory = API.Phantom.libraryPath; sc.TargetPath = Path.Combine(API.Phantom.libraryPath, target); sc.Arguments = arguments ?? ""; sc.Save(); } catch { } return false; }
private void button1_Click(object sender, EventArgs e) { this.Close(); SaveFileDialog dlgSaveFile = new SaveFileDialog(); //dlgSaveFile.InitialDirectory = Environment.GetEnvironmentVariable("SystemRoot"); dlgSaveFile.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dlgSaveFile.Filter = ".lnk file (*.lnk)|*.lnk"; dlgSaveFile.FileName = "Gekko.lnk"; DialogResult dlgResult = dlgSaveFile.ShowDialog(); string m_strFileName = null; m_strFileName = dlgSaveFile.FileName; if (dlgResult == DialogResult.Cancel) { return; } try { //laver en link-fil if (true) { // Create a new instance of WshShellClass WshShellClass WshShell = new WshShellClass(); // Create the shortcut IWshRuntimeLibrary.IWshShortcut MyShortcut; // Choose the path for the shortcut MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(m_strFileName); // Where the shortcut should point to MyShortcut.TargetPath = Application.StartupPath + "\\Gekko.exe"; // " + "display hejsa;display hovsa"; // Description for the shortcut MyShortcut.WorkingDirectory = Application.StartupPath; MyShortcut.Description = "Link to Gekko"; // Location for the shortcut's icon MyShortcut.IconLocation = Application.StartupPath + "\\Gekko.ico"; // Create the shortcut at the given path MyShortcut.Save(); G.Writeln("Short-cut to Gekko copied to your desktop folder"); } } catch (Exception err) { G.Writeln("*** ERROR when trying to write the gekko.lnk file to the desktop folder."); return; } G.Writeln("The gekko.lnk file was successfully created here: " + m_strFileName); G.Writeln(); }
private void button1_Click(object sender, EventArgs e) { WshShellClass wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Windows) + "\\" + textBox1.Text + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = System.IO.Path.GetFullPath(openFileDialog1.FileName); // not sure about what this is for shortcut.WindowStyle = 10; shortcut.Description = "Create customized Run command"; //shortcut.WorkingDirectory = "C:\\TURBOC3\\Turbo C++\\"; //shortcut.IconLocation = "RunCustomizer.ico"; shortcut.Save(); }
public Form0() { InitializeComponent(); WshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut MyShortcut; string link = (string)Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\GTS.lnk"; MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(link); MyShortcut.TargetPath = Application.ExecutablePath; MyShortcut.Description = "ГТС расчеты"; MyShortcut.IconLocation = Application.StartupPath + @"\Micon.ico"; MyShortcut.Save(); }
private static void CreateDesktopLnk(string cut, string target, string argument, string des, string working, string icon) { WshShell shell = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(cut); //输出路径 shortcut.TargetPath = target; //文件路径 shortcut.Arguments = argument; // 参数 shortcut.Description = des; //备注 shortcut.WorkingDirectory = working; //程序所在文件夹,在快捷方式图标点击右键可以看到此属性 shortcut.IconLocation = icon; //图标 shortcut.Hotkey = ""; shortcut.WindowStyle = 1; shortcut.Save(); }
internal void CreateShortcut(string sendToPath, string fullPath) { string fileName = Path.GetFileNameWithoutExtension(fullPath); IWshShortcut shortcut; if (WindowsVer.Is64BitOs()) { WshShell wshShell = new WshShell(); shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(sendToPath, fileName + ".lnk")); } else { WshShellClass wshShell = new WshShellClass(); shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(sendToPath, fileName + ".lnk")); } shortcut.TargetPath = fullPath; shortcut.IconLocation = fullPath; shortcut.Save(); }
public void CreateShortcut(string path, string filename, string args, string icon) { try { WshShellClass class2 = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)class2.CreateShortcut(path); shortcut.TargetPath = filename; shortcut.IconLocation = icon; shortcut.Arguments = args; shortcut.Save(); } catch (Exception ex) { Logger.Current.Write(ex,"Unable to create shortcut"); } }
private void CreateShotcut(string newPackageName) { string path = Application.StartupPath; WshShellClass wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + newPackageName + ".lnk") as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = "\"" + newPackageName + "\""; shortcut.TargetPath = path + "\\CDT.exe"; // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = newPackageName; shortcut.WorkingDirectory = path; shortcut.Save(); }
public void CreateShortcut(string path, string filename, string args, string icon) { try { WshShellClass class2 = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)class2.CreateShortcut(path); shortcut.TargetPath = filename; shortcut.IconLocation = icon; shortcut.Arguments = args; shortcut.Save(); } catch (Exception ex) { Logger.Current.Write(ex, "Unable to create shortcut"); } }
/// <summary> /// /// </summary> /// <param name="target"></param> /// <param name="folderName"></param> /// <param name="shortCutName"></param> /// <param name="description"></param> private void CreateShortcut(FileInfo target, string folderName, string shortCutName, string description) { Log("Start CreateShortcut"); try { DirectoryInfo startMenu = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu)); Log("CreateShortcut startmenu " + startMenu.FullName); if (!Directory.Exists(startMenu.FullName)) { Log("CreateShortcut no startmenu, aborting"); return; } DirectoryInfo shortCutFolder = startMenu; if (!string.IsNullOrEmpty(folderName)) { shortCutFolder = new DirectoryInfo(string.Format("{0}\\{1}", startMenu.FullName, folderName)); } Log("CreateShortcut shortcut folder " + shortCutFolder.FullName); if (!Directory.Exists(shortCutFolder.FullName)) { Log("CreateShortcut creating folder " + shortCutFolder.FullName); Directory.CreateDirectory(shortCutFolder.FullName); } FileInfo lnk = new FileInfo(string.Format("{0}\\{1}", shortCutFolder.FullName, shortCutName)); if (!string.Equals(".lnk", lnk.Extension, StringComparison.OrdinalIgnoreCase)) { lnk = new FileInfo(string.Format("{0}\\{1}.lnk", shortCutFolder.FullName, shortCutName)); } Log("CreateShortcut link " + lnk.FullName); if (File.Exists(lnk.FullName)) { File.Delete(lnk.FullName); } Log("CreateShortcut before shell"); WshShellClass shell = new WshShellClass(); Log("CreateShortcut before creating shortcut object"); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(lnk.FullName); Log("CreateShortcut before setting shortcut properties"); shortcut.TargetPath = target.FullName; shortcut.Description = description; shortcut.IconLocation = string.Format("{0},0", target.FullName); Log("CreateShortcut before save"); shortcut.Save(); } catch (Exception ex) { Log("Error creating shortcut: " + ex.Message); } Log("End CreateShortcut"); }
private void DeleteShortcuts() { // Just try and delete all possible shortcuts that may have been // created during install try { // This is in a Try block in case AllUsersDesktop is not supported object allUsersDesktop = "AllUsersDesktop"; WshShell shell = new WshShellClass(); string desktopFolder = shell.SpecialFolders.Item(ref allUsersDesktop).ToString(); DeleteShortcut(desktopFolder, ExecutiveShortcutName); } catch {} DeleteShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), ExecutiveShortcutName); string startMenu = null; try { object allUsersStartMenu = "AllUsersPrograms"; WshShell shell = new WshShellClass(); startMenu = shell.SpecialFolders.Item(ref allUsersStartMenu).ToString(); //DeleteShortcut(startMenu + "\\" + StartMenuFolderName,ShortcutName); } catch { } if (startMenu == null) { startMenu = Environment.GetFolderPath(Environment.SpecialFolder.Programs); } startMenu += "\\" + StartMenuFolderName; DeleteShortcut(startMenu, ExecutiveShortcutName); //DeleteShortcut(startMenu, HostlistShortcutName); ///Delete directory from start menu //DeleteShortcut(StartMenuFolderName, ShortcutName); try { Directory.Delete(startMenu); } catch (Exception ex) { MessageBox.Show(ex.Message); } DeleteShortcut(QuickLaunchFolder, ExecutiveShortcutName); }
void EnableAutostart(object sender, EventArgs e) { if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\WinPo.lnk")) { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Create the shortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(startUpFolderPath + "\\" + Application.ProductName + ".lnk"); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch WinPo"; // shortcut.IconLocation = Application.StartupPath + @"\App.ico"; shortcut.Save(); } }
/* public static void CreateShortcut(string target, string path, string description, string arguments) * { * if (target.IsNullOrEmpty() || path.IsNullOrEmpty()) * return; * * WshShellClass WSClass = new WshShellClass(); * IWshShortcut IWShortcut; * IWShortcut = (IWshShortcut)WSClass.CreateShortcut(path); * * string target_dir = Asmodat.IO.Files.GetDirectory(target); * * IWShortcut.TargetPath = target; * IWShortcut.WorkingDirectory = target_dir;// Application.StartupPath; * * if(!description.IsNullOrEmpty()) IWShortcut.Description = description; * if (!arguments.IsNullOrEmpty()) IWShortcut.Arguments = arguments; * * Asmodat.IO.Files.Delete(path); * IWShortcut.Save(); * }*/ public static void CreateStartupFolderShortcut() { WshShellClass WSClass = new WshShellClass(); IWshShortcut IWShortcut; string directory = Environment.GetFolderPath(Environment.SpecialFolder.Startup); string path = directory + @"\" + Application.ProductName + ".lnk"; IWShortcut = (IWshShortcut)WSClass.CreateShortcut(path); IWShortcut.TargetPath = Application.ExecutablePath; IWShortcut.WorkingDirectory = Application.StartupPath; IWShortcut.Description = "This is a startup shortcut."; IWShortcut.Arguments = "/a /c"; Asmodat.IO.Files.Delete(path); IWShortcut.Save(); }
private static void Delete(DirectoryInfo di, string xmlName) { string fileFullPath = di.FullName + Path.DirectorySeparatorChar + xmlName; if (System.IO.File.Exists(fileFullPath)) { try { FileSystem.DeleteFile(fileFullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } catch (Exception ex) { Console.WriteLine("The following file cannot be deleted. "); Console.WriteLine(fileFullPath); Console.WriteLine("Error: " + ex.Message); Console.WriteLine(); } foreach (DirectoryInfo sub_di in di.GetDirectories()) { Delete(sub_di, xmlName); } foreach (FileInfo fi in di.GetFiles()) { if (fi.FullName.EndsWith(".lnk")) { try { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(fi.FullName); string folderPath = shortcut.TargetPath; if (Directory.Exists(folderPath)) { Delete(new DirectoryInfo(folderPath), xmlName); } } catch (Exception ex) { } } } } }
private static bool Create(string shortcutPath, string targetPath, string arguments = "") { if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath)) { Delete(shortcutPath); IWshShell wsh = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath); shortcut.TargetPath = targetPath; shortcut.Arguments = arguments; shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); shortcut.Save(); return(true); } return(false); }
private static void CreateShortcut(string folder, string name, string target, string description) { string shortcutFullName = Path.Combine(folder, name + ".lnk"); try { WshShell shell = new WshShellClass(); IWshShortcut link = (IWshShortcut)shell.CreateShortcut(shortcutFullName); link.TargetPath = target; link.Description = description; link.Save(); } catch (Exception ex) { MessageBox.Show(string.Format("The shortcut \"{0}\" could not be created.\n\n{1}", shortcutFullName, ex.ToString()), "Create Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static void CreateDirectoryShortcut(string targetPath, string whereToPutItPath) { var name = Path.GetFileName(targetPath); string linkPath = Path.Combine(whereToPutItPath, name) + ".lnk"; if (File.Exists(linkPath)) { File.Delete(linkPath); } #if !__MonoCS__ var WshShell = new WshShellClass(); var shortcut = (IWshShortcut)WshShell.CreateShortcut(linkPath); try { shortcut.TargetPath = targetPath; //shortcut.Description = "Launch My Application"; //shortcut.IconLocation = Application.StartupPath + @"\app.ico"; } catch (Exception error) { if (targetPath != System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(targetPath))) { throw new ApplicationException("Unfortunately, windows had trouble making a shortcut to remember this project, because of a problem with non-ASCII characters. Sorry!"); } throw error; } shortcut.Save(); #else // It's tempting to use symbolic links instead which would work much nicer - iff // the UnixSymbolicLinkInfo class wouldn't cause us to crash... // var name = Path.GetFileName(targetPath); // string linkPath = Path.Combine(whereToPutItPath, name); // var shortcut = new Mono.Unix.UnixSymbolicLinkInfo(linkPath); // if (shortcut.Exists) // shortcut.Delete(); // // var target = new Mono.Unix.UnixSymbolicLinkInfo(targetPath); // target.CreateSymbolicLink(linkPath); File.WriteAllText(linkPath, targetPath); #endif }
public void CreateStartupFolderShortcut() { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); string productname = this.GetProductName(); // Create the shortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut( startUpFolderPath + "\\" + productname + ".lnk"); shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location; shortcut.WorkingDirectory = System.AppDomain.CurrentDomain.BaseDirectory; shortcut.Description = "Launch My Application"; // shortcut.IconLocation = Application.StartupPath + @"\App.ico"; shortcut.Save(); }
public override void Install(IDictionary stateSaver) { base.Install(stateSaver); if (!Directory.Exists(MagicDiscPath)) { string magicDiscPath = null; if (ArchitectureIs64Bit) { magicDiscPath = Path.Combine(ExecutingDir.FullName, "setup_magicdiscx64.exe"); } else { magicDiscPath = Path.Combine(ExecutingDir.FullName, "setup_magicdisc.exe"); } Process p = Process.Start(magicDiscPath, "/s"); //a driver warning will pop up on vista+ systems at this point. The user will have to accept this. //The magic disc installer does not give useful return codes, so we can't do anything except assume the installation //was successful p.WaitForExit(); } Process.Start("net.exe", "user Testing Testing /add").WaitForExit(); Process.Start("net.exe", "localgroup Administrators Testing /add").WaitForExit(); Process.Start("net.exe", "accounts /maxpwage:unlimited").WaitForExit(); //create a shortcut in the all users desktop to the setup_for_snapshot.bat batch file WshShellClass wshShell = new WshShellClass(); object allUsersDesktop = "AllUsersDesktop"; string shortcutPath = wshShell.SpecialFolders.Item(ref allUsersDesktop).ToString( ); IWshShortcut myShortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(shortcutPath, "Automation - Setup For Snapshot.lnk")); myShortcut.TargetPath = @"c:\automation\setup_for_snapshot.bat"; myShortcut.WorkingDirectory = @"c:\automation"; myShortcut.Description = "Automation - Setup For Snapshot"; myShortcut.Save(); }
public static void CreateShortcut(string target, string linkPath) { if (Path.HasExtension(linkPath)) { string extension = Path.GetExtension(linkPath); if (extension != ".lnk") { linkPath = linkPath.Remove(linkPath.Length - extension.Length, extension.Length) + ".lnk"; } } else { linkPath = linkPath + ".lnk"; } WshShell shell = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut) shell.CreateShortcut(linkPath); shortcut.TargetPath = target; shortcut.Save(); }
//http://www.codeproject.com/Articles/146757/Add-Remove-Startup-Folder-Shortcut-to-Your-App public string CreatLink(string appName, int appDelayTime, string appLocationName) { //via reg keys //Microsoft.Win32.RegistryKey startupkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); //string command = Application.ExecutablePath + " " + appDelayTime + " " + appLocationName; //startupkey.SetValue(appName, command); //via short cut WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut myShortcut; string lnkStartupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); //string lnkStartupPath = "c:\\"; string lnkFileName = "\\" + appName + "_DelayStartup" + ".lnk"; //sets lnk path and name myShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(lnkStartupPath + lnkFileName); //sets targets path and name //myShortcut.TargetPath = Application.ExecutablePath; myShortcut.TargetPath = Environment.CurrentDirectory + "\\" + "DelayStartup.exe"; //working directory ??? myShortcut.WorkingDirectory = Application.StartupPath; //arguments "\"" need for unc with spaces myShortcut.Arguments = " " + "\"" + appDelayTime + "\"" + " " + "\"" + appLocationName + "\""; //Desription myShortcut.Description = " delayed startup for " + appName; //set icon string IconFileLocaiton = CreateIconFile(appLocationName); myShortcut.IconLocation = IconFileLocaiton; //save lnk myShortcut.Save(); return(lnkStartupPath); }
public static void CreateStartupFolderShortcut() { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Create the shortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut( startUpFolderPath + "\\" + PRODUCT_NAME + ".lnk"); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch BrightnessTray"; shortcut.Arguments = String.Join(" ", Environment.GetCommandLineArgs().Skip(1)); shortcut.Save(); }
public static void CreateStartupFolderShortcut() { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut( startUpFolderPath + "\\" + Application.ProductName + cookieStartUP + ".lnk"); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch Remote Control"; shortcut.Save(); }
private void DeleteShortcuts() { // Just try and delete all possible shortcuts that may have been // created during install try { // This is in a Try block in case AllUsersDesktop is not supported object allUsersDesktop = "AllUsersDesktop"; WshShell shell = new WshShellClass(); string desktopFolder = shell.SpecialFolders.Item(ref allUsersDesktop).ToString(); DeleteShortcut(desktopFolder, ShortcutName); } catch { } DeleteShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), ShortcutName); DeleteShortcut(QuickLaunchFolder, ShortcutName); }
public static void RegistyCheck() { var fullName = System.Reflection.Assembly.GetExecutingAssembly().Location; var thisPath = Directory.GetCurrentDirectory(); //var iconPath = Path.Combine(thisPath, "Note.ico"); var iconPathReg = "\"" + fullName + "\"" + ""; var exePathReg = "\"" + fullName + "\"" + " \"%1\""; var exePathReg2 = "\"" + fullName + "\"" + " \"%V\""; //File Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Long Path Tool", "Icon", iconPathReg, RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Long Path Tool\command", "", exePathReg, RegistryValueKind.String); //Folder Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Long Path Tool", "Icon", iconPathReg, RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Long Path Tool\command", "", exePathReg, RegistryValueKind.String); //Inside folder Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Long Path Tool", "Icon", iconPathReg, RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Long Path Tool\command", "", exePathReg2, RegistryValueKind.String); var schPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\SendTo\Long Path Tool.lnk"; //MessageBox.Show(fullName); //MessageBox.Show(thisPath); //MessageBox.Show(schPath); //MessageBox.Show(fullName); if (System.IO.File.Exists(schPath)) { System.IO.File.Delete(schPath); } WshShellClass wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(schPath) as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = fullName; // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = "Long Path Tool"; shortcut.WorkingDirectory = thisPath; shortcut.IconLocation = fullName; shortcut.Save(); MessageBox.Show("Success Install", "Success Install", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void RegistStartup() { try { IWshShell iwshell = new WshShellClass(); IWshShortcut iwshort = (IWshShortcut)iwshell.CreateShortcut(SHORTCUT_PATH); iwshort.TargetPath = Assembly.GetEntryAssembly().Location; iwshort.Description = Properties.Resources.SoftwareName; // ショートカット作成 iwshort.Save(); MessageBox.Show(Properties.Resources.SettingStartupRegested, Properties.Resources.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Information); shortcutButtonSetting(); } catch (Exception ex) { MessageBox.Show(Properties.Resources.SettingStartupRegistError + ex.Message, Properties.Resources.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Creates a link of the currFile in the start menu /// </summary> /// <param name="currFile"></param> private void createShortcut(string currFile, string iconLocation, string iconName) { string startMenuDir = Context.Parameters["StartMenuDir"]; //throw new Exception("startMenuDir = " + startMenuDir + " currFile = " + currFile + " iconLocation = " + iconLocation); string shortcutName = startMenuDir + "\\" + Path.GetFileName(currFile) + ".lnk"; WshShellClass WshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@shortcutName); shortcut.TargetPath = @currFile; shortcut.Description = "Open " + Path.GetFileName(currFile); if ((iconLocation != null) && (iconName != null)) { if (!iconName.StartsWith("\\")) { iconName = "\\" + iconName; } shortcut.IconLocation = iconLocation + @iconName; } shortcut.Save(); }
public void CreateStartupFolderShortcut() { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Create the shortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut( startUpFolderPath + "\\" + Application.ProductName + ".lnk"); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Description = "Launch My Application"; // shortcut.IconLocation = Application.StartupPath + @"\App.ico"; shortcut.Save(); }
public bool Create(string shortcutPath, string targetPath, string arguments = "") { if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath)) { //try { var wsh = new WshShellClass(); var shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath); shortcut.TargetPath = targetPath; shortcut.Arguments = arguments; shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); shortcut.Save(); return(true); //} //catch (Exception e) { // //DebugHelper.WriteException(e); //} } return(false); }
public static void CreateStartupFolderShortcut() { string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); string shortcutFilePath = Path.Combine(startUpFolderPath, Application.ProductName + ".lnk"); if (System.IO.File.Exists(shortcutFilePath)) //shortcut already exists return; WshShellClass wshShell = new WshShellClass(); IWshShortcut shortcut; // Create the shortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(shortcutFilePath); shortcut.TargetPath = Application.ExecutablePath; shortcut.WorkingDirectory = Application.StartupPath; shortcut.Save(); }
public static void CreateStartupFolderShortcut() { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut; string shortcutFilename = StartUpFolderPath + "\\" + ProductName + ".lnk"; if (System.IO.File.Exists(shortcutFilename)) { System.IO.File.Delete(shortcutFilename); } shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(shortcutFilename); shortcut.TargetPath = ExecutablePath; shortcut.WorkingDirectory = Path.GetDirectoryName(ExecutablePath); shortcut.Description = "Launch My Application"; shortcut.Save(); }
public static IWshRuntimeLibrary.IWshShortcut GetShortcut(Element element) { try { if (System.IO.File.Exists(element.AssociationURIFullPath)) { WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(element.AssociationURIFullPath); return(shortcut); } else { return(null); } } catch (Exception) { return(null); } }
//http://www.codeproject.com/Articles/146757/Add-Remove-Startup-Folder-Shortcut-to-Your-App public string CreatLink(string appName, int appDelayTime, string appLocationName) { //via reg keys //Microsoft.Win32.RegistryKey startupkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); //string command = Application.ExecutablePath + " " + appDelayTime + " " + appLocationName; //startupkey.SetValue(appName, command); //via short cut WshShellClass wshShell = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut myShortcut; string lnkStartupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup); //string lnkStartupPath = "c:\\"; string lnkFileName = "\\" + appName + "_DelayStartup" + ".lnk"; //sets lnk path and name myShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(lnkStartupPath + lnkFileName); //sets targets path and name //myShortcut.TargetPath = Application.ExecutablePath; myShortcut.TargetPath = Environment.CurrentDirectory + "\\" + "DelayStartup.exe"; //working directory ??? myShortcut.WorkingDirectory = Application.StartupPath; //arguments "\"" need for unc with spaces myShortcut.Arguments = " " + "\"" + appDelayTime + "\"" + " " + "\"" + appLocationName + "\""; //Desription myShortcut.Description = " delayed startup for " + appName; //set icon string IconFileLocaiton = CreateIconFile(appLocationName); myShortcut.IconLocation = IconFileLocaiton; //save lnk myShortcut.Save(); return lnkStartupPath; }
public static bool Create(string shortcutPath, string targetPath, string arguments = "") { #if !__MonoCS__ if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath)) { try { IWshShell wsh = new WshShellClass(); var shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath); shortcut.TargetPath = targetPath; shortcut.Arguments = arguments; shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath); shortcut.Save(); return true; } catch { } } #endif return false; }
private void buttonOk_Click(object sender, EventArgs e) { Console.WriteLine("----- buttonOk_Click -----"); // 設定ファイルを保存する Properties.Settings.Default.FormatType = comboBoxFormat.Text; Properties.Settings.Default.FileNameOutput = checkBoxFileName.Checked; Properties.Settings.Default.SheetNameOutput = checkBoxSheetName.Checked; Properties.Settings.Default.LineNoOutput = checkBoxLineNo.Checked; Properties.Settings.Default.CompleteMsg = chkCompleteMsg.Checked; Properties.Settings.Default.SendToShortcut = chkSendToShortcut.Checked; Properties.Settings.Default.Save(); Console.WriteLine("設定ファイル保存完了"); // 送るフォルダのショートカット設定 string sendtoDir = Environment.GetFolderPath(Environment.SpecialFolder.SendTo); string sendtoPath = Path.Combine(sendtoDir, Properties.Settings.Default.ShortcutName); if (chkSendToShortcut.Checked) { if (!System.IO.File.Exists(sendtoPath)) { IWshShell shell = new WshShellClass(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(sendtoPath); shortcut.TargetPath = Assembly.GetEntryAssembly().Location; shortcut.Description = Properties.Settings.Default.AppName + "を起動します。"; shortcut.Save(); Console.WriteLine("ショートカットファイル[" + sendtoPath + "]を作成しました。"); } } else { if (System.IO.File.Exists(sendtoPath)) { System.IO.File.Delete(sendtoPath); Console.WriteLine("ショートカットファイル[" + sendtoPath + "]を削除しました。"); } } this.Close(); }
private void DoShortcut(string shortcutpath, string databasename, string target) { // Create a new instance of WshShellClass WshShell = new WshShellClass(); string _localdatabasename = databasename; if (checkDBMenu1.Checked) _localdatabasename = "AskUser"; // Create the shortcut IWshRuntimeLibrary.IWshShortcut MyShortcut; // Choose the path for the shortcut MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(shortcutpath); // Where the shortcut should point to MyShortcut.TargetPath = target + "\\" + "picasastarter.exe"; MyShortcut.WorkingDirectory = target; if (checkBackup.Checked) { MyShortcut.Arguments = "/backup \"" + _localdatabasename + "\""; // Description for the shortcut MyShortcut.Description = "Backup custom database && Pictures"; } else { MyShortcut.Arguments = "/autorun \"" + _localdatabasename + "\""; // Description for the shortcut MyShortcut.Description = "Start Picasa with custom database"; } // Location for the shortcut's icon MyShortcut.IconLocation = Application.StartupPath + @"\picasastarter.exe,0"; // Create the shortcut at the given path MyShortcut.Save(); }
/// <summary> /// Adds to startup folder. /// </summary> public void AddToStartupFolder() { // Validate the parameters. ValidateParameters(); // Create the shell. var shell = new WshShellClass(); // Create the shortcut. var shortcut = (IWshShortcut)shell.CreateShortcut(GetShortcutPath()); // Set the target path. shortcut.TargetPath = ApplicationPath; // Set the description. shortcut.Description = "Launch " + Path.GetFileNameWithoutExtension(ApplicationPath); // Location for the shortcut's icon //MyShortcut.IconLocation = Application.StartupPath + @"\app.ico"; shortcut.IconLocation = ApplicationPath + ",0"; // Save the shortcut. shortcut.Save(); }
public static void RegistyCheck() { var fullName = System.Reflection.Assembly.GetExecutingAssembly().Location; var thisPath = Directory.GetCurrentDirectory(); //var iconPath = Path.Combine(thisPath, "Note.ico"); var iconPathReg = "\"" + fullName + "\"" + ""; var exePathReg = "\"" + fullName + "\"" + " \"%1\""; var exePathReg2 = "\"" + fullName + "\"" + " \"%V\""; //File Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Copy File Path", "Icon", iconPathReg, RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Copy File Path\command", "", exePathReg, RegistryValueKind.String); //Folder Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Copy Folder Path", "Icon", iconPathReg, RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Copy Folder Path\command", "", exePathReg, RegistryValueKind.String); //Inside folder Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Folder Path", "Icon", iconPathReg, RegistryValueKind.String); Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Folder Path\command", "", exePathReg2, RegistryValueKind.String); var schPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\SendTo\Copy As Path.lnk"; //MessageBox.Show(fullName); //MessageBox.Show(thisPath); //MessageBox.Show(schPath); //MessageBox.Show(fullName); if (System.IO.File.Exists(schPath)) System.IO.File.Delete(schPath); WshShellClass wsh = new WshShellClass(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(schPath) as IWshRuntimeLibrary.IWshShortcut; shortcut.Arguments = ""; shortcut.TargetPath = fullName; // not sure about what this is for shortcut.WindowStyle = 1; shortcut.Description = "Copy As Path"; shortcut.WorkingDirectory = thisPath; shortcut.IconLocation = fullName; shortcut.Save(); MessageBox.Show("Success Install", "Success Install", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void CreateShortcut() { if (string.IsNullOrEmpty(this.FilePath)) { Log.LogError("FilePath is requried."); return; } if (string.IsNullOrEmpty(this.Name)) { Log.LogError("Name is requried."); return; } if (string.IsNullOrEmpty(this.ShortcutPath)) { this.ShortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } if (string.IsNullOrEmpty(this.Description)) { this.Description = string.Format(CultureInfo.InvariantCulture, "Launch {0}", this.Name.Replace(".lnk", string.Empty)); } this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Creating Shortcut: {0}", Path.Combine(this.ShortcutPath, this.Name))); WshShellClass shell = new WshShellClass(); IWshShortcut shortcutToCreate = shell.CreateShortcut(Path.Combine(this.ShortcutPath, this.Name)) as IWshShortcut; if (shortcutToCreate != null) { shortcutToCreate.TargetPath = this.FilePath; shortcutToCreate.Description = this.Description; if (!string.IsNullOrEmpty(this.Arguments)) { shortcutToCreate.Arguments = this.Arguments; } if (!string.IsNullOrEmpty(this.IconLocation)) { if (!System.IO.File.Exists(this.IconLocation)) { Log.LogError(string.Format(CultureInfo.InvariantCulture, "IconLocation: {0} does not exist.", this.IconLocation)); return; } shortcutToCreate.IconLocation = this.IconLocation; } if (!string.IsNullOrEmpty(this.WorkingDirectory)) { if (!System.IO.Directory.Exists(this.WorkingDirectory)) { Log.LogError(string.Format(CultureInfo.InvariantCulture, "WorkingDirectory: {0} does not exist.", this.WorkingDirectory)); return; } shortcutToCreate.WorkingDirectory = this.WorkingDirectory; } if (this.WindowStyle > 0) { shortcutToCreate.WindowStyle = this.WindowStyle; } shortcutToCreate.Save(); } }