ClickOnce application does not start through Process.Start(“x.abc”) with *.abc associated to the ClickOnce application

后端 未结 4 924
心在旅途
心在旅途 2020-12-30 03:02

I have successfully developed and deployed a ClickOnce application which registers an associated file extension, for instance *.abc. When I click on a file name

4条回答
  •  死守一世寂寞
    2020-12-30 03:25

    That only might start system wide extensions like .bat or even .txt, but it can't always launch correct programs through extensions.

    Instead try this API or a similar alternative in .NET:

    FindExecutable : shell32.dll Alias : "FindExecutableA" / "FindExecutableW" return type : int parameters : · lpFile Pointer to a null-terminated string specifying a filename. This can be a document or executable file. · lpDirectory Pointer to a null-terminated string specifying the default directory. · lpResult Pointer to a buffer to receive the filename when the function returns. This filename is a null-terminated string specifying the executable file started when an “open” association is run on the file specified in the lpFile parameter.

    This returns an integer bigger than zero if success and the char value will contain a null-terminated string that points to the executable that launches this file extension then you can use it like this

    System.Diagnostics.Process.Start ("program.exe $:\path\x.abc");
    

    Instead of program.exe, you'll use the result of the API function, and you'll use the path to the file separated with a space just like a command line.

    As for the application failure, it might indicate that the program needs administrative rights to run correctly. cmd already got administrative rights, so it can make child applications inherit it, but not windows API. createprocess allows you to use LPSECURITY attributes which can help in launching this program with the correct privileges.

提交回复
热议问题