Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about console programs

Status
Not open for further replies.

Sidro

MIS
Sep 28, 2002
197
US
hi,
How would I ask this question? here it is...
To execute a console program for example, we do something like this," Ghost.exe -autoname, -split=650, -Z9 "
Im just using Norton Ghost as an example. Now I can put that command line thats in quotation on a batch file and execute it and thats what Ive been doing so far. That works but that method stinks because other people can read the command line just by opening up the batch file. I would like to accomplish this same task in a little sophisticated way. I want to create a console program and have the console program execute the command lines. How would I go about in doing it? Thankx in advance!
 
This is an extract of one of my programs.
As you can see there are a number of parameters that can be set, but this should be enough.
You might have to include the complete path to the excutable in CommandLine .. I don't really remember.

char CommandLine[256];
PROCESS_INFORMATION process_info;
STARTUPINFO startup_info;
BOOL brc;

// Init startup_info :
memset(&startup_info, 0, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
startup_info.lpReserved = 0;
//startup_info.lpDesktop = name; // Problem with this parameter !!
startup_info.lpTitle = name;
startup_info.dwX = 0;
startup_info.dwY = 0;
startup_info.dwXSize = 0;
startup_info.dwYSize = 0;
startup_info.dwXCountChars = 0;
startup_info.dwYCountChars = 0;
startup_info.dwFlags = 0;
startup_info.wShowWindow = 0;
startup_info.cbReserved2 = 0;
startup_info.lpReserved2 = 0;
startup_info.hStdInput = 0;
startup_info.hStdOutput = 0;
startup_info.hStdError = 0;

// Init process_info :
memset(&process_info, 0, sizeof(process_info));

// Build CommandLine :
strcpy(CommandLine, "Ghost.exe -autoname, -split=650, -Z9 ");

// Maybe "C:\\ProgramFiles\\Ghost\\Ghost.exe .......);

brc = CreateProcess(0, // lpApplicationName
CommandLine, // lpCommandLine
NULL, // lpProcessAttributes (Security)
NULL, // lpThreadAttributes (Security)
0, // bInheritHandles
NORMAL_PRIORITY_CLASS, // // dwCreationFlags
NULL, // lpEnvironment
NULL, // lpCurrentDirectory
&startup_info, // lpStartupInfo
&process_info); // lpProcessInformation

brc will be 0 in case of error. If so call GetLastError() to get errorcode.

/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top