MS Office Windows File Associations via command line

Hello guys;

I need to create a batch file that will help me associate all MS Word extensions with MS Office word.exe

.doc
.dochtml
.docm
.docx
.docxml
.dot
.dothtml
.rtf
.wbk
.dotm
.dotx

We have environment that dose not allow us to associate the files automatically so we have to do it manually and not via registry in other words it must be a batch file.

 Can someone drop me some examples (step by step) on how I can accomplish that ? Thanks

LVL 2
atigrisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BeghemotCommented:
Please clarify the info about your environment...

So the batch file can not include commands that modify the registry?
or
Your access to the registry editing tools is disabled via policy and you need a script that can bypass the policy?

How do you normally "manually" create the associations?
0
uscshaggyCommented:
You can use the 'assoc' command for this.  You should check on a system that has the file associations that you want to confirm the proper commands.  You can do this by running 'assoc .doc' on that system and seeing what is returned.  On my XP box with Office 2003 and my 7 box with Office 2007 it shows:  .doc=Word.Document.8

Do this for each file type to get all the appropriate associations, and then create your script to set those same values.

So your batch file will simply be:


@echo off
assoc .doc=Word.Document.8
assoc .dochtml=wordhtmlfile
assoc .docm=Word.DocumentMacroEnabled.12
assoc .docx=Word.Document.12

Open in new window

0
atigrisAuthor Commented:
yes, we manually create them for each user by right clicking on a document let us say .doc  then choose "open with" and select the appropriate app in our case "MS Word"

So that means yes there will edit the registry. we want this process to be automated so one click it will assign all extensions to it's appropriate applications.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

BeghemotCommented:
uscshaggy's method is a great one. The assoc command can batch the changes you need.

http://support.microsoft.com/kb/323526
0
atigrisAuthor Commented:
Ok thanks guys but I don't know from where Word.Document.8, wordhtmlfile , Word.DocumentMacroEnabled.12 ...etc is coming from.

How to find these values as I have to do it for all MS office sweet and PDF

@echo off
assoc .doc=Word.Document.8
assoc .dochtml=wordhtmlfile
assoc .docm=Word.DocumentMacroEnabled.12
assoc .docx=Word.Document.12
0
atigrisAuthor Commented:
I tried ASSOCIATE .xls     "%SystemRoot%\Program Files\Microsoft Office\Office12\EXCEL.exe" /q /f

it will add it with no errors but when I try to click on the application it will not allow it to open and instead it shows "open with" to select the appropriate application.  

Can someone advice ?

Thanks
0
BeghemotCommented:
Ok at a command prompt at at machine where you manually loaded the associations type assoc >assoc.txt

This will send the output of the assoc commant to a textfile.  It generates a list of all the file associations on the machine.  You shouldn't have to point it at an executable, just at a preregistered file type.

For excel it would look something like this:


assoc .xls=Excel.Sheet.8

Open in new window

0
atigrisAuthor Commented:
Ok, My application is installed in isolation environment in other words .xls=Excel.Sheet.8 will now show up when I  type assoc in the command prompt  because the application is not installed on the system.

Is there anyway I can register this with the registry via command line ?
0
uscshaggyCommented:
Can you clarify your last comment?  Are you saying .xls=Excel.Sheet.8 does or does not show up when you type 'assoc'?

It shouldn't show up until you run the command to create the association.  Once you have run all the commands via batch script, then they should show up in the 'assoc' output and open with the appropriate application assuming it is installed.
0
plymelkCommented:
I believe that you are missing the ftype command.
The ftype command allows you to assign an action to the File Type.  This is an extra layer that allows each application to define their open action.  (From the registry, move actions are available).
 
 
C:\WINDOWS\system32>assoc .xls
.xls=Excel.Sheet.8
C:\WINDOWS\system32>ftype Excel.Sheet.8
Excel.Sheet.8="C:\Program Files\Microsoft Office\OFFICE11\EXCEL.EXE" /e
C:\WINDOWS\system32>

So your script should look like the attached code (Snippet ID=941675).
 

@echo off
ftype Word.Document.8="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype wordhtmlfile="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE"
ftype Word.DocumentMacroEnabled.12="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype Word.Document.12="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype Word.Template.8="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype wordhtmltemplate="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE"
ftype Word.RTF.8="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype Word.Backup.8="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype Word.TemplateMacroEnabled.12="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde
ftype Word.Template.12="C:\Program Files\Microsoft Office 2007\Office12\WINWORD.EXE" /n /dde

rem On the source system, wordxmlfile was undefined for ftype

assoc .doc=Word.Document.8
assoc .dochtml=wordhtmlfile
assoc .docm=Word.DocumentMacroEnabled.12
assoc .docx=Word.Document.12
assoc .docxml=wordxmlfile
assoc .dot=Word.Template.8
assoc .dothtml=wordhtmltemplate
assoc .rtf=Word.RTF.8
assoc .wbk=Word.Backup.8
assoc .dotm=Word.TemplateMacroEnabled.12
assoc .dotx=Word.Template.12

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.