我创建了一个程序,使用某个库通过打开文件对话框生成到特定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)
// {
// }
}
}
}
label1.Text
的值和命令行开关。你可以在{1}
之前添加一个-
来分隔参数。 - keyboardP