c - 如何使用 WinAPI 作为另一个用户启动通用应用程序?

标签 c winapi windows-10-desktop

如何使用 CreateProcessWithLogonW() 作为另一个用户启动通用应用程序?我无法使用 C:\\Windows\\System32\\cmd.exe/c start skype: 启动它,即使 start skype: 确实在终端中启动。

#include <stdio.h>
#include <windows.h>
#include <lmcons.h>

int main(void)
{
    PROCESS_INFORMATION pi = { 0 };
    STARTUPINFOW        si = { 0 };
    si.cb = sizeof(STARTUPINFOW);

    /*
    not working:
    L"C:\\Windows\\System32\\cmd.exe /c start skype"        error: "The filename, directory name, or volume label syntax is incorrect."
    L"C:\\Windows\\System32\\cmd.exe /c start skype:"       no error but a pop-up with text: "You'll need a new app to open this"
    */
    wchar_t lpCommandLine[] = L"C:\\Windows\\System32\\cmd.exe /c start skype:"; // lpCommandLine must be writable memory
    if (!CreateProcessWithLogonW(L"username", L".", L"password", LOGON_WITH_PROFILE, NULL, lpCommandLine, 0, NULL, NULL, &si, &pi))
    {
        printf("GetLastError(): %i\n", GetLastError());
        char buf[UNLEN + 1] = { 0 };
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, sizeof(buf), NULL);
        puts(buf);

        return 1;
    }
    else
    {
        // do stuff only while skype is running
        puts("skype is running.");

        if (WaitForSingleObject(pi.hProcess, INFINITE) == WAIT_FAILED)
            puts("WaitForSingleObject() failed");

        // do stuff only after skype exits
        puts("skype is NOT running.");
    }

    return 0;
}

最佳答案

这是不可能的。无论 UWP 应用在哪个用户下运行,它始终会在每个用户 session 都不同的沙盒 AppContainer 用户下运行。您不能使用 Win32 api 以其他用户身份运行 UWP 应用。

关于c - 如何使用 WinAPI 作为另一个用户启动通用应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53194771/

相关文章:

C mmap() 共享内存写入在其他进程中看不到

c++ - SetTimer(带回调函数)是否通过启动一个新线程来工作?

c++ - 软件许可类中的 Win32_WindowsProductActivation ProductID 等效项

c++ - VC++项目,如何定义DLL丢失错误信息?

c# - Windows 10 : How to determine whether a process is an App/Background Process/Windows Process

c - 字符串数组末尾为NULL(C编程)

c - 在 C 中使用 fts_children() 的意外结果

windows-10 - native 时钟可能与服务器时间不同步五分钟以上

c - 我的循环从不进入 if 语句

uwp - 通过App Installer安装UWP应用程序出现网络错误,依赖包丢失