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 * 2 2852
"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
> > 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.)
|
by: MLH |
last post by:
Should this line work?
x = Shell("WordPad.exe", 1)
I get an error citing the 'file cannot
be found'???
|
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
|
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
|
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
| |
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:
|
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
|
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
|
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
|
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...
|
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,...
| |
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |