简体   繁体   中英

How to run program from hidden folder WinAPI

I'm try to run program with this code:

    PROCESS_INFORMATION ProcInfo = { 0 };

    STARTUPINFO StartInfo = { 0 };
    StartInfo.cb = sizeof(StartInfo);

    if (!::CreateProcessW(NULL, (LPWSTR)wszPathToFile, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &StartInfo, &ProcInfo)) {
        return GetLastError();
    }

But I get error message: The system cannot find the path specified. wszPathToFile - path to file (example: "C:\\test\\test.exe /retest"). Folder "test" is hidden How to fix it?

That the folder is hidden is not relevant. That has no impact here.

As discussed in the comments, the fact that you are casting the lpCommandLine argument indicates that szPathToFile is not the correct type. It must be a pointer to a modifiable array of wide characters. If it was then you could omit the cast and the compiler would accept szPathToFile directly.

Most likely szPathToFile is actually a pointer to an array of ANSI encoded 8 bit char .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM