簡體   English   中英

C#始終為0參數

[英]C# Always 0 Arguments

我已經將我的程序與此方法相關聯:

public static void CreateFileAssociation(string extension, string key, string description, string path)
{
    RegistryKey classes = Registry.ClassesRoot;
    RegistryKey extensionKey = classes.CreateSubKey(extension);
    extensionKey.SetValue(null, key);

    RegistryKey typeKey = classes.CreateSubKey(key);
    typeKey.SetValue(null, description);

    RegistryKey shellKey = typeKey.CreateSubKey("shell");
    RegistryKey shellOpenKey = shellKey.CreateSubKey("open");
    RegistryKey shellOpenCommandKey = shellOpenKey.CreateSubKey("command");
    shellOpenCommandKey.SetValue(null, path);
}

我的Program.cs

static void Main(string[] args)
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1(args.TryGet(0)));
}

和我的Form1.cs

string filenameArg = "";

public Form1(string arg)
{
    InitializeComponent();

    filenameArg = arg;
}

當我打開關聯的文件(擴展名)時,我的程序開始時沒有參數

不知道這是什么問題。 它出什么問題了 ?

您可能錯過了命令值中的%1

HKEY_CLASSES_ROOT\...\shell\open\command = ...appdata\local\myProgram\prog.exe "%1"

%1將替換為所選文件的路徑。 將其放在雙引號中,這樣帶有空格的路徑也將作為單個參數傳遞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM