Re: copying files and folders- Design doubt
I would just use CopyFile() for the list of files instead of using VBScript.
You could easily create the folder tree if there is more than one folder
needed. You could even key off a list of files in your installation set.
Using CopyFile() allows you to have more control over what is appearing on
the screen.
I had an application where I had to copy a file then start it up and I used
code similar to the following:
bool CMyDlg::CopyAndRunProgram(TCHAR cThisDrive)
{
// Get tempfile folder and copy the file to the Windows Temp folder.
TCHAR strPath[sizeof(TCHAR) * MAX_PATH];
if(GetTempPath(sizeof(TCHAR) * MAX_PATH,strPath) == 0)
return false;
CString csTempProgramPath = strPath;
CString csProgramName = GetFileOnly(m_csProgramPath);
csTempProgramPath = AddPathAndFile(csTempProgramPath,csProgramName);
if(!CopyFile(csTempProgramPath,m_csProgramPath) )
return false;
// Start the other file
CString csParams;
csParams.Format(_T("\"%s\" -autostart:%c"),csTempProgramPath,
cThisDrive);
// CreateProcessW can modify Parameters thus we
// allocate needed memory
wchar_t * pwszParam = new wchar_t[csParams.GetLength() + 1];
if (pwszParam == NULL)
return false;
const wchar_t* pchrTemp = csParams.GetBuffer();
wcscpy_s(pwszParam, csParams.GetLength() + 1, pchrTemp);
// Start up the copy of the program
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si,sizeof(si)) ;
ZeroMemory(&pi,sizeof(pi));
si.cb=sizeof(si);
if(CreateProcess(NULL,pwszParam,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi)) {
//Wait for new copy to start
DWORD dwExit = WaitForInputIdle(pi.hProcess,5 * 1000);
}
delete[] pwszParam;
pwszParam = NULL;
// Release handles
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return true;
}
You could also use ShellExecute() of ShellExecuteEx() instead of the old
'system' function. I only went to this trouble becuase I wanted to wait
until the external program started up.
Tom
"Sudhakar" <Sudhakar@discussions.microsoft.com> wrote in message
news:A6C9C6B4-83FD-44CD-A857-FD126B769700@microsoft.com...
Hello ,
Design Issues:
I have an application , say, GMS. It is a VC++ application written in MFC.
Requirement:
************
At one point, GMS.exe(Win32 application) has to start a another external
application,say,GMS_upgrade.exe(Win32 application).
The GMS_Upgrade.exe copies files and folders hierarchy for the
GMSinstalled.
so, this will copy the GMS.exe also.
The design is ,
a)GMS.exe starts the GMS_Upgrade.exe,
b)GMS_Upgrade.exe waits until GMS.exe goes off and then it starts the
copying via copy.vbs(a separate VBScript invoked from
insdie GMS_Upgrade.exe)
I achieved the above said things.
After the GMS_Upgrade.exe is started , it has to copy the files and folder
hierarchy to the GMS installed path.
The copying process is written in VBScript. I start the VBScript inside
the
GMS_Upgrade via the C-runtime call,
system("D:\\copy.vbs")
My Doubts:
************
I have the following questions related to design,
1) Can the GMs_Upgrade.exe be an Win32 Console application ? It is started
by GMS but just waits until GMS goes off.
2) The copying process is done in VBScript. Copying the files and folders
is
done via VBScript.
Which is better approach, either copying the files and folders via
VBScript
or copying files and folders done via C++ ?? or
bothe approach are the same.
3) If Copying the files and folders via VBScript is OK, pls. suggest How
to
invoke the VBScript from inside C++ application.
I invoked via the call system("D:\\copy.vbs");
Does the above call will work in the platforms like, Windows XP, Windows
Vista
My another here is that , do I need to specify the "WSCript" is the host
for
the VBScript or it is considered by default in
all the above said platforms.
Thanks,
Sudhakar