我试图使用此博客将参数传递给离线单击一次应用程序。在博客底部附近有示例程序可供下载。我下载并发布了 C# 版本的程序“TestRunningWithArgs”。
现在我试图将一个参数传递给不起作用的应用程序。它一直说没有“没有传入参数”。
我正在尝试使用以下代码来传递参数:
shellexecute("File Path\My Applicaiton.application","MyArgument")
此代码运行应用程序,但示例应用程序声明它没有收到参数。语言是视觉基础的(可能是 4 或 6?)。
下面的代码可以运行并允许 Internet Explorer 运行并从共享点打开特定文件,我想知道是否存在我遗漏的差异。
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..tion_0000000000000000_0001.0000_03232931d88a66c9\”中的.exe,但它不起作用。