BlipFace.Helpers.AutoStart.createshortcut C# (CSharp) Method

createshortcut() private method

private createshortcut ( ) : void
return void
        void createshortcut()
        {
            //Chosen for creating a shortcut with the help of vbscript
            //It's an extra liablility, but better than forcing the
            //use of a WSH wrapper.
            //An alternative can be found here: http://www.msjogren.net/dotnet/eng/samples/dotnet_shelllink.asp
            //Looks very interesting, but didn't try it, since it would inflate the
            //use of this simple class too much.
            //But still it might be a very good thing to use, especially if
            //this doesn't work ;-)
            string file = Application.UserAppDataPath + "\\createshortcut.vbs";
            try
            {
                StreamWriter sw = new StreamWriter(file);
                sw.Write(string.Format(
                @"Set Shell = CreateObject(""WScript.Shell"")
            Set link = Shell.CreateShortcut(""{0}"")
            link.TargetPath = ""{1}""
            link.Description = ""{2}""
            link.Arguments = ""{3}""
            link.WorkingDirectory = ""{4}""
            link.Save"
                , startupfolderfile, ApplicationName, regkeyname, commandlineparams, new FileInfo(ApplicationName).DirectoryName));
                sw.Close();
                Process.Start(file).WaitForExit();
            }
            catch
            {
                throw;
            }
            finally
            {
                try { File.Delete(file); }
                catch { }
            }
        }