global template in code?

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

global template in code?

Post by Cecilia »

Hi Everyone!

I'm trying to make our global template install process a bit easier. Right now I have external files that copy the global template(s) to the Word Startup folder, a separate file that sets up registry entries, and a separate procedure that verifies that it's an activated add in. But I was thinking, why do I have to have an outside program install the template? Why can't I build it right into the template itself? Create a key combo that, no matter where my global template is located, it will copy itself to whatever startup folder the user has set?

Well, the reason right now is that when Word is open, the Word startup folder is locked. So I can't copy anything to the startup folder.

But...and I'm hoping someone (Hans? :D) can verify this logic and correct me if I'm getting too complicated...can't I change the startup folder, copy the file in, then change the startup folder back?

I'm working on this now, but if there is an easier way to do it, I'm all ears ;)

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

Trying to change the startup folder while Word is running is not a good idea.
Also, a template cannot copy itself to another folder because it is locked as in use while it is open.

But you probably don't need separate files for each of the following actions:
- Copy the template.
- Set up registry entries.
It should be possible to do this in one file.
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

haha I just discovered that I can't do it anyway. the startup folder stays locked no matter what. The big problem (okay, not that big, but it's confusing for other people) is that some people have their startup folders set somewhere else. So I can specify a startup folder in the external file, but it may or may not be the right startup folder. But I suppose I can have the file at least activate itself as an add in, that gets them part way there, at least to be functional.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

Which startup folder are you trying to use - the user's startup folder (by default C:\Users\<username>\AppData\Roaming\Microsoft\Word\STARTUP) or the generic one (something like C:\Program Files\Microsoft Office\Office12\STARTUP)?
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

User's startup folder...about 80% of users are initally set up this way, and since 79% of those people don't know how to (or why they would want to) change it, I get the most people using that place. About 20% of people are set up with the generic one, my old way was to change their startup back to the user's one, but now there are other people creating global templates and I have no control over them (and at the same time don't want to step on their toes or upset the users). So theoretically, it could be either place.

Maybe I should just copy the file to both places...? But then I have to worry about whether it's Office11, Office12, etc...very messy.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

I'd use the user's startup folder. You can get the actual location from the registry, if necessary.
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

OMG, that's too logical! lol my brain just exploded :D

I just found this on the MS site, but they say it hasn't been fully tested as of Office 2000 lol

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Microsoft\Word\Startup

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

It turns out that that registry key is not correct, and apparently the registry key changes based on the version of Word anyway, so it's another impossible situation. I'm giving up and going back to the multiple file system. Easier for my brain :(

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

Yes, the registry entry depends on the Office version: it's the STARTUP entry in

HKEY_CURRENT_USER\Software\Microsoft\Office\n.0\Common\General

where n is the internal version number of Office (n=10 for Office XP, n=11 for Office 2003, n=12 for Office 2007 and n=14 for Office 2010 - there is no version 13)
Best wishes,
Hans

User avatar
Sundog
5StarLounger
Posts: 704
Joined: 28 Jan 2010, 22:47
Location: Alien Country (Roswell NM)

Re: global template in code?

Post by Sundog »

HansV wrote:there is no version 13
Presumably those of us using Microsoft Office are unlucky enough already?
Sundog

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

The reason for skipping version 13 is indeed that it's considered to be an unlucky number - for the same reason highrise hotels usually don't have a 13th floor.
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

Oddly enough, on my system that key's value is simply "Startup".

There is supposed to be a key called "STARTUP-PATH" but it appears to not be on my system at all.

I like Sundog's answer at the moment.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

Aargh! I apologize. The entry in HKEY_CURRENT_USER\Software\Microsoft\Office\n.0\Common\General merely contains the NAME of the startup entry.

The path is the STARTUP-PATH entry in HKEY_CURRENT_USER\Software\Microsoft\Office\n.0\Word\Options. But if the user never changed the startup path, this registry entry may be missing; it will be added as soon as the user sets the startup path.
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

LOL I finally caught Hans!!! Of course it's a pretty obscure thing to catch you on. I figured out about the missing path while trying to write a batch file for this. Here's what I've got so far, it's not working yet, but I think I needed a new puzzle for today ;)

for /f "tokens=2,*" %%a in ('reg query "HKCU\Software\Microsoft\Office\11.0\Word\Options" /v STARTUP-PATH') do (set STARTUP_PATH=%%a)
if not defined STARTUP_PATH (set STARTUP_PATH="C:\Documents and Settings\%USERNAME%\Application Data\Microsoft\Word\STARTUP\" )
copy "%CD%\MyToolbar.dot" "%STARTUP_PATH%"
Last edited by Cecilia on 07 Feb 2011, 23:48, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78485
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: global template in code?

Post by HansV »

Perhaps our batch file expert John Gray can comment on that. I can never get my head round batch file syntax... :blush:
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

How cool! I had no idea we had one of those here!

Yeah, the syntax is a bit crazy, depending on how I call reg, sometimes it works, sometimes it doesn't (like in my code above) :(

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: global template in code?

Post by jscher2000 »

Cecilia wrote:I figured out about the missing path while trying to write a batch file for this.
You might find it easier to use VBScript on the Windows Script Host, since it has native registry reading and writing methods.

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15619
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: global template in code?

Post by ChrisGreaves »

Cecilia wrote:I'm trying to make our global template install process a bit easier.
Download the zip file with my Indxer from http://www.chrisgreaves.com/indxr.ca/
Read the ReadMe.txt and examine my Setup.dot.
It's been working for 15 years on Office 97/2000/2002/2003.
I haven't tested it yet on Office 2007/20010.
Please post any questions here.
There's nothing heavier than an empty water bottle

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

jscher2000 wrote:
Cecilia wrote:I figured out about the missing path while trying to write a batch file for this.
You might find it easier to use VBScript on the Windows Script Host, since it has native registry reading and writing methods.
Update: I found this site, http://computerperformance.co.uk/ezine/ezine62.htm" onclick="window.open(this.href);return false;, and OMG reading the registry is so much simpler! the other stuff is harder lol but at least it's somewhat familiar syntax. It actually turned out nicer than I imagined!!!

Read the startup path goes like this:
in a text file, extention .vbs

Code: Select all

Option Explicit
Dim objShell
Dim strStartup

strStartup="HKCU\Software\Microsoft\Office\11.0\Word\Options\STARTUP-PATH"
Set objShell = CreateObject("WScript.Shell")
strStartup = objShell.RegRead(strStartup) 

Wscript.Echo "Startup Path is " & vbTab & strStartup

WScript.Quit

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: global template in code?

Post by Cecilia »

Here's an odd one.

I created a vbs file to copy the template to the startup path as above. If I run the script directly from the shared drive where it lives, it runs fine (even with Sharepoint open). If I run it from a link to the file on the shared drive, it does everything except copy the template to the startup path, the startup path appears to be locked.

I'm confused. :(