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!

Open File as Read-Only ?

Status
Not open for further replies.

Lemox

Programmer
Dec 13, 2003
67
GB
Hi there,

VB6 : I'm trying to open a file with appropriate registered windows application.

To do this, I use the Shell command this way (found it in the FAQ section) :

A = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & FilePath, vbMaximizedFocus)


This works quite well.
The problem is that the file should be open as read-only !
Is it possible by using this line in a different way ?

Or do I need something more 'complicated' ? Like ???

Thanks in advance !
Lemox
 
Thanks for your help : I now use the ShellExecute API.

And looking for further information about it, I found out the solution for the "read-only part" of my question :
I use the 'SetAttr' statement just like that :

SetAttr strFileName, vbReadOnly

Then I open the file with ShellExecute.


So easy to use... so hard to find within MSDN !!!
 
Oooooooooooops.... got a problem using ShellExecute !!

I always use it by setting the parameter 'lpFile' to the name of the file I want to open, not the executable used to open it.

No problem with MS-Word, Excel,... but if I try to open a simple '.txt', Notepad is NOT 'activated' !
EVEN IF THE PROCESS IS STARTED : I SEE IT IN MY TASK MANAGER.
THE NOTEPAD WINDOW SIMPLY DOESN'T APPEAR.

MSDN website says that if you specify a filename, parameter 'NShowCmd', which controls the way the application is displayed, should be set to zero.

(
Regarding my app, working with file names instead of application names is required...

Any idea ?
Thanx
 
just tell the shell command to open

filename="C:\MyFile2Open.txt"
"notepad.exe " & filename
^pass this to the shell command - but of course use your filename/location

also just for your future ref
in vb on the toolbar there is a button called "object broswer" (looks like an open box) if you would of went here you would of found the SetAttr under the FileSystem section along with other commands that have to due with using files - (*NOTE no api commands are listed in the object browser)

%, 2004
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top