예제 #1
0
        public static void CreateDirectoryShortcut(string targetPath, string whereToPutItPath)
        {
            var name = Path.GetFileName(targetPath);
            var linkPath = Path.Combine(whereToPutItPath, name) + ".lnk";
            var shortLinkPath = "";

            if(RobustFile.Exists(linkPath))
                RobustFile.Delete(linkPath);

            #if !__MonoCS__
            var wshShell = new WshShellClass();
            var shortcut = (IWshShortcut)wshShell.CreateShortcut(linkPath);

            try
            {
                shortcut.TargetPath = targetPath;
            }
            catch (Exception)
            {
                if (targetPath == Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(targetPath))) throw;

                // this exception was caused by non-ascii characters in the path, use 8.3 names instead
                var shortTargetPath = new StringBuilder(MAX_PATH);
                GetShortPathName(targetPath, shortTargetPath, MAX_PATH);

                var shortWhereToPutPath = new StringBuilder(MAX_PATH);
                GetShortPathName(whereToPutItPath, shortWhereToPutPath, MAX_PATH);

                name = Path.GetFileName(shortTargetPath.ToString());

                shortLinkPath = Path.Combine(shortWhereToPutPath.ToString(), name) + ".lnk";
                if (RobustFile.Exists(shortLinkPath))
                    RobustFile.Delete(shortLinkPath);

                shortcut = (IWshShortcut)wshShell.CreateShortcut(shortLinkPath);
                shortcut.TargetPath = shortTargetPath.ToString();
            }

            shortcut.Save();

            // now rename the link to the correct name if needed
            if (!string.IsNullOrEmpty(shortLinkPath))
                RobustFile.Move(shortLinkPath, linkPath);

            #else
            // It's tempting to use symbolic links instead which would work much nicer - iff
            // the UnixSymbolicLinkInfo class wouldn't cause us to crash...
            //			var name = Path.GetFileName(targetPath);
            //			string linkPath = Path.Combine(whereToPutItPath, name);
            //			var shortcut = new Mono.Unix.UnixSymbolicLinkInfo(linkPath);
            //			if (shortcut.Exists)
            //				shortcut.Delete();
            //
            //			var target = new Mono.Unix.UnixSymbolicLinkInfo(targetPath);
            //			target.CreateSymbolicLink(linkPath);

            RobustFile.WriteAllText(linkPath, targetPath);
            #endif
        }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                if (args[0] == "/u")
                {
                    try
                    {
                        IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StartGlashFish.lnk");
                        IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StopGlashFish.lnk");
                        IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MySql.lnk");
                    }
                    catch(Exception ex)
                    {

                    }
                }
            }
            else
            {
                WshShell = new WshShellClass();
                // Create the shortcut
                IWshRuntimeLibrary.IWshShortcut MyShortcut;
                // Choose the path for the shortcut
                string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StartGlashFish.lnk";
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path);
                // Where the shortcut should point to
                MyShortcut.TargetPath = @"c:\nolis\appdesigner\startglassfish.exe";
                // Description for the shortcut
                // Create the shortcut at the given path
                MyShortcut.Save();

                WshShell = new WshShellClass();
                // Create the shortcut

                // Choose the path for the shortcut
                path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StopGlashFish.lnk";
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path);
                // Where the shortcut should point to
                MyShortcut.TargetPath = @"c:\nolis\appdesigner\stopglassfish.exe";
                // Description for the shortcut
                // Create the shortcut at the given path
                MyShortcut.Save();

                path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MySql.lnk";
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path);
                // Where the shortcut should point to
                MyShortcut.TargetPath = @"c:\program files\MySql\MySql server 5.0\bin\MySql.exe";
                MyShortcut.Arguments = "mysql -h localhost -u root -p";
                // Description for the shortcut
                // Create the shortcut at the given path
                MyShortcut.Save();
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            if (args.Length == 1)
            {
                if (args[0] == "/u")
                {
                    try
                    {
                        IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StartGlashFish.lnk");
                        IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StopGlashFish.lnk");
                        IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MySql.lnk");
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            else
            {
                WshShell = new WshShellClass();
                // Create the shortcut
                IWshRuntimeLibrary.IWshShortcut MyShortcut;
                // Choose the path for the shortcut
                string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StartGlashFish.lnk";
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path);
                // Where the shortcut should point to
                MyShortcut.TargetPath = @"c:\nolis\appdesigner\startglassfish.exe";
                // Description for the shortcut
                // Create the shortcut at the given path
                MyShortcut.Save();

                WshShell = new WshShellClass();
                // Create the shortcut

                // Choose the path for the shortcut
                path       = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\StopGlashFish.lnk";
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path);
                // Where the shortcut should point to
                MyShortcut.TargetPath = @"c:\nolis\appdesigner\stopglassfish.exe";
                // Description for the shortcut
                // Create the shortcut at the given path
                MyShortcut.Save();

                path       = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\MySql.lnk";
                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(path);
                // Where the shortcut should point to
                MyShortcut.TargetPath = @"c:\program files\MySql\MySql server 5.0\bin\MySql.exe";
                MyShortcut.Arguments  = "mysql -h localhost -u root -p";
                // Description for the shortcut
                // Create the shortcut at the given path
                MyShortcut.Save();
            }
        }
예제 #4
0
        private void convert_Click_1(object sender, EventArgs e)
        {
            DecryptFile(fileName, @"tc2.dat");
            using (Ionic.Zip.ZipFile zipnew = Ionic.Zip.ZipFile.Read(zipPath))
            {
                for (int i = 0; i < 100; i++)
                {
                    //Thread.Sleep(100);


                    foreach (ZipEntry zenew in zipnew)
                    {
                        //Ionic.Zip.ZipFile.ExtractToDirectory(zipPath, extractPath);
                        //zipnew.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently);
                        backgroundWorker1.ReportProgress(i);
                    }
                }
                //zip.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently);
                //System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);
                //ZipFile.ExtractToDirectory(zipPath, extractPath);

                // Periodically report progress to the main thread so that it can
                // update the UI.  In most cases you'll just need to send an
                // integer that will update a ProgressBar

                zipnew.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently);


                backgroundWorker1.RunWorkerAsync();
                convert.Enabled        = false;
                kryptonButton1.Enabled = true;
            }
            System.IO.File.Delete(@"tc2.dat");
            string   inString  = Environment.GetEnvironmentVariable("ProgramFiles").ToLower();
            TextInfo cultInfo  = new CultureInfo("en-US", false).TextInfo;
            string   output    = cultInfo.ToTitleCase(inString);
            string   shortfold = output + @"\microsoft games\age of empires ii" + @"\";

            //Copy icon
            System.IO.File.Copy("icon.ico", shortfold + @"Age2_x1\icon.ico", true);
            //Create shortcut

            StringBuilder allUserProfile = new StringBuilder(260);

            SHGetSpecialFolderPath(IntPtr.Zero, allUserProfile, CSIDL_COMMON_DESKTOPDIRECTORY, false);

            string settingsLink = Path.Combine(allUserProfile.ToString(), "Age of Empires II The Conquerors.lnk");
            //Create All Users Desktop Shortcut for Application Settings
            WshShellClass shellClass = new WshShellClass();
            IWshShortcut  shortcut   = (IWshShortcut)shellClass.CreateShortcut(settingsLink);

            shortcut.TargetPath   = shortfold + @"Age2_x1\age2_x1.exe";
            shortcut.IconLocation = shortfold + @"Age2_x1\icon.ico";
            shortcut.Arguments    = "arg1 arg2";
            shortcut.Description  = "Age of Empires II The Conquerors";
            shortcut.Save();

            MessageBox.Show("Shortcut created on your Desktop!");
            progressBar1.Enabled = false;
        }
예제 #5
0
        private void addShortCut(bool add)
        {
            String StartupFolder    = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            String shortcutFilePath = StartupFolder + @"\Blurts.lnk";

            if (add)
            {
                // Add/create the shortcut to the Startup folder
                WshShellClass WshShell = new WshShellClass();
                IWshRuntimeLibrary.IWshShortcut MyShortcut;

                // The shortcut will be created in the Startup folder

                MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(shortcutFilePath);

                //Specify target file full path
                MyShortcut.TargetPath       = Application.StartupPath + @"\Blurts.exe";
                MyShortcut.IconLocation     = Application.StartupPath + @"\blue1_32x32.ico";
                MyShortcut.WorkingDirectory = Application.StartupPath;

                //e.g.  MyShortcut.TargetPath = "C:\WINDOWS\system32\calc.exe"
                MyShortcut.Save();
            }
            else
            {
                //Remove the shortcut from the Startup folder
                if (System.IO.File.Exists(shortcutFilePath))
                {
                    System.IO.File.Delete(shortcutFilePath);
                }
            }
        }
예제 #6
0
    public SectionResponseEnum Execute(PackageClass packageClass, ActionItem actionItem)
    {
      if (ItemProcessed != null)
        ItemProcessed(this, new InstallEventArgs("Create ShortCut"));

      try
      {
        UnInstallItem unInstallItem =
          packageClass.UnInstallInfo.BackUpFile(actionItem.Params[Const_Loc].GetValueAsPath(), "CopyFile");

        WshShellClass wshShell = new WshShellClass();
        // Create the shortcut

        IWshShortcut myShortcut = (IWshShortcut)wshShell.CreateShortcut(actionItem.Params[Const_Loc].GetValueAsPath());
        myShortcut.TargetPath = Path.GetFullPath(actionItem.Params[Const_Target].GetValueAsPath());
        myShortcut.WorkingDirectory = Path.GetDirectoryName(myShortcut.TargetPath);
        myShortcut.Description = actionItem.Params[Const_Description].Value;

        if (!string.IsNullOrEmpty(actionItem.Params[Const_Icon].Value))
          myShortcut.IconLocation = actionItem.Params[Const_Icon].GetValueAsPath();
        else
          myShortcut.IconLocation = actionItem.Params[Const_Target].GetValueAsPath();

        myShortcut.Save();

        FileInfo info = new FileInfo(actionItem.Params[Const_Loc].GetValueAsPath());
        unInstallItem.FileDate = info.CreationTimeUtc;
        unInstallItem.FileSize = info.Length;
        packageClass.UnInstallInfo.Items.Add(unInstallItem);
      }
      catch (Exception) {}

      return SectionResponseEnum.Ok;
    }
예제 #7
0
        private void CreateShortcut(string folder, string name, string target, string description)
        {
            string shortcutFullName = Path.Combine(folder, name + ".lnk");

            if (!Directory.Exists(folder))
            {
                try
                {
                    Directory.CreateDirectory(folder);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error occured while creating directory " + folder + "!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            try
            {
                WshShell     shell = new WshShellClass();
                IWshShortcut link  = (IWshShortcut)shell.CreateShortcut(shortcutFullName);
                link.TargetPath       = target;
                link.WorkingDirectory = Path.GetDirectoryName(target);
                link.Description      = description;
                link.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("The shortcut \"{0}\" could not be created.\n\n{1}", shortcutFullName, ex.ToString()),
                                "Create Shortcut", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #8
0
        /// <summary>
        /// Creates a shortcut to reporting services for the specifed computer.
        /// </summary>
        /// <param name="computerName">The name of the computer that has reporting services.</param>
        /// <param name="managerName">The name of the report manager.</param>
        /// <returns>True if successful; false if not.</returns>
        public bool CreateShortcut(string computerName, string managerName)
        {
            _viewAdapter.UpdateInstallerLog("Creating shortcut\r\n");
            _viewAdapter.UpdateInstallerLog("Reports are hosted at " + _http + computerName + "/" + managerName + "\r\n");
            try
            {
                WshShellClass shell = new WshShellClass();
                // Use the Environment class to retrieve the Start Menu on the system

                //the programs menu for the logged in user
                string startMenu = Environment.GetFolderPath(Environment.SpecialFolder.Programs);

                startMenu += _startMenuPath;

                if (!Directory.Exists(startMenu))
                {
                    Directory.CreateDirectory(startMenu);
                }

                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(startMenu + _shortcutFile);
                shortcut.TargetPath  = _http + computerName + "/" + managerName;
                shortcut.Description = "Reporting Services Website";
                shortcut.Save();
                return(true);
            }
            catch (Exception)
            {
                _viewAdapter.UpdateInstallerLog("The setup program is unable to create a menu shortcut for SQLsecure Reports.\r\n  Please verify that this computer has Windows Scripting Host properly installed.\r\n  You can view reports at " + _http + computerName + "/" + managerName + "\r\n");
                _viewAdapter.DisplayMessageBox("The setup program is unable to create a menu shortcut for SQLsecure Reports.\r\n  Please verify that this computer has Windows Scripting Host properly installed.\r\n  You can view reports at " + _http + computerName + "/" + managerName + "\r\n", "Shortcut Creation Error!");
                return(false);
            }
        }
예제 #9
0
        /// <summary>
        /// Creates a shortcut of the select icon (app) on the
        /// desktop
        /// </summary>
        /// <param name="appInfo">App info of the selecteda app</param>
        /// <param name="fileInfo">File info of the app</param>
        private void createShortcut(AppInfo appInfo, FileInfo fileInfo)
        {
            try
            {
                var wsh = new WshShellClass();

                var shortCutName = (String.IsNullOrEmpty(appInfo.ShortcutName)) ? appInfo.Name : appInfo.ShortcutName;

                var targetPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" +
                                 Path.GetFileNameWithoutExtension(shortCutName) + ".lnk";

                var shortcut = wsh.CreateShortcut(targetPath) as IWshShortcut;
                if (shortcut != null)
                {
                    shortcut.Arguments        = appInfo.CommandLine;
                    shortcut.TargetPath       = fileInfo.FullName;
                    shortcut.WorkingDirectory = !String.IsNullOrEmpty(appInfo.WorkingDirectory) ? appInfo.WorkingDirectory : Path.GetDirectoryName(shortcut.TargetPath);
                    shortcut.WindowStyle      = 1;
                    shortcut.Description      = appInfo.Description;
                    shortcut.Save();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to create shortcut. Exception: " + ex, Name);
            }
        }
예제 #10
0
        //here we go, thats the method called by vvvv each frame
        //all data handling should be in here
        public void Evaluate(int SpreadMax)
        {
            //if any of the inputs has changed
            //recompute the outputs
            if (FShortcut.PinIsChanged)
            {
                FDestination.SliceCount = SpreadMax;

                string curSource;
                for (int i = 0; i < SpreadMax; i++)
                {
                    FShortcut.GetString(i, out curSource);
                    try
                    {
                        IWshShell    wsh         = new WshShellClass();
                        IWshShortcut curShortcut = (IWshShortcut)wsh.CreateShortcut(curSource);

                        FDestination.SetString(i, curShortcut.TargetPath);
                        FWorkingDir.SetString(i, curShortcut.WorkingDirectory);
                        FIcon.SetString(i, curShortcut.IconLocation);
                    }
                    catch
                    {
                        FHost.Log(TLogType.Error, "couldn't resolve shortcut " + curSource);
                        FDestination.SetString(i, string.Empty);
                        FWorkingDir.SetString(i, string.Empty);
                        FIcon.SetString(i, string.Empty);
                    }
                }
            }
        }
예제 #11
0
 private void MakeShortcut(string path, string shortcutDirectory)
 {
     var wsh = new WshShellClass();
     var shortcut = wsh.CreateShortcut(Path.ChangeExtension(shortcutDirectory, ".lnk")) as IWshShortcut;
     shortcut.TargetPath = path;
     shortcut.Save();
 }
예제 #12
0
        private static bool Create(string shortcutPath, string targetPath, string arguments = "")
        {
            if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                Delete(shortcutPath);

                try
                {
                    IWshShell wsh = new WshShellClass();
                    IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath);
                    shortcut.TargetPath = targetPath;
                    shortcut.Arguments = arguments;
                    shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
                    shortcut.Save();

                    return true;
                }
                catch (Exception e)
                {
                    DebugHelper.WriteException(e);
                }
            }

            return false;
        }
예제 #13
0
        private static string ShortcutTarget(string clickedItemPath)
        {
            var wsh = new WshShellClass();
            var sc  = (IWshShortcut)wsh.CreateShortcut(clickedItemPath);

            return(sc.TargetPath);
        }
예제 #14
0
        private void CreateShortCutAtDestkop()
        {
            string targetdir     = System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string mShortcutPath = targetdir + "\\נומרולוגיית הצאקרות.lnk";
            string mAppPath      = mDestinationFolder + "\\NumChakra.exe";

            // Create a new instance of WshShellClass
            WshShellClass WshShell = new WshShellClass();

            // Create the shortcut
            IWshRuntimeLibrary.IWshShortcut MyShortcut;

            // Choose the path for the shortcut
            MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(mShortcutPath);

            // Where the shortcut should point to
            MyShortcut.TargetPath = mAppPath;

            // Description for the shortcut
            MyShortcut.Description = "Launch Numerology Chakra Application";

            // Location for the shortcut's icon
            MyShortcut.IconLocation = mDestinationFolder + @"\CHKR_NUM.ico";

            // Create the shortcut at the given path
            MyShortcut.Save();

            //FileInfo fiSC = mDestFolder.GetFiles("*.lnk")[0];
            //fiSC.CopyTo(targetdir);
        }
예제 #15
0
        private void registry_registe(bool write)
        {
            string shortCut = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Drink.lnk";

            if (write)
            {
                #region registry registe

                if (System.IO.File.Exists(shortCut))
                {
                    System.IO.File.Delete(shortCut);
                }

                WshShellClass shell = new WshShellClass();

                //IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\PPCBacklightAdjustmentTool.lnk");
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortCut);

                shortcut.TargetPath = Application.ExecutablePath;

                // add Description of Short cut
                shortcut.Description = "DRINK";

                // save it / create
                shortcut.Save();
                #endregion
            }
            else
            {
                if (System.IO.File.Exists(shortCut))
                {
                    System.IO.File.Delete(shortCut);
                }
            }
        }
예제 #16
0
        public static void CreateStartupFolderShortcut()
        {
            var          wshShell = new WshShellClass();
            IWshShortcut shortcut;
            string       startUpFolderPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            // Create the shortcut
            shortcut =
                (IWshShortcut)wshShell.CreateShortcut(
                    startUpFolderPath + "\\" +
                    Assembly.GetExecutingAssembly().FullName
                    //Application.ProductName + ".lnk"
                    );

            //shortcut.TargetPath = Application.ExecutablePath;
            //shortcut.WorkingDirectory = Application.StartupPath;

            string exePath = Assembly.GetExecutingAssembly().GetName().CodeBase;

            shortcut.TargetPath       = exePath;
            shortcut.WorkingDirectory = Path.GetDirectoryName(exePath);
            shortcut.Description      = "Launch My Application";

            // shortcut.IconLocation = Application.StartupPath + @"\App.ico";
            shortcut.Save();
        }
예제 #17
0
        public static void CreateDirectoryShortcut(string targetPath, string whereToPutItPath)
        {
            var    name     = Path.GetFileName(targetPath);
            var    WshShell = new WshShellClass();
            string linkPath = Path.Combine(whereToPutItPath, name) + ".lnk";

            if (File.Exists(linkPath))
            {
                File.Delete(linkPath);
            }
            var shortcut = (IWshShortcut)WshShell.CreateShortcut(linkPath);

            try
            {
                shortcut.TargetPath = targetPath;
                //shortcut.Description = "Launch My Application";
                //shortcut.IconLocation = Application.StartupPath + @"\app.ico";
            }
            catch (Exception error)
            {
                if (targetPath != System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(targetPath)))
                {
                    throw new ApplicationException("Unfortunately, windows had trouble making a shortcut to remember this project, because of a problem with non-ASCII characters. Sorry!");
                }
                throw error;
            }
            shortcut.Save();
        }
예제 #18
0
        private void runCheck_CheckedChanged(object sender, EventArgs e)
        {
            if (runCheck.Checked)
            {
                // Create the shortcut responsible for starting the program on system start
                try
                {
                    WshShellClass wshShell = new WshShellClass();

                    IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName + ".lnk");

                    shortcut.TargetPath       = Application.ExecutablePath;
                    shortcut.WorkingDirectory = Application.StartupPath;

                    shortcut.Save();
                } catch (Exception ex) {
                    Program.mainForm.ErrorLog("ERROR: Creating shortcut\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }
            else
            {
                // Delete the shortcut responsible for starting the program on system start
                try
                {
                    System.IO.File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName + ".lnk");
                } catch (Exception ex) {
                    Program.mainForm.ErrorLog("ERROR: Deleting  shortcut\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }

            Program.settings["RunOnStartup"] = runCheck.Checked.ToString();
            Program.writeConfig();
        }
예제 #19
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                WshShellClass WshShell = new WshShellClass();
                IWshRuntimeLibrary.IWshShortcut shortCut = default(IWshRuntimeLibrary.IWshShortcut);

                shortCut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(folderBrowserDialog1.SelectedPath + "\\" + shortCutNameTextBox.Text + ".lnk");

                // shortcut properties
                shortCut.TargetPath = Application.ExecutablePath;
                shortCut.WindowStyle = 1;
                if(snapRadioButton.Checked)
                {
                    shortCut.Description = "Grab a snap shot from current screen using ScreenGrabber.";
                    // the next line sets a new argument so the program will know next time
                    // that the user only want to grab the screen
                    // which will be read from the command line.
                    shortCut.Arguments = "snap";
                }
                else
                    shortCut.Description = "Launch ScreenGrabber.";
                shortCut.WorkingDirectory = folderBrowserDialog1.SelectedPath;
                // the next line gets the first Icon from the executing program
                shortCut.IconLocation = Application.ExecutablePath + ", 0";
                shortCut.Save();

                pathLabel.Text = "Shortcut saved successfuly at:" + Environment.NewLine + folderBrowserDialog1.SelectedPath + "\\" + shortCutNameTextBox.Text + ".lnk";
            }
            catch(Exception ex)
            {
                MessageBox.Show("There were a problem saving your Shortcut.\n\n"+ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #20
0
        private void btnShortcut_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt    = ".lnk";
            sfd.FileName      = Mashed.version.NAME() + ".lnk";
            sfd.Filter        = "Shortcut (*.lnk)|*.lnk";
            sfd.ValidateNames = true;
            if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK && sfd.FileName != null)
            {
                WshShellClass wshShell = new WshShellClass();
                try {
                    IWshShortcut link = (IWshShortcut)(wshShell.CreateShortcut(sfd.FileName));
                    link.TargetPath  = Util.GetExePath();
                    link.Arguments   = "-fix";
                    link.Description = "Starts " + Mashed.version.NAME();
                    if (Mashed.checkExe())
                    {
                        link.IconLocation = Util.GetExeDir() + "\\" +
                                            "icon" + cmbIcon.SelectedItem + ".ico";
                    }
                    link.Save();
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #21
0
        public bool RunOnStartup()
        {
            WshShellClass wshShell = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut;

            try
            {
                // Create the shortcut
                shortcut =
                    (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(
                        getLinkPath()
                        );

                shortcut.TargetPath       = Application.ExecutablePath;
                shortcut.WorkingDirectory = Application.StartupPath;
                //shortcut.Description = "Launch My Application";
                shortcut.IconLocation = this.icoPath;
                shortcut.Save();
                return(true);
            }
            catch { }

            return(false);
        }
예제 #22
0
        private static string ShortcutTargetFolder(string clickedItemPath, string targetType)
        {
            var wsh = new WshShellClass();
            var sc  = (IWshShortcut)wsh.CreateShortcut(clickedItemPath);

            return("Folder" == targetType?ShortcutTarget(clickedItemPath) : Path.GetDirectoryName(sc.TargetPath));
        }
예제 #23
0
        public static void CreateDirectoryShortcut(string targetPath, string whereToPutItPath)
        {
            var name = Path.GetFileName(targetPath);
            var WshShell = new WshShellClass();
            string linkPath = Path.Combine(whereToPutItPath, name) + ".lnk";
            if(File.Exists(linkPath))
            {
                File.Delete(linkPath);
            }
            var shortcut = (IWshShortcut)WshShell.CreateShortcut(linkPath);

            try
            {
                shortcut.TargetPath = targetPath;
                //shortcut.Description = "Launch My Application";
                //shortcut.IconLocation = Application.StartupPath + @"\app.ico";
            }
            catch (Exception error)
            {
                if (targetPath !=System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(targetPath)))
                    throw new ApplicationException("Unfortunately, windows had trouble making a shortcut to remember this project, because of a problem with non-ASCII characters. Sorry!");
                throw error;
            }
            shortcut.Save();
        }
예제 #24
0
        private static bool Create(string shortcutPath, string targetPath, string arguments = "")
        {
            if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                Delete(shortcutPath);

                try
                {
                    IWshShell    wsh      = new WshShellClass();
                    IWshShortcut shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath);
                    shortcut.TargetPath       = targetPath;
                    shortcut.Arguments        = arguments;
                    shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
                    shortcut.Save();

                    return(true);
                }
                catch (Exception e)
                {
                    DebugHelper.WriteException(e);
                }
            }

            return(false);
        }
예제 #25
0
        /// <summary>
        /// 创建快捷方式
        /// </summary>
        /// <param name="path">快捷方式路径</param>
        /// <param name="targetPath">目标路径</param>
        public static void CreateShortcut(string path, string targetPath)
        {
            WshShell    shell    = new WshShellClass();
            WshShortcut shortcut = shell.CreateShortcut(path) as WshShortcut;

            shortcut.TargetPath = targetPath;
            shortcut.Save();
        }
예제 #26
0
        private void MakeShortcut(string path, string shortcutDirectory)
        {
            var wsh      = new WshShellClass();
            var shortcut = wsh.CreateShortcut(Path.ChangeExtension(shortcutDirectory, ".lnk")) as IWshShortcut;

            shortcut.TargetPath = path;
            shortcut.Save();
        }
예제 #27
0
 /// <summary>
 /// Follows a shortcut file programmatically
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static string ResolveLink(string path) {
     try
     {
         IWshShell wsh = new WshShellClass();
         IWshShortcut sc = (IWshShortcut)wsh.CreateShortcut(path);
         return sc.TargetPath;
     }
     catch { }
     return "";
 }
예제 #28
0
        public static void CreateShortcut(string folder, string filePath, string args, string shortCutName)
        {
            var          shell    = new WshShellClass();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(Path.Combine(folder, shortCutName + ".lnk"));

            shortcut.TargetPath = filePath;
            shortcut.Arguments  = args;
            // save it / create
            shortcut.Save();
        }
예제 #29
0
파일: Create.cs 프로젝트: sanzenwin/jschess
        static void Shortcut(String source, String dest, String description="")
        {
            WshShell wsh = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)wsh.CreateShortcut(dest);
            shortcut.Arguments = ".";
            shortcut.TargetPath = source;

            shortcut.Save();
        }
예제 #30
0
 public static void CreateShortcut(this IEnumerable<DirectoryInfo> directories, string rootFolder)
 {
     var wshShellClass = new WshShellClass();
     foreach (var directoryInfo in directories)
     {
         var shortcut = wshShellClass.CreateShortcut(Path.Combine(rootFolder, string.Format("{0}.lnk", directoryInfo.Name))) as IWshShortcut;
         shortcut.TargetPath = directoryInfo.FullName;
         shortcut.Save();
     }
 }
예제 #31
0
        public static void CreateShortcut(string saveLocation, string targetPath, string description)
        {
            WshShellClass wshShell = new WshShellClass();
            object        tempObj  = wshShell.CreateShortcut(saveLocation);
            IWshShortcut  shortcut = (IWshShortcut)tempObj;

            shortcut.TargetPath  = targetPath;
            shortcut.Description = description;
            shortcut.Save();
        }
예제 #32
0
 /// <summary>
 /// Follows a shortcut file programmatically
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static string ResolveLink(string path)
 {
     try
     {
         IWshShell    wsh = new WshShellClass();
         IWshShortcut sc  = (IWshShortcut)wsh.CreateShortcut(path);
         return(sc.TargetPath);
     }
     catch { }
     return("");
 }
예제 #33
0
        public static void CreateShortcut(this IEnumerable <DirectoryInfo> directories, string rootFolder)
        {
            var wshShellClass = new WshShellClass();

            foreach (var directoryInfo in directories)
            {
                var shortcut = wshShellClass.CreateShortcut(Path.Combine(rootFolder, string.Format("{0}.lnk", directoryInfo.Name))) as IWshShortcut;
                shortcut.TargetPath = directoryInfo.FullName;
                shortcut.Save();
            }
        }
예제 #34
0
        private void CreateShortcut(string folder)
        {
            string shortcutFullname = System.IO.Path.Combine(folder, this.ShortcutName + ".lnk");

            WshShell     shell    = new WshShellClass();
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutFullname);

            shortcut.TargetPath  = this.ShortcutTarget;
            shortcut.Description = this.ShortcutDescription;
            shortcut.Save();
        }
예제 #35
0
        public void CreateStartupFolderShortcut()
        {
            WshShellClass wshShell = new WshShellClass();
            IWshShortcut  shortcut;
            string        startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            shortcut                  = (IWshShortcut)wshShell.CreateShortcut(startUpFolderPath + "\\" + Application.ProductName + ".lnk");
            shortcut.TargetPath       = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Description      = "Launch Reserver Application";
            shortcut.Save();
        }
예제 #36
0
        private static void createShortCut(ShortCutProperties pShortcut, string pShortcutPath)
        {
            WshShellClass shellClass = new WshShellClass();
            IWshShortcut  workingShortCut;

            // Shortcuts erzeugen
            workingShortCut              = (IWshRuntimeLibrary.IWshShortcut)shellClass.CreateShortcut(pShortcutPath);
            workingShortCut.TargetPath   = @pShortcut.TargetPath;
            workingShortCut.Description  = pShortcut.Description;
            workingShortCut.IconLocation = @pShortcut.IconPath;
            workingShortCut.Save();
        }
예제 #37
0
        void createStartMenu()
        {
            string StartMenu = var_data.getStartMenu() + "\\" +
                               InfraSoftwareClient.nameClient;

            if (!Directory.Exists(StartMenu))
            {
                Directory.CreateDirectory(StartMenu);
            }

            // Program link
            {
                string shortcut = StartMenu + "\\" + InstallData.app + ".lnk";

                if (System.IO.File.Exists(shortcut))
                {
                    System.IO.File.Delete(shortcut);
                }

                WshShellClass WshShell   = new WshShellClass();
                IWshShortcut  MyShortcut = (IWshShortcut)WshShell.CreateShortcut(shortcut);

                MyShortcut.TargetPath       = var_data.pathDir + "\\" + InstallData.app + ".exe";
                MyShortcut.WorkingDirectory = var_data.pathDir;
                MyShortcut.IconLocation     = var_data.pathDir + "\\" + InstallData.app + ".exe";

                MyShortcut.Save();
            }

            // Uninstall link
            {
                string shortcut = StartMenu + "\\uninstall " + InstallData.app + ".lnk";

                if (System.IO.File.Exists(shortcut))
                {
                    System.IO.File.Delete(shortcut);
                }

                WshShellClass WshShell   = new WshShellClass();
                IWshShortcut  MyShortcut = (IWshShortcut)WshShell.CreateShortcut(shortcut);

                string path = System.Environment.GetEnvironmentVariable("COMMONPROGRAMFILES") +
                              "\\" +
                              InfraSoftwareClient.nameClient + " " + InstallData.app;

                MyShortcut.TargetPath       = path + "\\" + InstallData.app + "Setup.exe";
                MyShortcut.WorkingDirectory = path;
                MyShortcut.IconLocation     = path + "\\" + InstallData.app + "Setup.exe";

                MyShortcut.Save();
            }
        }
예제 #38
0
        private void CreateStartupFolderShortcut()
        {
            WshShellClass wshShell = new WshShellClass();

            IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(woxLinkPath);

            shortcut.TargetPath       = Application.ExecutablePath;
            shortcut.Arguments        = "hideStart";
            shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
            shortcut.Description      = "Launch Wox";
            shortcut.IconLocation     = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "App.ico");
            shortcut.Save();
        }
예제 #39
0
        /// <summary>
        /// Create Shortcut
        /// </summary>
        /// <param name="shortcutDir">Source directory where the shortcut will be saved.</param>
        /// <param name="targetPath">Target directory where the source for the shortcut is located.</param>
        public static void CreateShortcut(string shortcutDir, string targetPath)
        {
            string        path     = shortcutDir + ".lnk";
            WshShellClass shell    = new WshShellClass();
            WshShortcut   shortcut = (WshShortcut)shell.CreateShortcut(path);

            shortcut.TargetPath       = targetPath;
            shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
            shortcut.Arguments        = "Argument";
            shortcut.Description      = "This is a Shortcut";

            shortcut.Save();
        }
예제 #40
0
 public static void CreateShortcut(SpecialFolders specialFolder, string name, string exePath)
 {
     WshShell ws = new WshShellClass();
     string path = GetShortcutPath(ws, specialFolder, name);
     WshShortcut shortcut = ws.CreateShortcut(path) as WshShortcut;
     shortcut.TargetPath = exePath;
     shortcut.WindowStyle = 1;
     //shortcut.Hotkey = "CTRL+SHIFT+F";
     shortcut.IconLocation = exePath + ", 0";
     shortcut.Description = name;
     shortcut.WorkingDirectory = Path.GetDirectoryName(exePath);
     shortcut.Save();
 }
예제 #41
0
        private void createShortcut()
        {
            var wshCSClass = new WshShellClass();

            IWshRuntimeLibrary.IWshShortcut appShortcut;
            appShortcut              = (IWshRuntimeLibrary.IWshShortcut)wshCSClass.CreateShortcut(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "CottonHarvestFileDownloadUtility.lnk"));
            appShortcut.TargetPath   = Application.ExecutablePath;
            appShortcut.Description  = "Start Cotton Harvest File Download Utility";
            appShortcut.IconLocation = Application.StartupPath + @"\Resources\favicon.ico";
            appShortcut.Arguments    = " -minimized";
            appShortcut.WindowStyle  = 7;
            appShortcut.Save();
        }
예제 #42
0
        public static void CreateStartupFolderShortcut()
        {
            WshShellClass wshShell = new WshShellClass();
            IWshShortcut shortcut;
            string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            // Create the shortcut
            shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(startUpFolderPath, Application.ProductName + ".lnk"));

            shortcut.TargetPath = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;

            shortcut.Save();
        }
예제 #43
0
 /// <summary>
 /// Creates a shortcut programatically, used for testing
 /// </summary>
 /// <param name="file"></param>
 /// <param name="target"></param>
 /// <param name="arguments"></param>
 /// <returns></returns>
 public static bool CreateLink(string file, string target, string arguments)
 {
     try
     {
         IWshShell wsh = new WshShellClass();
         IWshShortcut sc = (IWshShortcut)wsh.CreateShortcut(file);
         sc.WorkingDirectory = API.Phantom.libraryPath;
         sc.TargetPath = Path.Combine(API.Phantom.libraryPath, target);
         sc.Arguments = arguments ?? "";
         sc.Save();
     }
     catch { }
     return false;
 }
예제 #44
0
파일: Exe.cs 프로젝트: GEPWNAGE/Steel
        public void createShortcut(string gamePath)
        {
            WshShell = new WshShellClass();
            IWshRuntimeLibrary.IWshShortcut GameShortcut;

            string deskDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            GameShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Path.Combine(deskDir,title + ".lnk"));
            GameShortcut.TargetPath = Path.Combine(gamePath,file);
            GameShortcut.Description = title;
            GameShortcut.IconLocation = Path.Combine(gamePath,file);
            GameShortcut.WorkingDirectory = gamePath;
            GameShortcut.Save();
        }
예제 #45
0
        public static void Make(string mySourcePath, string myDestPath)
        {
            //string path = Path.Combine(myDestPath, "sample_shortcut.lnk");

            //
            // ショートカット作成
            //
            IWshShell shell = new WshShellClass();

            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(myDestPath);
            shortcut.TargetPath = mySourcePath;
            shortcut.Description = "TEST";
            shortcut.Save();
        }
예제 #46
0
 internal void CreateShortcut(string sendToPath, string fullPath)
 {
     string fileName = Path.GetFileNameWithoutExtension(fullPath);
     IWshShortcut shortcut;
     if (WindowsVer.Is64BitOs()) {
         WshShell wshShell = new WshShell();
         shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(sendToPath, fileName + ".lnk"));
     } else {
         WshShellClass wshShell = new WshShellClass();
         shortcut = (IWshShortcut)wshShell.CreateShortcut(Path.Combine(sendToPath, fileName + ".lnk"));
     }
     shortcut.TargetPath = fullPath;
     shortcut.IconLocation = fullPath;
     shortcut.Save();
 }
예제 #47
0
 public void CreateShortcut(string path, string filename, string args, string icon)
 {
     try
     {
         WshShellClass class2 = new WshShellClass();
         IWshShortcut shortcut = (IWshShortcut)class2.CreateShortcut(path);
         shortcut.TargetPath = filename;
         shortcut.IconLocation = icon;
         shortcut.Arguments = args;
         shortcut.Save();
     }
     catch (Exception ex)
     {
         Logger.Current.Write(ex,"Unable to create shortcut");
     }
 }
예제 #48
0
 public static void CreateShortcut(string target, string linkPath)
 {
     if (Path.HasExtension(linkPath))
     {
         string extension = Path.GetExtension(linkPath);
         if (extension != ".lnk")
         {
             linkPath = linkPath.Remove(linkPath.Length - extension.Length, extension.Length) + ".lnk";
         }
     }
     else
     {
         linkPath = linkPath + ".lnk";
     }
     WshShell shell = new WshShellClass();
     IWshShortcut shortcut = (IWshShortcut) shell.CreateShortcut(linkPath);
     shortcut.TargetPath = target;
     shortcut.Save();
 }
예제 #49
0
        public void CreateStartupFolderShortcut()
        {
            WshShellClass wshShell = new WshShellClass();
            IWshRuntimeLibrary.IWshShortcut shortcut;
            string startUpFolderPath =
              Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            string productname = this.GetProductName();
            // Create the shortcut
            shortcut =
              (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(
                startUpFolderPath + "\\" +
                productname + ".lnk");

            shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            shortcut.WorkingDirectory = System.AppDomain.CurrentDomain.BaseDirectory;
            shortcut.Description = "Launch My Application";
            // shortcut.IconLocation = Application.StartupPath + @"\App.ico";
            shortcut.Save();
        }
예제 #50
0
        public static void CreateStartupFolderShortcut()
        {
            WshShellClass wshShell = new WshShellClass();
            IWshRuntimeLibrary.IWshShortcut shortcut;
            string startUpFolderPath =
              Environment.GetFolderPath(Environment.SpecialFolder.Startup);

            // Create the shortcut
            shortcut =
              (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(
                startUpFolderPath + "\\" +
                PRODUCT_NAME + ".lnk");

            shortcut.TargetPath = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;
            shortcut.Description = "Launch BrightnessTray";
            shortcut.Arguments = String.Join(" ", Environment.GetCommandLineArgs().Skip(1));
            shortcut.Save();
        }
예제 #51
0
        public static void CreateStartupFolderShortcut()
        {
            string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            string shortcutFilePath = Path.Combine(startUpFolderPath, Application.ProductName + ".lnk");

            if (System.IO.File.Exists(shortcutFilePath))
                //shortcut already exists
                return;

            WshShellClass wshShell = new WshShellClass();
            IWshShortcut shortcut;

            // Create the shortcut
            shortcut = (IWshShortcut)wshShell.CreateShortcut(shortcutFilePath);

            shortcut.TargetPath = Application.ExecutablePath;
            shortcut.WorkingDirectory = Application.StartupPath;

            shortcut.Save();
        }
예제 #52
0
        //http://www.codeproject.com/Articles/146757/Add-Remove-Startup-Folder-Shortcut-to-Your-App
        public string CreatLink(string appName, int appDelayTime, string appLocationName)
        {
            //via reg keys

            //Microsoft.Win32.RegistryKey startupkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
            //string command = Application.ExecutablePath + " " + appDelayTime + " " + appLocationName;
            //startupkey.SetValue(appName, command);

            //via short cut
            WshShellClass wshShell = new WshShellClass();
            IWshRuntimeLibrary.IWshShortcut myShortcut;

            string lnkStartupPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
            //string lnkStartupPath = "c:\\";
            string lnkFileName = "\\" + appName + "_DelayStartup" + ".lnk";

            //sets lnk path and name
            myShortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(lnkStartupPath + lnkFileName);

            //sets targets path and name
            //myShortcut.TargetPath = Application.ExecutablePath;
            myShortcut.TargetPath = Environment.CurrentDirectory + "\\" + "DelayStartup.exe";

            //working directory ???
            myShortcut.WorkingDirectory = Application.StartupPath;

            //arguments "\"" need for unc with spaces
            myShortcut.Arguments = " " + "\"" + appDelayTime + "\"" + " " + "\"" + appLocationName + "\"";

            //Desription
            myShortcut.Description = " delayed startup for " + appName;

            //set icon
            string IconFileLocaiton = CreateIconFile(appLocationName);
            myShortcut.IconLocation = IconFileLocaiton;

            //save lnk
            myShortcut.Save();

            return lnkStartupPath;
        }
예제 #53
0
        public static bool Create(string shortcutPath, string targetPath, string arguments = "")
        {
#if !__MonoCS__
            if (!string.IsNullOrEmpty(shortcutPath) && !string.IsNullOrEmpty(targetPath) && File.Exists(targetPath))
            {
                try
                {
                    IWshShell wsh = new WshShellClass();
                    var shortcut = (IWshShortcut)wsh.CreateShortcut(shortcutPath);
                    shortcut.TargetPath = targetPath;
                    shortcut.Arguments = arguments;
                    shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);
                    shortcut.Save();

                    return true;
                }
                catch { }
            }
#endif
            return false;
        }
예제 #54
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            Console.WriteLine("----- buttonOk_Click -----");

            // 設定ファイルを保存する
            Properties.Settings.Default.FormatType = comboBoxFormat.Text;
            Properties.Settings.Default.FileNameOutput = checkBoxFileName.Checked;
            Properties.Settings.Default.SheetNameOutput = checkBoxSheetName.Checked;
            Properties.Settings.Default.LineNoOutput = checkBoxLineNo.Checked;
            Properties.Settings.Default.CompleteMsg = chkCompleteMsg.Checked;
            Properties.Settings.Default.SendToShortcut = chkSendToShortcut.Checked;
            Properties.Settings.Default.Save();
            Console.WriteLine("設定ファイル保存完了");

            // 送るフォルダのショートカット設定
            string sendtoDir = Environment.GetFolderPath(Environment.SpecialFolder.SendTo);
            string sendtoPath = Path.Combine(sendtoDir, Properties.Settings.Default.ShortcutName);
            if (chkSendToShortcut.Checked)
            {
                if (!System.IO.File.Exists(sendtoPath))
                {
                    IWshShell shell = new WshShellClass();
                    IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(sendtoPath);
                    shortcut.TargetPath = Assembly.GetEntryAssembly().Location;
                    shortcut.Description = Properties.Settings.Default.AppName + "を起動します。";
                    shortcut.Save();
                    Console.WriteLine("ショートカットファイル[" + sendtoPath + "]を作成しました。");
                }
            }
            else
            {
                if (System.IO.File.Exists(sendtoPath))
                {
                    System.IO.File.Delete(sendtoPath);
                    Console.WriteLine("ショートカットファイル[" + sendtoPath + "]を削除しました。");
                }
            }

            this.Close();
        }
예제 #55
0
        private void DoShortcut(string shortcutpath, string databasename, string target)
        {
            // Create a new instance of WshShellClass
             WshShell = new WshShellClass();
             string _localdatabasename = databasename;

             if (checkDBMenu1.Checked)
                 _localdatabasename = "AskUser";

             // Create the shortcut
             IWshRuntimeLibrary.IWshShortcut MyShortcut;

             // Choose the path for the shortcut
             MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(shortcutpath);

             // Where the shortcut should point to
             MyShortcut.TargetPath = target + "\\" + "picasastarter.exe";
             MyShortcut.WorkingDirectory = target;
             if (checkBackup.Checked)
             {
                 MyShortcut.Arguments = "/backup \"" + _localdatabasename + "\"";
                 // Description for the shortcut
                 MyShortcut.Description = "Backup custom database && Pictures";
             }
             else
             {
                 MyShortcut.Arguments = "/autorun \"" + _localdatabasename + "\"";
                 // Description for the shortcut
                 MyShortcut.Description = "Start Picasa with custom database";
             }

             // Location for the shortcut's icon
             MyShortcut.IconLocation = Application.StartupPath + @"\picasastarter.exe,0";

             // Create the shortcut at the given path
             MyShortcut.Save();
 
        }
예제 #56
0
        public static void RegistyCheck()
        {
            var fullName = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var thisPath = Directory.GetCurrentDirectory();
            //var iconPath = Path.Combine(thisPath, "Note.ico");
            var iconPathReg = "\"" + fullName + "\"" + "";
            var exePathReg = "\"" + fullName + "\"" + " \"%1\"";
            var exePathReg2 = "\"" + fullName + "\"" + " \"%V\"";
            //File
            Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Copy File Path", "Icon", iconPathReg, RegistryValueKind.String);
            Registry.SetValue(@"HKEY_CLASSES_ROOT\*\shell\Copy File Path\command", "", exePathReg, RegistryValueKind.String);
            //Folder
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Copy Folder Path", "Icon", iconPathReg, RegistryValueKind.String);
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\shell\Copy Folder Path\command", "", exePathReg, RegistryValueKind.String);
            //Inside folder
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Folder Path", "Icon", iconPathReg, RegistryValueKind.String);
            Registry.SetValue(@"HKEY_CLASSES_ROOT\Directory\Background\shell\Copy Folder Path\command", "", exePathReg2, RegistryValueKind.String);

            var schPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\SendTo\Copy As Path.lnk";
            //MessageBox.Show(fullName);
            //MessageBox.Show(thisPath);
            //MessageBox.Show(schPath);
            //MessageBox.Show(fullName);
            if (System.IO.File.Exists(schPath)) System.IO.File.Delete(schPath);
            WshShellClass wsh = new WshShellClass();
            IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(schPath) as IWshRuntimeLibrary.IWshShortcut;
            shortcut.Arguments = "";
            shortcut.TargetPath = fullName;
            // not sure about what this is for
            shortcut.WindowStyle = 1;
            shortcut.Description = "Copy As Path";
            shortcut.WorkingDirectory = thisPath;
            shortcut.IconLocation = fullName;
            shortcut.Save();
            MessageBox.Show("Success Install", "Success Install", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        /// <summary>
        /// Adds to startup folder.
        /// </summary>
        public void AddToStartupFolder()
        {
            //  Validate the parameters.
            ValidateParameters();

            //  Create the shell.
            var shell = new WshShellClass();

            //  Create the shortcut.
            var shortcut = (IWshShortcut)shell.CreateShortcut(GetShortcutPath());

            //  Set the target path.
            shortcut.TargetPath = ApplicationPath;

            //  Set the description.
            shortcut.Description = "Launch " + Path.GetFileNameWithoutExtension(ApplicationPath);

            // Location for the shortcut's icon
            //MyShortcut.IconLocation = Application.StartupPath + @"\app.ico";
            shortcut.IconLocation = ApplicationPath + ",0";

            //  Save the shortcut.
            shortcut.Save();
        }
예제 #58
0
        private void CreateShortcut()
        {
            if (string.IsNullOrEmpty(this.FilePath))
            {
                Log.LogError("FilePath is requried.");
                return;
            }

            if (string.IsNullOrEmpty(this.Name))
            {
                Log.LogError("Name is requried.");
                return;
            }

            if (string.IsNullOrEmpty(this.ShortcutPath))
            {
                this.ShortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }

            if (string.IsNullOrEmpty(this.Description))
            {
                this.Description = string.Format(CultureInfo.InvariantCulture, "Launch {0}", this.Name.Replace(".lnk", string.Empty));
            }

            this.LogTaskMessage(string.Format(CultureInfo.CurrentCulture, "Creating Shortcut: {0}", Path.Combine(this.ShortcutPath, this.Name)));
            WshShellClass shell = new WshShellClass();
            IWshShortcut shortcutToCreate = shell.CreateShortcut(Path.Combine(this.ShortcutPath, this.Name)) as IWshShortcut;
            if (shortcutToCreate != null)
            {
                shortcutToCreate.TargetPath = this.FilePath;
                shortcutToCreate.Description = this.Description;
                
                if (!string.IsNullOrEmpty(this.Arguments))                   
                {
                    shortcutToCreate.Arguments = this.Arguments;
                }

                if (!string.IsNullOrEmpty(this.IconLocation))
                {
                    if (!System.IO.File.Exists(this.IconLocation))
                    {
                        Log.LogError(string.Format(CultureInfo.InvariantCulture, "IconLocation: {0} does not exist.", this.IconLocation));
                        return;
                    }

                    shortcutToCreate.IconLocation = this.IconLocation;
                }

                if (!string.IsNullOrEmpty(this.WorkingDirectory))
                {
                    if (!System.IO.Directory.Exists(this.WorkingDirectory))
                    {
                        Log.LogError(string.Format(CultureInfo.InvariantCulture, "WorkingDirectory: {0} does not exist.", this.WorkingDirectory));
                        return;
                    }

                    shortcutToCreate.WorkingDirectory = this.WorkingDirectory;
                }

                if (this.WindowStyle > 0)
                {
                    shortcutToCreate.WindowStyle = this.WindowStyle;
                }
                
                shortcutToCreate.Save();
            }
        }
예제 #59
0
 /// <summary>
 /// Creates a link of the currFile in the start menu
 /// </summary>
 /// <param name="currFile"></param>
 private void createShortcut(string currFile, string iconLocation, string iconName)
 {
     string startMenuDir = Context.Parameters["StartMenuDir"];
     //throw new Exception("startMenuDir = " + startMenuDir + " currFile = " + currFile + " iconLocation = " + iconLocation);
     string shortcutName = startMenuDir + "\\" + Path.GetFileName(currFile) + ".lnk";
     WshShellClass WshShell = new WshShellClass();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@shortcutName);
     shortcut.TargetPath = @currFile;
     shortcut.Description = "Open " + Path.GetFileName(currFile);
     if((iconLocation != null) && (iconName != null)) {
         if(!iconName.StartsWith("\\")) {
             iconName = "\\" + iconName;
         }
         shortcut.IconLocation = iconLocation + @iconName;
     }
     shortcut.Save();
 }
예제 #60
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string localProdDirectoryRootedPath = @"C:\Code\PROD";
            string repositorySourceDirectoryUri = @"https://github.com/CosimoDeMedici/Duomo/trunk/Source"; // NOTE, http:// requires final '/' whereas svn:// does not.
            int repositorySourceDirectoryUriLength = repositorySourceDirectoryUri.Length;

            // TODO, will need to ensure no duplicate repository solution URIs.
            Dictionary<string, int> repositorySolutionUrisAndRevisions = new Dictionary<string, int>();
            repositorySolutionUrisAndRevisions.Add(@"https://github.com/CosimoDeMedici/Duomo/trunk/Source/Common/Applications/Gunther/Duomo.Common.Gunther.sln", 17);

            // Ensure that all repository solution URIs are in the source directory.
            Dictionary<string, int> repositorySolutionRelativeUrisAndRevisions = new Dictionary<string, int>();
            foreach (string curUri in repositorySolutionUrisAndRevisions.Keys)
            {
                if (curUri.Substring(0, repositorySourceDirectoryUriLength) == repositorySourceDirectoryUri)
                {
                    string solutionRelativeUri = curUri.Substring(repositorySourceDirectoryUriLength);
                    repositorySolutionRelativeUrisAndRevisions.Add(solutionRelativeUri, repositorySolutionUrisAndRevisions[curUri]);
                }
                else
                {
                    throw new ApplicationException(String.Format("Repository solution URI '{0}' was not within the repositoryl source directory URI '{1}'.", curUri, repositorySourceDirectoryUri));
                }
            }

            // Checkout (the checkout command will update if the directory already exists) the Lib directory. This assumes there is a 'Lib' directory as a sibling to the main 'Source' directory.
            string libFolderName = @"Lib";
            string localLibDirectoryRootedPath = Path.Combine(localProdDirectoryRootedPath, libFolderName);

            Uri uri = new Uri(repositorySourceDirectoryUri);
            string repositorySourceParentDirectoryUri = uri.GetParentUriString();
            uri = new Uri(repositorySourceParentDirectoryUri);
            string repositoryLibDirectoryUri = uri.AppendSegment(libFolderName);

            using (SvnClient client = new SvnClient())
            {
                SvnUriTarget target = new SvnUriTarget(repositoryLibDirectoryUri);
                client.CheckOut(new SvnUriTarget(repositoryLibDirectoryUri), localLibDirectoryRootedPath);
            }

            // For each solution, check out the solution's directory to the proper local path.
            WshShell wshShell = new WshShellClass(); // For creating a short-cut to the solution.
            foreach (string curRelativeUri in repositorySolutionRelativeUrisAndRevisions.Keys)
            {
                // Check out the solution.
                string curRepoRootedUri = repositorySourceDirectoryUri + curRelativeUri;
                Uri curRepoUri = new Uri(curRepoRootedUri);

                string solutionFileName = curRepoUri.GetLeaf();
                string solutionName = solutionFileName.Substring(0, solutionFileName.Length - 4);

                string localFolderName = Path.Combine(localProdDirectoryRootedPath, solutionName);
                if (!Directory.Exists(localFolderName))
                {
                    Directory.CreateDirectory(localFolderName);
                }

                string repoSolutionFolder = curRepoUri.GetParentUriString();
                string localSolutionFileRootedPath = localFolderName + curRelativeUri;
                FileInfo fInfo = new FileInfo(localSolutionFileRootedPath);
                string localSolutionDirectoryRootedPath = fInfo.DirectoryName;

                using (SvnClient client = new SvnClient())
                {
                    client.CheckOut(new SvnUriTarget(repoSolutionFolder), localSolutionDirectoryRootedPath);
                }

                // Create a short-cut to the solution file and place it in the local folder for the solution.
                string shortCutFileName = String.Format("{0} - Shortcut.lnk", solutionFileName);
                string shortCutFileRootedPath = Path.Combine(localFolderName, shortCutFileName);
                if (!System.IO.File.Exists(shortCutFileRootedPath))
                {
                    IWshShortcut shortCut = (IWshShortcut)wshShell.CreateShortcut(shortCutFileRootedPath);
                    shortCut.TargetPath = localSolutionFileRootedPath;
                    shortCut.Save();
                }

                // Now get the list of relative project paths by parsing the solution file.
                List<string> solutionFileLines = TextFileSerializer.DeserializeFromRootedPath(localSolutionFileRootedPath);

                List<string> projectLines = new List<string>();
                string projectSignifier = @"Project";
                foreach (string line in solutionFileLines)
                {
                    if (line.Length >= projectSignifier.Length && projectSignifier == line.Substring(0, projectSignifier.Length))
                    {
                        projectLines.Add(line);
                    }
                }

                List<string> relativeFilePaths = new List<string>();
                string[] separators = new string[] { "=", "," };
                foreach (string line in projectLines)
                {
                    string[] tokens = line.Split(separators, StringSplitOptions.None);
                    string relativePath = tokens[2].Trim().Trim('"');

                    if (@".." == relativePath.Substring(0, 2)) // Otherwise it's a subdirectory of the main solution directory, which has already been checked out.
                    {
                        relativeFilePaths.Add(relativePath);
                    }
                }

                // Now check out the folders containing each of the relative projects to their appropriate relative local paths.
                foreach (string relativeFilePath in relativeFilePaths)
                {
                    string relativeOtherProjectPath = Path.Combine(localSolutionDirectoryRootedPath, relativeFilePath);
                    string localOtherProjectRootedFilePath = Path.GetFullPath(relativeOtherProjectPath);
                    FileInfo localOtherProjectFileInfo = new FileInfo(localOtherProjectRootedFilePath);
                    string localOtherProjectDirectoryRootedPath = localOtherProjectFileInfo.DirectoryName;

                    if (!Directory.Exists(localOtherProjectDirectoryRootedPath))
                    {
                        Directory.CreateDirectory(localOtherProjectDirectoryRootedPath);
                    }

                    Uri repoOtherProjectUri = new Uri(repoSolutionFolder + relativeFilePath);
                    string repoOtherProjectFolderUri = repoOtherProjectUri.GetParentUriString();

                    using (SvnClient client = new SvnClient())
                    {
                        client.CheckOut(new SvnUriTarget(repoOtherProjectFolderUri), localOtherProjectDirectoryRootedPath);
                    }
                }
            }
        }