我已经创建了一个程序,它通过打开的文件对话框生成一个特定EXE的快捷方式,使用一些库。我让它正常工作,但我希望程序向目标路径添加一个参数,使其看起来如下:("E:\Cod4\iw3mp.exe" +Seta Map mp_crash)。在不删除(+ Seta Map mp_Crash)或破坏.exe扩展的情况下,如何在"标记之后添加(.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)
// {
// }
}
}
}发布于 2013-08-28 14:47:25
根据你最新的问题,试试这个
shortcut.TargetPath = ofd.FileName;
shortcut.Arguments = "Seta Map mp_crash";发布于 2013-08-28 15:08:32
这就是你想做的吗?
var ofd = new OpenFileDialog();
ofd.ShowDialog();
string shortcut = '"' + ofd.FileName + '"' + " +Seta Map mp_crash";这应该是你想要的字符串的格式.
发布于 2013-08-29 04:30:38
感谢每一个人花时间去发现我无法发现的东西,特别是KeyboardP和他的工作代码
shortcut.TargetPath = ofd.FileName;
shortcut.Arguments = "Seta Map mp_crash";https://stackoverflow.com/questions/18491076
复制相似问题