Where is Word?

G

Guy Lateur

Hi all,

I need a way to get the path where MS Word/Office has been installed. I need
to start Word from a script (see earlier post), but it doesn't work if I
don't know its path. So "os.system("winword.exe %s" % fileName)" doesn't
always work; I need to say "os.system("C:\Program Files\Microsoft
Office\Office10\winword.exe %s" % fileName)".

Any ideas?

TIA,
g
 
P

Peter Hansen

Guy said:
I need a way to get the path where MS Word/Office has been installed. I need
to start Word from a script (see earlier post),

(Asking us to refer to some earlier post that may or may not even be
available on our news servers isn't the best way to get us the info. A
sentence or two summarizing would work best, I think.)

Can you describe what the user is going to do after Word pops open with
this file in it? Maybe there are simpler ways to do what you are trying
to accomplish, aside from the specific issue of how to open Word itself.

For example, maybe the work you plan to have the user accomplish can be
done automatically by controlling Word with COM.

-Peter
 
G

Guy Lateur

My original post is called "Start application & continue after app exits".
Is there a better way to refer to past posts, btw?

I want to make a temporary file (directory listing), open it in Word to let
the user edit, layout and print it, and then delete the temp file
afterwards. I don't think we'll be able to fully automate it, though. The
user should be able to set her own fonts and stuff.

g
 
P

Peter Hansen

Guy said:
My original post is called "Start application & continue after app exits".
Is there a better way to refer to past posts, btw?

No, the subject is a good way to refer to past posts. I just meant
forcing us to dig back, when the post may no longer even be on our
servers, is not helpful.
I want to make a temporary file (directory listing), open it in Word to let
the user edit, layout and print it, and then delete the temp file
afterwards. I don't think we'll be able to fully automate it, though. The
user should be able to set her own fonts and stuff.

I understand now. Definitely if you are doing this to allow customizing
fonts and such, at the user's whim, you can't automate it, by definition...

(Perhaps I should ask why anyone would want to waste time putting
arbitrary fonts and colours and such around a simple directory listing,
but I won't. <wink>)

-Peter
 
G

guy lateur

No, the subject is a good way to refer to past posts. I just meant
forcing us to dig back, when the post may no longer even be on our
servers, is not helpful.

I agree, my bad.

(Perhaps I should ask why anyone would want to waste time putting
arbitrary fonts and colours and such around a simple directory listing,
but I won't. <wink>)

Please don't.. ;)

g
 
G

guy lateur

Thanks for all the feedback, everyone. What a helpfull community this is!
It's actually kinda hard keeping up with y'all..

Cheers,
g
 
G

Guy Lateur

Ok, I've tried various proposed solutions, and this is what I've come up
with:

<code>
# get Word path
wordKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE,
'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths', 0, win32con.KEY_READ)
wPath = win32api.RegQueryValue(wordKey, 'winword.exe')
win32api.RegCloseKey(wordKey)

# open/write tempfile & delete afterwards
fD, fN = tempfile.mkstemp('.txt')
fH = os.fdopen(fD, 'w')
fH.write('blabla')
fH.close()
os.spawnl(os.P_WAIT, wPath, 'winword.exe', fN)
os.remove(fN)
</code>


The above seems to work ok, but if you run the script a second time without
first closing Word(1), the os.spawnl() doesn't seem to block. As a
consequence, the tempfile is not removed (because Word still has it open
when os.remove(fN) is called).

Is this behaviour normal? Anything I can do about this?

Thanks,
g
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,241
Messages
2,571,223
Members
47,859
Latest member
AidenNorth

Latest Threads

Top