I use this line to open a txt file with notepad:
Shell "NOTEPAD.EXE " & App.Path & "\" & "Settings.ini", vbMaximizedFocus
which works fine, but the problem is that there are some txt files that don't show correctly with notepad and I need to open them with Word or Wordpad.
Since Wordpad is installed almost everywhere and Word is not, I'd like to open the file with Wordpad.
The problem is that I don't want to write the full path of the exe as it may not be the same in every system.
How do I do that? :-o
I have an idea of changing the file association to Wordpad, open the file and then change it back again to whatever it was, but I don't really know how to do that :-)
Well, here are some things to think about.
first, find out who your audience will be, meaning 98, ME, 2000, XP ect.... Find out the different paths for each OS and write some select case or if satements in your form load. The hard part is having your app figure what OS it is on. I use API's and there are soooo many different techniques. One would be "findsystemdirectory" and the outcome will decide which select case your program follows.
If you need some code let me know but a search here will produce more that enough info.
First of all, thank you for your reply.
My target OS is anything, Win 98, Me, 2000, NT, XP...
I think that recognizing the OS won't do exactly what I want as someone may install Wordpad in another directory.
Anyway, now I did this:
My program tries to find WORDPAD.EXE
First it looks at C:\Program Files\Accessories.
If it finds it, it uses that exe and it doesn't search again.
If not, then it will search drive C: for the file. If it finds it, it won't search again. If not, it will use Notepad as a last solution...
Of course it could look in other specific directories where it could be, but I have XP and I don't know where it should be in 98, Me, 2000, NT (Probably the same).
Of course if there is another way to launch wordpad without knowing its path and that doesn't depend on the OS, I'd prefer it :-)
Like worpad is in registry.
It may be under difefrent keys for different Os, but it will tell you where they are even if user was able to install them somewhere different from default.
Ie: on Win2K, registry key is
To quickly read the registry, use the followind code:
And don't forget to add the reference Windows Script Host Model
Const WORDPAD_REGISTRY_PATH = "HKEY_CLASSES_ROOT\Applications\WORDPAD.EXE\shell\open\command\"
Private Sub Command1_Click()
'Add a reference to Windows Script HOst Model
Dim objReg As New WshShell
Set objReg = Nothing
Last edited by JeffB; February 9th, 2003 at 12:17 PM.