473,382 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Launching Wordpad on Windows

I'm trying to find a clean way to launch a Wordpad editor
on Windows. By "clean", I mean that it should work on as
many versions of Windows as possible, and it shouldn't
require installing any extra software. I assume everyone
has win32api and its friends.

The problem is to find the path to wordpad.exe. At first
I just copied the path from my XP machine:
c:\Program Files\Windows NT\Accessories\WORDPAD.EXE

I verified that the same path works on W2K, but I don't
know about older versions. With some labor I was able
to come up with a longer, more obfuscated bit of code:

item = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\ \App Paths\\WORDPAD.EXE"
key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, item, 0,
win32con.KEY_QUERY_VALUE)
info = win32api.RegQueryValueEx(key, None)
win32api.RegCloseKey(key)
editor = win32api.ExpandEnvironmentStrings(info[0])

I would like to solicit learned opinions about this. Which
version will work in more versions of Windows? Is there a
better approach?

--
* Patrick L. Nolan *
* W. W. Hansen Experimental Physics Laboratory (HEPL) *
* Stanford University *
Jul 18 '05 #1
2 2836
"Patrick L. Nolan" <pl*@razzle.Stanford.EDU> wrote in message
news:bu**********@news.Stanford.EDU...
I'm trying to find a clean way to launch a Wordpad editor
on Windows. By "clean", I mean that it should work on as
many versions of Windows as possible, and it shouldn't
require installing any extra software. I assume everyone
has win32api and its friends.

The problem is to find the path to wordpad.exe. At first
I just copied the path from my XP machine:
c:\Program Files\Windows NT\Accessories\WORDPAD.EXE

I verified that the same path works on W2K, but I don't
know about older versions. With some labor I was able
to come up with a longer, more obfuscated bit of code:

item = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\ \App Paths\\WORDPAD.EXE" key = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, item, 0,
win32con.KEY_QUERY_VALUE)
info = win32api.RegQueryValueEx(key, None)
win32api.RegCloseKey(key)
editor = win32api.ExpandEnvironmentStrings(info[0])

I would like to solicit learned opinions about this. Which
version will work in more versions of Windows? Is there a
better approach?

--
* Patrick L. Nolan *
* W. W. Hansen Experimental Physics Laboratory (HEPL) *
* Stanford University *

This works for me:
(Using WinXP Pro)

Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
import os
os.system("start wordpad")

0

Hope this helps.

Adonis
Jul 18 '05 #2
> > I'm trying to find a clean way to launch a Wordpad
editor on Windows. By "clean", I mean that it should
work on as many versions of Windows as possible,
and it shouldn't require installing any extra software.
I assume everyone has win32api and its friends.

The problem is to find the path to wordpad.exe. At
first I just copied the path from my XP machine:
c:\Program Files\Windows NT\Accessories\WORDPAD.EXE

I verified that the same path works on W2K, but I
don't know about older versions.
Never hard code a path like that. It definitely won't work on all versions
of Windows. It won't even work on all XP systems. The Program Files
directory isn't always on the C: drive!
With some labor I was able to come up with a
longer, more obfuscated bit of code:

[code using the App Paths registry key]

I would like to solicit learned opinions about this.
Which version will work in more versions of
Windows? Is there a better approach?

You can do it with App Paths, but that's way too much work. It's not the
Windowsonic way to do it. :-)
This works for me:
(Using WinXP Pro)
import os
os.system("start wordpad") 0

Hope this helps.


I wouldn't recommend os.system. The problem is that it starts a command
shell. You didn't notice this because you're testing from a console window,
so the secondary command shell runs in the same console window you're
already using. But if you put this code in a non-console app, it will open a
new console window in addition to the WordPad window. That window will close
right away because you're using the 'start' command, but it's extra screen
activity you don't want.

So what's the right way to do it? The underlying Windows function you're
looking for is ShellExecute(). That's the easiest way to launch an app. It
knows all about App Paths and the environment PATH. It's the same function
that gets called if you do a Start/Run... in the Windows UI.

You can use win32api.ShellExecute, or better yet, the os.startfile function
calls ShellExecute, so you don't even need win32api:
import os
os.startfile('wordpad.exe')


-Mike
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Maya | last post by:
Hey, there! I'm new to vb.net and it seems I wouldn't be able to solve this without help. I have a pipe delimited file that has to be saved in txt format so it could be accepted by my DTS...
3
by: MLH | last post by:
Should this line work? x = Shell("WordPad.exe", 1) I get an error citing the 'file cannot be found'???
3
by: MLH | last post by:
I can open WordPad directly (Start, Run...), then open a document & click File, Send... Out goes the email without a hitch. However, if I open WordPad from Access this way... Sub...
4
by: Lorimer | last post by:
Thanks in advance for any help received. Is it possible to automatically display a text file in Wordpad using VB.NET and if so how do I do it? Thanks again L
24
by: Alan M Dunsmuir | last post by:
What is the command (in Windows Forms VB.NET) which will cause the subject computer's default browser to launch, and display a specified Web page? -- Alan M Dunsmuir
1
by: Water Cooler v2 | last post by:
I have a Windows Service I am writing in C# and a set of, let us say three, other executables written in C# (mostly console applications). I want that the Windows Service must do so every few...
0
by: microb0x | last post by:
Is there any difference in the way an Access .mdb file is launched from directly double-clicking the file through windows explorer versus using code within another Access file to launch the...
0
by: rupali77 | last post by:
hi i want to open my existing wordpad file on button click in vb.net for eq. if i click on button ABC tht shud allow me to open my ABC.txt file(wordpad) if i click on button XYZ tht shud...
1
by: vinoth124 | last post by:
Hi Friend, I need to open a "D:sam\a.wif" file in the wordpad then I need to save the same file immediately with out any updation and then I need to close it. For opening a file I used this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.