struggling_coder_3203
asked on
command
I have a visual c++ program that envokes the command prompt. The problem is every time I create a process the command prompt window opens, and it executes. This is all fine...however, if my program is going to execute a hundred commands, or even a thousand, the command prompt window is constantly opening and closing. If this is the case, then the computer won't be usable while the program is running because the command prompt window constantly opens. Any suggestions????
500 pts
500 pts
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In addition, with ShellExecute you can also specify how you want your process' window to be (e.g. hidden, maximized, minimized, etc)
ASKER
well right now i am using "CreateProcess" and "system"....
ASKER
so with shell execute, i will be able to run my program in the background without having the command prompt pop up every couple seconds and steal focus???
Yes, you can specify whether you want you process' window to be hidden, maximized, etc2.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp
ASKER
how would i use ShellExecute to move a file from one folder to another??
or un an .exe????
or un an .exe????
ASKER
or run an .exe???
I don't think you can use ShellExecute directly to move files. To run an exe, just call ShellExecute with the lpOperation parameter as "open" and lpFile as the name of the executable.
ASKER
well, but i am moving a lot of files in my program....
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could turn your project from Win32 Console Application to Win32 Application. Your main function turns to WinMain
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
and if you did evaluate the commandline arguments in main, you now have to parse the lpCmdLine argument.
In link settings you have to change option
/subsystem:console
to
/subsystem:windows
Regards, Alex
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
and if you did evaluate the commandline arguments in main, you now have to parse the lpCmdLine argument.
In link settings you have to change option
/subsystem:console
to
/subsystem:windows
Regards, Alex
Simplest way I know is to use WinExec() function:
WinExec(some command here, SW_HIDE);
WinExec(some command here, SW_HIDE);
Wait a second, if you're moving a file, isnt it important to know if the file move actually WORKED?
I would write my own file move function, something along the lines of:
Err = rename( oldname, newname );
if( Err != NoError ) { printf("cant rename %s to %s, doing byte copy\n", oldname, newname );
in = fopen( oldname, "r" ); out = fopen( newname, "w" );
if( in == Error ){ printf("cant open %s for reading!!!\n", oldname ); return( -1 ); }
else
{
if( Out == Error ){ printf("cant open %s for writing!!!\n", newname ); return( -2 ); }
else
{
while( ! feof( in ) ) { rd = fread( buf, inlen, &inact, in );
if( rd < 0 ) { printf("Error reading input file!\n"); return(-3); }
else { wt = fwrite( buf, inact, outact, out );
if( wt < 0 ) { pritnf("Error writing!" ); return( -4 ); }
}
err = fclose( in ); if( err... )
err = fclose( out ); if( err ... )
}
return(0);
}
// note, you have to declare all varaibles, check param lists and error checks for accuracy....
I would write my own file move function, something along the lines of:
Err = rename( oldname, newname );
if( Err != NoError ) { printf("cant rename %s to %s, doing byte copy\n", oldname, newname );
in = fopen( oldname, "r" ); out = fopen( newname, "w" );
if( in == Error ){ printf("cant open %s for reading!!!\n", oldname ); return( -1 ); }
else
{
if( Out == Error ){ printf("cant open %s for writing!!!\n", newname ); return( -2 ); }
else
{
while( ! feof( in ) ) { rd = fread( buf, inlen, &inact, in );
if( rd < 0 ) { printf("Error reading input file!\n"); return(-3); }
else { wt = fwrite( buf, inact, outact, out );
if( wt < 0 ) { pritnf("Error writing!" ); return( -4 ); }
}
err = fclose( in ); if( err... )
err = fclose( out ); if( err ... )
}
return(0);
}
// note, you have to declare all varaibles, check param lists and error checks for accuracy....
ASKER
i cannot seem to get any of your suggestions to work for moving a file to a new directory...any examples???
thanks
thanks
MoveFileEx ( "c:\\dir1\\sample.txt", "c:\\dir2\\sample2.txt", MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) ;
would do the job...
would do the job...