2013-08-28 6 views
4

일부 라이브러리를 사용하여 열린 파일 대화 상자를 통해 선택한 특정 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) 
     // { 
     // } 
     } 
    } 
} 

답변

4

을 바탕으로,이

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

WindowsFormsApplication18.exe에서 'System.ArgumentException'형식의 처리되지 않은 예외가 발생했습니다. 추가 정보 : 값이 예상되는 범위에 들지 않습니다. – VoVb

+0

어떤 줄이 그 오류를 던집니까? 위의 코드는'label1.Text'의 값과 커맨드 라인 스위치를 따옴표로 둘러싼 문자열을 반환합니다. '{1} '바로 앞에'-'를 추가하여 인수를 구분할 수 있습니다. – keyboardP

+0

단축키. 대상 경로 – VoVb

1

당신이 뭘 하려는지 이것은 시도?

시간을 보내는마다 하나 고맙습니다
 var ofd = new OpenFileDialog(); 
     ofd.ShowDialog(); 
     string shortcut = '"' + ofd.FileName + '"' + " +Seta Map mp_crash"; 
당신이 그것을 할 방법 문자열을 포맷해야

...

+0

같은 오류 WindowsFormsApplication18.exe에서 'System.ArgumentException'유형의 처리되지 않은 예외가 발생했습니다. 추가 정보 : 값이 예상되는 범위 내에 있지 않습니다. – VoVb

1

어떻게 내가 할 수있는 발견하지 특히 ​​KeyboardP 자신의 작업 코드, 고맙습니다

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