简体   繁体   English

获取正在启动exe的文件

[英]Getting file that is launching exe

I have been looking around for the solution to my problem, and found nothing. 我一直在寻找解决问题的方法,但没有发现任何问题。 How do you get the file that is being opened up by the default program that you set it to open up with? 如何获取被设置为打开程序的默认程序正在打开的文件? For example: if I have a file called HelloWorld.hello , and I set it up so that a program called Hello.exe will open when the file is clicked. 例如:如果我有一个名为HelloWorld.hello的文件,并且将其设置为单击该文件时将打开一个名为Hello.exe的程序。 How do I get the file that is launching Hello.exe ? 我如何获取正在启动Hello.exe的文件?

The problem is that calls to "execute HelloWorld.exe " go through a common methodology programmed into the OS - it's by definition an OS function to handdle execution requests. 问题在于,对“ execute HelloWorld.exe ”的调用会通过编程到OS中的通用方法进行处理-根据定义,这是一个OS函数来处理执行请求。 Thus, the most you'll ever get is your kernal for "what launched me?" 因此,您获得的最大收获就是您“启动了我什么?”的核心。

EDIT If you want to get the program that is executing current code, ie the entry point of an application, this is accessible via Environment.CommandLine . 编辑如果要获取正在执行当前代码的程序,即应用程序的入口点,则可以通过Environment.CommandLine访问。 Unless you're building a library accessed by multiple executables, this is not very useful, and if you are, there are few cases where the library should know what's calling it. 除非您要构建一个可被多个可执行文件访问的库,否则它不是很有用,如果是这样,则在少数情况下该库应该知道调用它的对象。

If you have control of the calling function, you may want to consider passing in some arguments during startup into the targeted program - these are accessible via the string[] parameter in Main 如果您可以控制调用函数,则可能要考虑在启动时将一些参数传递到目标程序中-可通过Mainstring[]参数访问这些参数。

EDIT Elaborating on the option to pass information into Main , you can actually have one of several signatures for your Main method. 编辑详细说明将信息传递给Main的选项,实际上您可以为Main方法使用多个签名之一。 Using the following: 使用以下内容:

static void Main(string[] args)

Will take any command line arguments and pass them into the args array. 将接受任何命令行参数,并将其传递到args数组。 Thus, if you called your program HelloWorld.exe (in windows) as 因此,如果您以以下方式调用程序HelloWorld.exe (在Windows中)

HelloWorld "alpha beta" delta gamma

then args will contains ["alpha beta", "delta", "gamma"] values. 那么args将包含["alpha beta", "delta", "gamma"]值。 Thus, passing in flags or enabling command line arguments becomes possible 因此,可以传递标志或启用命令行参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法获取Install Shield“ .exe”文件的“发布者”信息。 启动应用程序时 - Not getting “Publisher” information for an Install Shield “.exe” file. While launching the Application Windows服务启动和Exe - Windows Service launching and Exe 从exe文件获取解决方案 - Getting solution from exe file 启动隔离存储中存储的EXE - Launching an EXE stored in Isolated Storage 启动同一个exe的多个实例 - launching multiple instances of same exe 在浏览器或xbap中启动现有exe - launching existing exe in a browser or xbap EXE 文件未使用所需的图标进行编译 - EXE file not getting compiled with required icon 使用 Specflow 启动 Chrome 驱动程序时 - chromedriver.exe 文件不存在错误 - When Launching Chrome Driver using Specflow - chromedriver.exe file does not exist error 使用Process.Start()启动system32 \\ winsat.exe时出现“找不到文件”错误 - “File not found” error launching system32\winsat.exe using Process.Start() 以编程方式启动批处理文件(带有输出重定向)时冻结,当批处理文件仅调用“start some.exe”时 - Freeze when programmatically launching a batch file (with output redirection), when the batch file simply calls "start some.exe"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM