February 8th, 2003, 06:01 PM
Open a .txt with Wordpad, not notepad
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 :-)
February 8th, 2003, 10:30 PM
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.
R.L.T.W. A+, NET+, CCNA
doin' my best
February 9th, 2003, 02:05 AM
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 :-)
February 9th, 2003, 04:06 AM
Path of installed components
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
where you can find this value:
"%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" "%1"
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
February 9th, 2003, 12:13 PM
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.
November 20th, 2003, 09:37 AM
try this one:
Private Sub Command1_Click()
Last edited by vin; November 20th, 2003 at 09:39 AM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!