Advertisement
fortsoft

ProgramShortcut

Mar 23rd, 2021 (edited)
933
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.85 KB | Source Code | 0 0
  1. /**
  2.  * This is open-source software licensed under the terms of the MIT License.
  3.  *
  4.  * Copyright (c) 2019-2022 Petr Červinka - FortSoft <[email protected]>
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  7.  * of this software and associated documentation files (the "Software"), to deal
  8.  * in the Software without restriction, including without limitation the rights
  9.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.  * copies of the Software, and to permit persons to whom the Software is
  11.  * furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in all
  14.  * copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  **
  24.  * Version 1.1.0.0
  25.  */
  26.  
  27. using IWshRuntimeLibrary;
  28.  
  29. namespace FostSoft.Tools {
  30.  
  31.     /// <summary>
  32.     /// Tool for creating Windows shortcuts (*.lnk).
  33.     /// </summary>
  34.     public class ProgramShortcut {
  35.  
  36.         /// <summary>
  37.         /// Field
  38.         /// </summary>
  39.         private WshShell wshShell;
  40.  
  41.         /// <summary>
  42.         /// Initializes a new instance of the <see cref="ProgramShortcut"/>
  43.         /// class.
  44.         /// </summary>
  45.         public ProgramShortcut() {
  46.             wshShell = new WshShell();
  47.         }
  48.  
  49.         /// <summary>
  50.         /// Shortcut file path.
  51.         /// </summary>
  52.         public string ShortcutFilePath { get; set; }
  53.  
  54.         /// <summary>
  55.         /// Target path.
  56.         /// </summary>
  57.         public string TargetPath { get; set; }
  58.  
  59.         /// <summary>
  60.         /// Working directory.
  61.         /// </summary>
  62.         public string WorkingDirectory { get; set; }
  63.  
  64.         /// <summary>
  65.         /// Arguments.
  66.         /// </summary>
  67.         public string Arguments { get; set; }
  68.  
  69.         /// <summary>
  70.         /// Icon location.
  71.         /// </summary>
  72.         public string IconLocation { get; set; }
  73.  
  74.         /// <summary>
  75.         /// Creates Windows shortcut.
  76.         /// </summary>
  77.         public void Create() {
  78.             IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(ShortcutFilePath);
  79.             shortcut.TargetPath = TargetPath;
  80.             shortcut.WorkingDirectory = WorkingDirectory;
  81.             shortcut.Arguments = Arguments;
  82.             shortcut.IconLocation = IconLocation;
  83.             shortcut.Save();
  84.         }
  85.     }
  86. }
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement