C#ShortCut路径修改 [英] C# ShortCut Path Modification

查看:322
本文介绍了C#ShortCut路径修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个程序,该程序使用某些库生成通过打开的文件对话框选择的特定EXE的快捷方式.我可以使用它,但是我希望程序在目标路径中添加一个参数,使其看起来像这样:("E:\Cod4\iw3mp.exe" +Seta Map mp_crash).我该怎么做才能在"标记后添加(+ Seta Map mp_Crash)部分而不删除它或破坏.exe扩展名?

I've created a program which generates a shortcut to a specific EXE selected via the open file dialog, using some library. I got it to work but I want the program to add a parameter to the Target path to make it look like this: ("E:\Cod4\iw3mp.exe" +Seta Map mp_crash). What can I do to add the (+ Seta Map mp_Crash) part after the " mark without removing it or ruining the extension of the .exe?

这是我编写的用于添加参数的代码块:

Here is block of the code I wrote to add the parameter:

label1.Text = openFileDialog1.FileName;

shortcut.TargetPath = label1.Text + " Seta Map mp_crash";

shortcut.Save();

此代码会将seta部分添加到目标中,但会破坏扩展名,看起来像这样"E:\Cod4\iw3mp.exe Seta Map mp_crash "

This code will add the seta part to the target but it will ruin the extension and it will look like this "E:\Cod4\iw3mp.exe Seta Map mp_crash "

请帮助. 这是完整的代码:

Please help. here is the full code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IWshRuntimeLibrary;
using System.IO;

namespace WindowsFormsApplication18

{
    public partial class Form1 : Form

    {


        public Form1()

        {

            InitializeComponent( 
            );

        }
        public void CreateShortcut()
        {

            object shDesktop = (object)"Desktop";
            WshShell shell = new WshShell();
            string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Server.lnk";
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
            shortcut.Description = "Server Shortcut";
            shortcut.Hotkey = "Ctrl+Shift+N";
            var ofd = new OpenFileDialog();
            ofd.ShowDialog();
            shortcut.TargetPath = '"' + ofd.FileName + '"' + "+Seta Map mp_crash";
        }

        private void button1_Click(object sender, EventArgs e)
        {

            CreateShortcut();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          //  var ofd = new OpenFileDialog();
         //   ofd.ShowDialog();
        //    string shortcut = '"' + ofd.FileName + '"' + "+Seta Map mp_crash";
         //   openFileDialog1.DefaultExt = "EXE";
      //  / //  openFileDialog1.FileName = "Iw3mp.exe";
         //  DialogResult result2 = openFileDialog1.ShowDialog();
       //   label1.Text = openFileDialog1.FileName;
       //   a = label1.Text;

        //    if (result2 == DialogResult.OK) 
        //   {
        //    }
        }
    }
}

推荐答案

根据您更新的问题,尝试执行此操作

Based on your updated question, try this

shortcut.TargetPath = ofd.FileName;
shortcut.Arguments = "Seta Map mp_crash";

这篇关于C#ShortCut路径修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆