2013-09-24 120 views
0

我試圖使用此Blog將參數傳遞給脫機一次性應用程序。在博客底部附近有一些示例程序可供下載。我下載併發布了程序「TestRunningWithArgs」的C#版本。將參數傳遞給ClickOnce使用ShellExecute

現在我試圖將參數傳遞給不工作的應用程序。它一直說不「傳入任何參數」。

我嘗試使用下面的代碼來傳遞參數:

shellexecute("File Path\My Applicaiton.application","MyArgument")

此代碼運行應用程序,但示例應用程序聲明它沒有收到一個參數。語言是可視化的基礎(可能是4或6?)。

下面的代碼工作,並允許Internet Explorer運行,並從Sharepoint打開特定的文件,我想知道是否有差異,我失蹤。

shellexecute("C:\Program Files\Internet Explorer\iexplore.exe",FileLocation)

唯一一個我看到的是一次點擊是。應用文件Vs的.exe和有沒有辦法得到這個工作?

下面是點擊一次應用程序的代碼,從提供的示例程序只是複製在博客上

public partial class MainForm : Form 
{ 
public MainForm() 
{ 
    InitializeComponent(); 
    GetArgsToShow(); 
} 

/// Get the arguments and show them on the screen. 
private void GetArgsToShow() 
{ 
    // Get the ActivationArguments from the SetupInformation property of the domain. 
    string[] activationData = 
     AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData; 

    if (activationData != null && activationData.Length > 0) 
    { 
     //querystring starts with ?; file association starts with "file:" 
     if (activationData.Length == 1 && activationData[0].Substring(0, 1) == "?") 
     { 
      ProcessQueryString(activationData); 
     } 
     else if (activationData.Length == 1 && activationData[0].Length >= 5 && activationData[0].Substring(0,5).ToLower() == @"file:") 
     { 
      ProcessFileAssociation(activationData); 
     } 
     else 
     { 
      ProcessCSVParameters(activationData); 
     } 
    } 
    else 
    { 
     if (activationData == null) 
     { 
      lstArgs.Items.Add("No arguments passed in."); 
     } 
     else 
     { 
      lstArgs.Items.Add(String.Format("Number of args = {0}", activationData.Length)); 
     } 
    } 

} 

/// Convert a query string into Name/Value pairs and process it. 
private void ProcessQueryString(string[] activationData) 
{ 
    NameValueCollection nvc = 
     System.Web.HttpUtility.ParseQueryString(activationData[0]); 

    //Get all the keys in the collection, then pull the values for each of them. 
    //I'm only passing each key once, with one value. 
    string[] theKeys = nvc.AllKeys; 
    foreach (string theKey in theKeys) 
    { 
     string[] theValue = nvc.GetValues(theKey); 
     lstArgs.Items.Add(string.Format("Key = {0}, Value = {1}", theKey, theValue[0])); 
    }     
} 

/// Process what you would get if you set up a file association, 
/// and the user double-clicked on one of the associated file. 
private void ProcessFileAssociation(string[] activationData) 
{ 
    //This is what you get when you set up a file association and the user double-clicks 
    // on an associated file. 
    Uri uri = new Uri(activationData[0]); 
    lstArgs.Items.Add(uri.LocalPath.ToString()); 
} 

/// Process a comma-delimited string of values. Not: can't have spaces or double-quotes in the string, 
/// it will only read the first argument. 
private void ProcessCSVParameters(string[] activationData) 
{ 
    //I have to say here that I've only ever seen 1 entry passed in activationData, 
    // but I'm checking for multiples just in case. 
    //This takes each entry and splits it by comma and separates them into separate entries. 

    char[] myComma = { ',' }; 

    foreach (string arg in activationData) 
    { 
     string[] myList = activationData[0].Split(myComma, StringSplitOptions.RemoveEmptyEntries); 
     foreach (string oneItem in myList) 
      lstArgs.Items.Add(oneItem); 
    } 
} 
} 

編輯 嗯,我試圖訪問存放在「C中的.exe:\ Users \ userName \ AppData \ Local \ Apps \ 2.0 \ 5G9CGPWV.6O3 \ X7YPB07N.2Q2 \ test..tion_0000000000000000_0001.0000_03232931d88a66c9 \「,這是行不通的。

回答

0

找到您必須調用以發送參數的文件。

shellexecute("C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\(Publisher Name)\My Application.appref-ms", Arguement)

發佈者的名稱在Visual Studio中指定的發佈選項卡,選項,然後出版商名稱。這也是您的程序可以從中啓動的開始菜單文件夾。