Solved

MS Office Windows File Associations via command line

Posted on 2010-08-17
10
1,565 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:atigris
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:Beghemot
ID: 33461441
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
 
LVL 2

Expert Comment

by:uscshaggy
ID: 33461455
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
 
LVL 2

Author Comment

by:atigris
ID: 33465806
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
 
LVL 2

Expert Comment

by:Beghemot
ID: 33466567
uscshaggy's method is a great one. The assoc command can batch the changes you need.

http://support.microsoft.com/kb/323526
0
 
LVL 2

Author Comment

by:atigris
ID: 33466693
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 2

Author Comment

by:atigris
ID: 33466739
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
 
LVL 2

Expert Comment

by:Beghemot
ID: 33466998
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
 
LVL 2

Author Comment

by:atigris
ID: 33467295
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
 
LVL 2

Expert Comment

by:uscshaggy
ID: 33467555
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
 
LVL 2

Accepted Solution

by:
plymelk earned 500 total points
ID: 33477181
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

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now