By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

Where is Word?

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Guy Lateur wrote:
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
Jul 19 '05 #2

P: n/a
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

"Peter Hansen" <pe***@engcorp.com> schreef in bericht
news:zN********************@powergate.ca...
Guy Lateur wrote:
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

Jul 19 '05 #3

P: n/a
Guy Lateur wrote:
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
Jul 19 '05 #4

P: n/a
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
Jul 19 '05 #5

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

Cheers,
g
"Guy Lateur" <gu********@b-b.be> schreef in bericht
news:uF**********************@phobos.telenet-ops.be...
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

Jul 19 '05 #6

P: n/a
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
Jul 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.