in windows can you use ShellExecute, which is an API call that will allow you to spawn an application.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
well, it's included in the windows.h, so try this:
#include <iostream>
#include <windows.h>
int main(int argc, char **argv)
{
ShellExecute(NULL, "open", "C:\\windows\\system32\\calc.exe","", "C:\\", SW_NORMAL);
return 0;
}
EDIT: Negative. ShellExecute is NOT C++.... ShellExecute is a windows function that can be called from any language with the ability to use windows API's (C++ is such a language). This is windows specific, and won't work in *nix or Mac.... and is not a standard.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Or use.. execlp(...)
Which I believe is *nix only.....
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
you wouldn't change open to runas..... open is the "command" basically, that you are doing. What do you want to do with this file? Open it. Just like if I double clicked on it. calc.exe is a program in windows (all versions passed like 2.0). Runas is a program in vista. So replacing open with runas isn't going to work.... it's the wrong parameter. You need to replace calc.exe with runas, and somehow pass like calc.exe (and all the switches) to the parameters argument of shellexecute. It may be easier to use shellexecuteex as in the provided link above... so I guess something like this (not tested):
ShellExecute (NULL, "open", "runas", "test.bat", "c:\\", SW_NORMAL);
But based on the fact that you are in vista, and require elevated privs, I suggest using the shellexecuteex.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
it's actually on the link that you provided . If you look carefully, they are using ShellExecuteEx there. So, do that, and adjust it to your .bat file.
Comatose
Taboo Programmer
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
Above code works fine in windows XP, so perhaps some sort of vista thing?
The more important question is: Why would you want to execute a bat file? What's in it that you can't do with c++?
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403