Simple Question

closed account (LN7oGNh0)
Is it possible to make code that will open up microsoft office word? (And when I mean open, I mean it will be the same as clicking on it. Without clicking on it...) Seems a bit pointless, but I really want to know! And if it is possible, then how???

Thanks.
Last edited on
1
2
3
4
5
6
7
8
9
#include <windows.h>

int main()
{
    const char *path = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs"
                       "\\Microsoft Office\\Microsoft Office Word 2007.lnk";

    ShellExecute(NULL,NULL,path,NULL,NULL,SW_SHOWNORMAL);
}
closed account (LN7oGNh0)
I tried compiling the program, but I got an error:

error C2664: 'ShellExecuteW' : cannot convert parameter 3 from 'const char *' to 'LPCWSTR'
Last edited on
@tntxtnt
ShellExecute requires you pass it a LPCWSTR*, while you're passing it a C literal string.
In order for that to compile properly, you can either use ShellExecuteA (which will accept that as a parameter) instead, or do this:
1
2
3
4
const wchar_t *path = L"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs" //notice the L prefix
                       "\\Microsoft Office\\Microsoft Office Word 2007.lnk";

ShellExecute(NULL, NULL, path, NULL, NULL, SW_SHOWNORMAL);

Topic archived. No new replies allowed.