472,348 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 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 2728
"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...
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...
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? ...
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?...
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...
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 ...
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...
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...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.