Having to create a short cut to the desktop for an app seems easy if you do it manually, most of the programmatic ways I have so far found on the internet involve referring to a COM Library/Component to facilitate this, any how here is a slightly hacky version that seems to work for me found on a forum which I have adapted to take data from unity etc
Warning! This method relies upon writing and executing a visual basic script to create the short cut, security measures on some machines may not allow this so be warned.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
public string shortcutpath; void Start () { //we use the holding directory of the app as the link name in this example shortcutpath=System.IO.Directory.GetParent(Application.dataPath).ToString(); if (!PlayerPrefs.HasKey("HasShortcut"+Path.GetFileName(shortcutpath))) { //first run only CreateShortcut(Path.GetFileName(shortcutpath),"myprogram.exe"); PlayerPrefs.SetString("HasShortcut"+Path.GetFileName(shortcutpath),"true"); } } public void CreateShortcut(string linkName,string appfilename) { //in this example we place on desktop if (!Application.isEditor) { try { string[] vbswrite = {"set WshShell = WScript.CreateObject(\"WScript.Shell\")", "strDesktop = WshShell.SpecialFolders(\"Desktop\")", "set oShellLink = WshShell.CreateShortcut(strDesktop & \"\\"+linkName+".lnk\")", "oShellLink.TargetPath = \""+shortcutpath+"\\"+appfilename+"\"", "oShellLink.WindowStyle = 1", "oShellLink.Hotkey = \"CTRL+SHIFT+F\"", "oShellLink.IconLocation = \""+shortcutpath+"\\"+appfilename+", 0\"", "oShellLink.Description = \"Shortcut To Start "+linkName+" Application\"", "oShellLink.WorkingDirectory = \""+shortcutpath+"\"", "oShellLink.Save()"}; File.WriteAllLines("temp.vbs", vbswrite); Process Prc = Process.Start("temp.vbs"); Prc.WaitForExit(int.MaxValue); File.Delete("temp.vbs"); } catch(Exception e) { UnityEngine.Debug.Log ("issue making shortcut:"+e.ToString()); } } } |
10085 Total Views 1 Views Today