Re: CAB Files by Lucian
Lucian
Thu Jul 17 05:26:45 CDT 2003
Alberto Silva wrote:
>I've made them read-only on the desktop... perhaps it looses the read-only
>attribute when copied to the file store, although it doesn't loose it when
>copied to the main memory or to the SD card.
>I've seen this behaviour on the ipaq 3870, 3970 and 5450
Ah, sorry, I failed to read your message carefully enough.
* In main memory, and on SD card, setting 'readonly' prevents the cab
from being deleted, as expected.;
* On my iPAQ, for a cab file in \\iPAQ File Store, the 'readonly' flag
fails to prevent its deletion. I reckon this is a bug.
I experimented a bit. If you keep an open file handle on the cab file,
then it won't get deleted. Something like this:
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPWSTR,int)
{ const wchar_t *fn = L"\\iPAQ File Store\\uninstall.cab";
CopyFile(L"\\My Documents\\uninstall.cab",fn,FALSE);
const wchar_t *cmd = L"\\windows\\wceload.exe";
wchar_t arg[MAX_PATH]; wsprintf(arg,L"\"%s\"",fn);
//
HANDLE hf =
CreateFile(fn,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,0);
//
PROCESS_INFORMATION pi;
BOOL res=CreateProcess(cmd,arg,0,0,0,0,0,0,0,&pi);
if (!res) MessageBox(NULL,L"Couldn't",L"ce_setup",MB_OK);
else
{ WaitForSingleObject(pi.hProcess,10000);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
MessageBox(NULL,L"done",L"cab",MB_OK);
CloseHandle(hf);
MessageBox(NULL,L"closed",L"cab",MB_OK);
return 0;
}
It's hard to know how long to wait for the process to terminate. If it
pops up a UI and waits for user confirmation, it might end up taking
ages. I normally use /noaskdest and /noui to prevent any dialogs from
being displayed. (and I also write in the registry to prevent the
"overwrite?" dialog from being displayed). With these assumptions, 10
seconds is probably safe.
--
Lucian