سؤال

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