我试图使用此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 \“,这是行不通的。