使用 ShellExecute 将参数传递给 ClickOnce

本文关键字:ClickOnce 参数传递 ShellExecute 使用 | 更新日期: 2023-09-27 18:32:48

我试图使用此博客将参数传递给离线点击一次应用程序。 在博客底部附近有示例程序可供下载。 我下载并发布了程序"TestRunningWithArgs"的C#版本。

现在我正在尝试将参数传递给不起作用的应用程序。 它一直说不"没有通过论据"。

我正在尝试使用以下代码来传递参数:

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

此代码运行应用程序,但示例应用程序声明它未收到参数。 该语言是视觉基础语言(也许是 4 或 6

下面的代码有效,允许互联网浏览器运行并从sharepoint打开特定文件,我想知道我是否缺少差异。

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

我看到的唯一一个是点击一次是 .application 文件与.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:''Users''userName''AppData''Local''Apps''2.0''5G9CGPWV.6O3''X7YPB07N.2Q2''test."中的.exe。tion_0000000000000000_0001.0000_03232931d88a66c9''"不起作用。

使用 ShellExecute 将参数传递给 ClickOnce

找到发送参数时必须调用的文件。

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

发布者名称在 Visual Studio 的"发布"选项卡、选项和"发布者名称"中指定。 这也是可以从中启动程序的"开始"菜单文件夹。