vendredi 8 juillet 2016

ShellExecute a cmd prompt with a specific working directory


I want to launch an elevated command prompt in Windows to a specific working directory. So for example, I have tried this:

ShellExecute(
    hWnd,
    L"runas",
    L"cmd.exe",
    NULL,
    m_szSelectedFile,
    SW_SHOW
);

Where m_szSelectedFile = L"C:\Users\User\Desktop"

ShellExecute is documented as

HINSTANCE ShellExecute(
  _In_opt_ HWND    hwnd,
  _In_opt_ LPCTSTR lpOperation,
  _In_     LPCTSTR lpFile,
  _In_opt_ LPCTSTR lpParameters,
  _In_opt_ LPCTSTR lpDirectory,
  _In_     INT     nShowCmd
);

Unfortunately, it always launches to C:WINDOWSsystem32. What am I doing wrong?


Aucun commentaire:

Enregistrer un commentaire