Pavle_nis

Create shortcut

Nov 24th, 2016
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.Diagnostics;
  12. using Microsoft.Win32;
  13. using IWshRuntimeLibrary;
  14. using System.IO;
  15.  
  16. namespace Shortcut
  17. {
  18.     public partial class Form1 : Form
  19.     {
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void Form1_Load(object sender, EventArgs e)
  26.         {
  27.             GetInstalledApps();
  28.         }
  29.         public void GetInstalledApps()
  30.         {
  31.             string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
  32.             using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
  33.             {
  34.                 foreach (string skName in rk.GetSubKeyNames())
  35.                 {
  36.                     using (RegistryKey sk = rk.OpenSubKey(skName))
  37.                     {
  38.                         try
  39.                         {
  40.                             listBox1.Items.Add(sk.GetValue("DisplayName"));
  41.                         }
  42.                         catch (Exception ex)
  43.                         { }
  44.                     }
  45.                 }
  46.                 label1.Text = listBox1.Items.Count.ToString();
  47.             }
  48.         }
  49.  
  50.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  51.         {
  52.  
  53.         }
  54.  
  55.         private void button1_Click(object sender, EventArgs e)
  56.         {
  57.             listBox1.SelectedItems.Clear();
  58.             for(int i = listBox1.Items.Count - 1; i >= 0; i--)
  59.             {
  60.                 if (listBox1.Items[i].ToString().ToLower().Contains(textBox1.Text.ToLower()))
  61.                 {
  62.                     listBox1.SetSelected(i, true);
  63.                 }
  64.             }
  65.             label3.Text = listBox1.SelectedItems.Count.ToString() + " items found";
  66.         }
  67.  
  68.         private void button2_Click(object sender, EventArgs e)
  69.         {
  70.             CreateShortcut();
  71.             MessageBox.Show("Shortcut created!", "Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Information);
  72.         }
  73.         private void CreateShortcut()
  74.         {
  75.             object shDesktop = (object)"Desktop";
  76.             WshShell shell = new WshShell();
  77.             string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + listBox1.SelectedItem.ToString();
  78.             IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
  79.             shortcut.Description = "New shortcut for a Notepad";
  80.             shortcut.Hotkey = "Ctrl+Shift+N";
  81.             shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
  82.             shortcut.Save();
  83.         }
  84.         }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment