I am using CreateProcessAsUser in C++ code to open an application impersonating a user. This works well, if an executable is given but fails with a non-executable file.

What is the simplest way to open non-executable files with their default application with CreateProcessAsUser.

I need a solution other than via:

cmd.exe /S /C ""path_to_my_file""
有帮助吗?

解决方案

The simplest solution is as follows:

  1. From the original process, process A say, use CreateProcessAsUser to create a new process, process B, say. Process B runs as a different user.
  2. Pass to process B command line arguments that specify the file that you want to open.
  3. From process B call ShellExecute or ShellExecuteEx to open the other file.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top