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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening files in read only mode.

Status
Not open for further replies.

WilliamGS

Programmer
Jan 21, 2004
54
PE
Hi all. I'm opening files with 'ShellExecute()', but sometimes I need them in read only mode. Is there some way to open a file in read only mode?.

Thanks in advance.

William GS.
 
It seems ShellExecute as is can't do that. If you specify open operation, it defines (in the registry) file open mode for the corresponding application...
 
If you use Shellexecute to open files for the SAME program, look out for the program line arguments , there mighrt be one that opens files as read-only (excel and word I think ahve this feature)

HTH,

s-)

Blessed is he who in the name of justice and goodwill, sheperds the weak through the valley of darkness...
 
You could modify the file with the code below and then open it. It is a bit of a work around but ShellExecute will open the file read only. Then you can reverse this with a
"&= ~(CFile::readOnly)"

Matt

CFileStatus fs;
CFile::GetStatus(fileName,fs);

fs.m_mtime=0;
fs.m_attribute |= (CFile::readOnly);

CFile::SetStatus(fileName,fs);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top