473,835 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\\Micr osoft\\Windows\ \CurrentVersion \\App Paths\\WORDPAD. EXE"
key = win32api.RegOpe nKey(win32con.H KEY_LOCAL_MACHI NE, item, 0,
win32con.KEY_QU ERY_VALUE)
info = win32api.RegQue ryValueEx(key, None)
win32api.RegClo seKey(key)
editor = win32api.Expand EnvironmentStri ngs(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 2859
"Patrick L. Nolan" <pl*@razzle.Sta nford.EDU> wrote in message
news:bu******** **@news.Stanfor d.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\\Micr osoft\\Windows\ \CurrentVersion \\App Paths\\WORDPAD. EXE" key = win32api.RegOpe nKey(win32con.H KEY_LOCAL_MACHI NE, item, 0,
win32con.KEY_QU ERY_VALUE)
info = win32api.RegQue ryValueEx(key, None)
win32api.RegClo seKey(key)
editor = win32api.Expand EnvironmentStri ngs(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("star t 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("star t 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.ShellE xecute, or better yet, the os.startfile function
calls ShellExecute, so you don't even need win32api:
import os
os.startfile('w ordpad.exe')


-Mike
Jul 18 '05 #3

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

Similar topics

3
11269
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 package. If I open and save the file manualy in Wordpad - it works. (not in Notepad otherwise formatting is changed and DTS package won't accept it.)
3
4106
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
4388
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 Button1_Click () x = Shell("c:\windows\system32\dllcache\WordPad.exe ", 1) SendKeys "%FOc:\cr\docs\packets\ntrolttr.rtf~", False End Sub
4
4282
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
2098
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
1745
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 seconds: Check to see if each of the other executables are running or not. If they are not running, it should load them. For this purpose, I am planning the following:
0
1786
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 same file? Here is my situation: I have an application that when launched does a check whether or not
0
934
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 allow me to open XYZ.txt directly in wordpad. help me to get above result thanks
1
3055
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 command: Shell "C:\Program Files\Windows NT\Accessories\wordpad.exe D:sam\a.wif" Will you please help me to save the a.wif file once the above command executed. Thanks in advance
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9653
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10815
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7770
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6970
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5808
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4435
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.