Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Office Script

Status
Not open for further replies.

imarg

Technical User
Jun 5, 2006
18
CA
Hi everyone,

My department has a start up script that runs every time a user logs onto a computer that automatically sets various settings for Microsoft Office 2003 applications. The problem is that when a user logs onto a specific computer for the first time the script does not run properly and an error message is generated (From what I can tell, this is because the computer has to install office under the users profile). Any fixes that anyone can think of would be appreciated.

The idea I had were
1) for the script to start of by checking if the application was already set up.
or
2) Check if user had logged onto that workstation before.

If no to either, then supress the error message, let it run through the set up, and then rerun original script.

Unfortunately I am a bit of a newbie with MS script and am unsure on how to do either of the above.

Thanks,

Ilya
 

Your ideas seem as good as any but you haven't really given enough information for anybody to help. What is the script doing? What is the error message? etc.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
When the user logs in, the script activates office, inserts some default settings for the user (ie. Author name, sets a default save folder etc..), then closes word.

However if the user logs in for the first time, the script opens office, but can't proceed, because office is setting itself up.

Thanks.
 
This is still not enough detail. You mentioned Word. Are you saying this is only for Word? Yet you mention "Office". I am doubtful about a login script that sets "Author". If this is correct...it seems very overbearing, and could be much better handled by the use of templates.

What do you mean "the scipt opens office"????? Opens Office??? I have no idea what that means. Office is not really something that "opens".

More details please. Can you walk through step by step WHAT the script does?

Gerry
 
Here is the main part of the code

Set objSysInfo = CreateObject("ADSystemInfo")

strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

Set objWord = CreateObject("Word.Application")
objWord.UserName = objUser.givenName & " " & objUser.SN
objWord.UserInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1)
objWord.Quit


The seeings it applies are applied to all office applications. Let me know if this is enough detail.
 
One more thing, the script works perfectly 99% of time, but whenever a user uses his logon on a computer for the first time it doesn't.
 
Do you mean log on for the first time - after a reboot?
Do you mean log on for the first time - after they've logged off?
Do you mean log on for the first time - on a power up?

I do not understand why the script would be running "99% of time". WHEN is it running - other than "first" login?

Again...as asked tell us what is happening. We can not see when the script is running. YOU have to tell us. WHEN are the other times it may be run, and it DOES work?

Give an example of a NOT first time. A logon for the "second" time. Explain.

And - again - I see absolutely zero reason to be putting the Username and Initials into Word on logon. It seems truly odd. Why would this be run mor ethan once? But - perhaps if you actually explained the situation more. Is there no local machine running of Word?

The only thing I can suggest at this time, is an check for the UserName. If you are saying the "first" time (still rather undefined), then will the UserName be blank? You state Office is "setting up". I am not sure why that would be - but if it is, then UserName may be blank. Perhaps have error trapping for that.

Gerry
 

I think I understand what you mean. When a user logs on to a machine for the first time (ever), Word starts slowly because it is doing some initialisation, and asynchronously with your script and so your script is trying to use the application before it is initialised.

When a user logs on any time other than the first time ever on the machine you reset the Office user name and initials for them. Why do you need to do this? Do your users routinely change them? It seems unusual user behaviour and, if true, means that they are deliberately overriding your imposed settings - so your script is failing in its intention. If, on the other hand, your users aren't changing their names then your script is just slowing up their logons to no effect.

That just leaves when a user logs on for the first time ever and Office is started for that user. Your script would seem to be failing the only time it might ever have a useful effect and so is probably not the right way to do what you want. I'm no expert in this area but can you not use policies? Or roaming profiles? For that matter, what does Word default to?

If none of that helps, what you must do is wait for Word's startup to finish. It should be possible, though I don't know exactly how - and it won't be easy, to wait for notification. Generally people just code DoEvents loops (does that work in scripting?). In this case I'd be inclined to try and code an explicit wait (a second at a time?) if you get a failure (perhaps checking for the actual error you expect) and then retry.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Tony is right in his explanation. First time does mean the first time a user ever logs onto a workstation.

The user name is just one of the things that is changed. We also change the user's default save folder, and several other settings. The biggest reason for us doing this is because there is a specific format that every document that comes out of our department has to look like. This script accomplishes it.

What I am wondering I guess is if there is any way to check whether word has already been initialized. If I knew how to do that, my problem would be solved.

If anyone knows, let me know.

Cheers.
 

It seems like overkill to do this at every logon unless your users are in the habit of overriding what you set up which raises a lot of other questions.

I really don't have enough knowledge to give definitive answers but, as i understand it, roaming profiles (apart from other benefits) would mean that once a user had logged on once - somewhere on the network - their setup would be copied to wherever else on the network they logged on after that. And policies could be used to make sure that initial profiles were set up as you wanted without the need for ever starting Word at all.

If you really must do it the way you describe I guess you could check for the existence of registry keys (HKCU\Software\Microsoft\Office\(release number)) - or, for that matter, set them (but really that's the effect of policies so why not just use them?)

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

Professional Office Developers Association
 
Without rethinking if there is a better way of doing this you should be able to use TonyJollans idea and check for a reg key existance, something under Current User for office, not sure what to look for but there should be serveral keys that will only appear after the initial setup of Office completes.

If your settings only need to be run once(unless you are trying to reset the values) you could also use another key that is check each time they logon if it exists it will skip the rest of the script so that it doesn't have to fully run each time the logon.
 
Thanks folks... I think I may have a solution... Checking for the existance of
C:\Documents and Settings\USER\Application Data\Microsoft\Office

Since it appears that doesnt exist until after the first time the program is run.

Cheers
 
The biggest reason for us doing this is because there is a specific format that every document that comes out of our department has to look like. This script accomplishes it.
This is crazy. If the "biggest reason" for doing this is to have every document formatted a specific way...then for heaven's sake, just use a template!!

A document template will have every document made from that template be formatted the same way.

This is what templates as for! You can it set up for whatever format you want, default fonts, default headers, default graphics, default styles...everything you could possible want for a document. Author, file locations, automatic save routines...whatever.

This is what templates are for. Word is designed to use templates. They SHOULD be used. If that is the main reason, then there is no need for this scripting.

I would also ask how this is "accomplishing that"? Again, Word uses templates. Have you also got a template that you are using for Normal.dot? How is the format being accomplished? Certainly the code you posted does not do this.

Gerry
 
First off let me preface that this was done long before I joined the department, I am just doing some update work.

But maybe calling it format isn't the right word. What it really applies to is Word options... ie. a specific way to write Author Name, Initials.

Default save directories, things like that.

Cheers.
 
Well..OK. Sheesh, when I saw the "look like"....
The biggest reason for us doing this is because there is a specific format that every document that comes out of our department has to look like

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top