CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Apr 2002

    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 :-)

  2. #2
    Join Date
    Dec 2002
    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

  3. #3
    Join Date
    Apr 2002
    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 :-)

  4. #4
    Join Date
    Jul 2000
    Milano, Italy

    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.

  5. #5
    Join Date
    Sep 2001
    Québec, Canada
    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
        MsgBox objReg.regread(WORDPAD_REGISTRY_PATH)
        Set objReg = Nothing
    End Sub
    Last edited by JeffB; February 9th, 2003 at 12:17 PM.
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  6. #6
    Join Date
    Feb 2000
    try this one:

    Private Sub Command1_Click()
    Shell "write.exe"
    End Sub
    Last edited by vin; November 20th, 2003 at 09: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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.