일부 라이브러리를 사용하여 열린 파일 대화 상자를 통해 선택한 특정 EXE에 대한 바로 가기를 생성하는 프로그램을 만들었습니다. 나는 그것을 작동시키지 만 프로그램이 Target 경로에 매개 변수를 추가하여 다음과 같이 만들도록하고 싶습니다 : ("E:\Cod4\iw3mp.exe" +Seta Map mp_crash
). .exe의 확장자를 제거하거나 제거하지 않고 "
표시 뒤에 (+ Seta Map mp_Crash
) 부분을 추가하려면 어떻게해야합니까? 여기C# ShortCut 경로 수정
내가 매개 변수를 추가하기 위해 작성한 코드의 블록 :
label1.Text = openFileDialog1.FileName;
shortcut.TargetPath = label1.Text + " Seta Map mp_crash";
shortcut.Save();
대상에 세타 파트를 추가하지만이 확장을 파괴하고는이 "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)
// {
// }
}
}
}
WindowsFormsApplication18.exe에서 'System.ArgumentException'형식의 처리되지 않은 예외가 발생했습니다. 추가 정보 : 값이 예상되는 범위에 들지 않습니다. – VoVb
어떤 줄이 그 오류를 던집니까? 위의 코드는'label1.Text'의 값과 커맨드 라인 스위치를 따옴표로 둘러싼 문자열을 반환합니다. '{1} '바로 앞에'-'를 추가하여 인수를 구분할 수 있습니다. – keyboardP
단축키. 대상 경로 – VoVb