4

ライブラリを使用して、[ファイルを開く] ダイアログで選択した特定の EXE へのショートカットを生成するプログラムを作成しました。私はそれを動作させましたが、プログラムがターゲットパスにパラメーターを追加して、次のように見えるようにしたいです: ( "E:\Cod4\iw3mp.exe" +Seta Map mp_crash)。+ Seta Map mp_Crashマークの後に ( ) 部分"を削除したり、.exe の拡張子を壊したりせずに追加するにはどうすればよいですか?

パラメータを追加するために私が書いたコードのブロックは次のとおりです。

label1.Text = openFileDialog1.FileName;

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

shortcut.Save();

このコードは seta 部分をターゲットに追加しますが、拡張機能を台無しにし、次のようになります"E:\Cod4\iw3mp.exe Seta Map mp_crash "

助けてください。完全なコードは次のとおりです。

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) 
        //   {
        //    }
        }
    }
}
4

3 に答える 3

5

更新された質問に基づいて、これを試してください

shortcut.TargetPath = ofd.FileName;
shortcut.Arguments = "Seta Map mp_crash";
于 2013-08-28T14:47:25.140 に答える
1

これはあなたがやろうとしていることですか?

        var ofd = new OpenFileDialog();
        ofd.ShowDialog();
        string shortcut = '"' + ofd.FileName + '"' + " +Seta Map mp_crash";

それはあなたが望むように文字列をフォーマットするはずです...

于 2013-08-28T15:08:32.220 に答える