|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hello,
I have been looking for this for quite some time now, but I just can't seem to find a clear solution to the problem. I am trying to make a program which executed at the logon of Windows, and then run's a few programs in a specific order and also has to execute some commandlines. Now the easiest way is to use the SYSTEM() function, which enables you to do this up to a certain point. I am currently working in WxDev C++, altough what I am showing here is just some C programming really. Code:
#include <wx/file.h>
#include <wx/utils.h>
#include <stdlib.h>
int main (int argc, char* argv[])
system("SUBST Y: E:\Tools");
Sleep(100);
system("SUBST W: H:\Series");
Sleep(100);
// This works, but the following subst will not work
system("SUBST Z: "F:\Temporary Files"");
// The extra quotes (""), around the path confuses the SYSTEM function
// Now running some apps
system("start mIRC");
Sleep(4000);
system("start ICQ");
Sleep(11000);
return 0;
}
There are however a few drawbacks, first of all with the system command, I can not subst the third dir and secondly the system command is not the most subtle way to run applications (this I read somewhere). I searched the web for a few days now, but I can not find a solution to this although I expect I should switch to C++ (Either Borland or Visual C++) or maybe C# (Microsoft). There should be a replacement for the SYSTEM command right, because I think the SYSTEM() function is actually C programming, not C++. I came acros this: System.Diagnostics.Process.Start which should be worth a shot, can someone help me on the way? Even books I looked at did't cover running applications, it was mostly on Win32 API, making windows and stuff... Cheers, Daan |
| Sponsored Links |
|
|
|
|||||
|
The system()-function which can be find in cstdlib (stdlib.h), is the most common and most used function for doing command prompt commands. It's fast, cross-platform (though somebody thinks something else - explanation follows), and after all, the easiest to use.
Many people don't think system() is cross-platform, but it actually is. But that doesn't mean that the commands for system() is cross-platform, because they are not! So system() is fully "valid". Usually, you don't use system() function much though. Many of the operations are better done in C (or C++), so the need for the function is not big. You don't use it to start other application neither. There are two good alternatives for starting other applications. There are ShellExecute and CreateProcess, which both can be found in the windows-header (windows.h) ShellExecute is probably the easiest to use, though there's a lot of different ways to use it. If you just want to start another application, the easiest way to that, is f.ex. to create a function like this: Code:
void Start(LPCTSTR lpFile)
{
ShellExecute(NULL, "open", lpFile, NULL, NULL, SW_SHOWNORMAL);
}
Code:
#include <windows.h>
// ...
Start("C:\\WINDOWS\\system32\\cmd.exe"); // Start a command prompt
// The path can differ from system to system
You can find a lot information about the two alternatives, at MSDN. Click here for information about ShellExecute. Click here for information about CreateProcess. |
|
|||
|
Thanks v0id, that solved my problems as far as running some apps. I used the CreateProcess method which works quite well now. The remaining problem is executing some CMD commands (like ipconfig, subst, label or whatever).
On the msdn website there is someone who has some trouble executing a batch file: Quote:
Anyone had a suggestion? |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |