-
February 8th, 2003, 07:01 PM
#1
Open a .txt with Wordpad, not notepad
Hi.
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, 11:30 PM
#2
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.
good luck
R.L.T.W. A+, NET+, CCNA
doin' my best
-
February 9th, 2003, 03:05 AM
#3
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, 05:06 AM
#4
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
Code:
HKEY_CLASSES_ROOT\Applications\wordpad.exe\shell\open\command
where you can find this value:
Code:
"%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, 01:13 PM
#5
To quickly read the registry, use the followind code:
And don't forget to add the reference Windows Script Host Model
Code:
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
MsgBox objReg.regread(WORDPAD_REGISTRY_PATH)
Set objReg = Nothing
End Sub
JeffB
Last edited by JeffB; February 9th, 2003 at 01:17 PM.
-
November 20th, 2003, 10:37 AM
#6
try this one:
Private Sub Command1_Click()
Shell "write.exe"
End Sub
Last edited by vin; November 20th, 2003 at 10:39 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|