.Exe shortcut maker
Have you ever wanted a tool to make your portable programs searchable in the start menu or to add all your steam games to the desktop?
This program allows users to create shortcut files based on an .exe file’s name and icon. It lets your scan a custom folder for exe files or one of the presets (epic games folder or steamapp folder) then you choose the output folder to place the shortcut files in or choose a preset (desktop or start menu for all/current users). The program will give you another chance if you enter an invalid path or invalid option and it will not create the shortcut if it already exists in that location.
Thanks so much to Brackeys for their C# tutorials which helped me make this project: HOW TO PROGRAM in C#
Downloads (For windows):
When downloading you may be given warnings that the files are uncommonly downloaded by your Browser, just click "keep". Running the exe files may trigger Microsoft SmartScreen as it is uncommonly run by people and the program requires admin (so that it has permissions to add shortcuts to the start menu). You will need to press "more info" then "run anyway". If you aren't comfortable using my exe files, I have included the source code so you can compile it yourself.
The primary C# code is provided below. You are welcome to use it for personal projects. For commercial use, please email me: brickbugpost@gmail.com
using IWshRuntimeLibrary;
using System;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.IO;
using System.IO.Enumeration;
using System.Reflection;
using static IWshRuntimeLibrary.WshShell;
using static System.Net.Mime.MediaTypeNames;
using static System.Runtime.InteropServices.JavaScript.JSType;
//explains what the program does to user
Console.WriteLine("This Program is for creating short cut files based of an .exe file's name and icon. \nYou can choose the location to search for exe files and output the shortcut file to. \nThe program will search for duplicates shortcuts already in that location with the same name. \nYou will be asked to confirm before any changes to your files are made.");
Console.WriteLine("");
//These call the subroutine that fetch variables from the users
string[] files = getThePathExe();
var temp = getThePathLnk();
string target = temp.Item1;
bool seachInBothLoc = temp.Item2;
//removing quotation marks from strings
static string RemoveQuotationMarks(string str)
{
if (!string.IsNullOrEmpty(str) && str[0] == '\"' && str[str.Length - 1] == '\"')
{
return str.Substring(1, str.Length - 2);
}
return str;
}
//returns the array of all exe files in a user selected path
static string[] getThePathExe()
{
Console.Write("Copy the folder path you want to be scanned for .exe files. \nOr enter \"1\" to scan the steamapp folder. \nOr enter \"2\" to scan epic games folder: ");
string selectOptions = Console.ReadLine();
string pathToScan;
string[] files = new string[0];
switch (selectOptions)
{
case "1":
case "one":
pathToScan = "C:\\Program Files (x86)\\Steam\\steamapps\\common";
break;
case "2":
case "two":
pathToScan = "C:\\Program Files\\Epic Games\\";
break;
default:
selectOptions = RemoveQuotationMarks(selectOptions);
pathToScan = selectOptions;
break;
}
//makes the array of exe files in the pathToScan location
try
{
files = System.IO.Directory.GetFiles(pathToScan, "*.exe", SearchOption.AllDirectories);
Console.WriteLine("");
}
catch
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Try again. That Path doesn’t exist or you don’t have permissions to go there.");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
files = getThePathExe();
}
return files;
}
//return the place to put the shortcut and calls seachInBothLocUserInput() to return if it should search for duplicates in all users or just current user
static Tuple<string, bool> getThePathLnk()
{
Console.Write("Copy the folder path you want your shortcuts to go. \nOr enter \"1\" to save in the start menu for all users \nOr enter \"2\" to save in the start menu for the current user. \nOr enter \"3\" to save to your desktop: ");
string selectOptions = Console.ReadLine();
string target;
bool seachInBothLoc;
switch (selectOptions)
{
case "1":
case "one":
target = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu";
seachInBothLoc = seachInBothLocUserInput();
break;
case "2":
case "two":
string roamingAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
target = roamingAppDataPath + "\\Microsoft\\Windows\\Start Menu";
seachInBothLoc = seachInBothLocUserInput();
break;
case "3":
case "three":
target = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
seachInBothLoc = false;
break;
default:
selectOptions = RemoveQuotationMarks(selectOptions);
target = selectOptions;
seachInBothLoc = false;
break;
}
// checks the directory is valid
if (!Directory.Exists(target))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Try again. That Path doesn’t exist or you don’t have permissions to go there.");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
var temp = getThePathLnk();
target = temp.Item1;
seachInBothLoc = temp.Item2;
}
else
{
Console.WriteLine("");
}
return new Tuple<string, bool>(target, seachInBothLoc);
}
//called by getThePathLnk() to return 1if it should search for duplicates in all users or just current user
static bool seachInBothLocUserInput()
{
Console.WriteLine("");
Console.WriteLine("Do you want us to check if a shortcut file already exist in the local start menu as well as for all users. ");
Console.Write("Press Y/y for yes and N/n for no: ");
string permition = Console.ReadLine();
bool seachInBothLoc;
switch (permition)
{
case "Y":
case "y":
seachInBothLoc = true;
break;
case "N":
case "n":
seachInBothLoc = false;
break;
default:
seachInBothLoc = seachInBothLocUserInput();
break;
}
return seachInBothLoc;
}
//makes the shortcut file for each exe file by calling CreateShortcut() for each exe file
for (int i = 0; i < files.Length; i++)
{
int rank = i + 1;
Console.Write("Are you happy creating a shortcut for the following program: ");
Console.WriteLine(files[i]);
string filename = null;
filename = Path.GetFileName(files[i]);
string shortCutName = filename.Remove(filename.Length - 4, 4);
Console.Write("Press Y/y for yes and N/n for no: ");
string permition = Console.ReadLine();
switch (permition)
{
case "Y":
case "y":
CreateShortcut(shortCutName, target, files[i], seachInBothLoc);
break;
case "N":
case "n":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Skipping");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
break;
default:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Try again. Press Y/y for yes and N/n for no");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
i = i - 1;
break;
}
}
Console.ReadKey();
//creates the shortcut based on passed values
static void CreateShortcut(string shortcutName, string shortcutPath, string targetFileLocation, bool seachInBothLoc)
{
try
{
string wildCard = "*" + shortcutName + ".lnk";
string[] duplicates = System.IO.Directory.GetFiles(shortcutPath, wildCard, SearchOption.AllDirectories);
string roamingAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string[] duplicates2 = new string[0];
if (seachInBothLoc == true)
{
if (shortcutPath == "C:\\ProgramData\\Microsoft\\Windows\\Start Menu")
{
duplicates2 = System.IO.Directory.GetFiles(roamingAppDataPath + "\\Microsoft\\Windows\\Start Menu", wildCard, SearchOption.AllDirectories);
}
else
{
duplicates2 = System.IO.Directory.GetFiles("C:\\ProgramData\\Microsoft\\Windows\\Start Menu", wildCard, SearchOption.AllDirectories);
}
}
else
{
}
if (duplicates.Length > 0 || duplicates2.Length > 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Duplicate was found. Shortcut will not be created.");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
}
else
{
string shortcutLocation = System.IO.Path.Combine(shortcutPath, shortcutName + ".lnk");
IWshRuntimeLibrary.WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.Description = "My shortcut description"; // The description of the shortcut
shortcut.IconLocation = targetFileLocation; // The icon of the shortcut
shortcut.TargetPath = targetFileLocation; // The path of the file that will launch when the shortcut is run
shortcut.Save();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Created");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
}
}
catch
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Your shortcut file could not be created. Mabey the program can't modify files in that location. Please close the program by pressing any key");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("");
Console.ReadKey();
// Close the current instance of the application
Environment.Exit(0);
}
}
Hello! I'm surprised you made it this far down on the page!