Solved

MS Office Windows File Associations via command line

Posted on 2010-08-17
10
1,513 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:atigris
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

12 Experts available now in Live!

Get 1:1 Help Now