![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Set File Type Associations Hi, I need to be able to set the default file associations for word,excel and powerpoint etc when a user logs in. We are using terminal services and roaming profiles. We have migrated some of our users to open office, so their profiles need to be updated to use swriter for word documents, calc for excel etc. I can do this manually for each user as they phone up; by right clicking say a spreadsheet and select open with, select scalc.exe and check always open with this program (which is rather tedious as we have about 300 users). I have tried the assoc command in a batch file under a normal user account; but i think this needs admin rights to work because i get an 'error in processing'? Is there a way I can do this through a vbscript? Thanks in advance Matt |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Set File Type Associations You can do it with VBScript. Each file extension has a key under HKCR, with a default value that points to a "class" key in HKCR. The default program is there. Example: HKCR\.txt\ default value: "txtfile" HKCR\txtfile\shell\open\command\ default value: "C:\windows\notepad.exe %1" That's the basic template. In some cases programs will write their own commandline parameters into the value. The basic formula of "[path] %1" should work, but as long as you're dealing with a single, known change it might be a good idea to check exactly what OO writes to the Registry. I've come across cases in the past where a program seems to have a "brittle" parsing technique and fails to open a file if the command line is not just right. To do the writing of values, see the RegWrite method of WScript.Shell. It's fairly simple: Dim SH, s, sCommand sCommand = "C:\windows\notepad.exe %1" Set SH = CreateObject("WScript.Shell") s = SH.RegRead("HKCR\.txt\") SH.RegWrite "HKCR\" & s & "\shell\open\command\", sCommand, "REG_SZ" Set SH = Nothing That's "air code". The first parameter is the path. A "\" at the end writes the default key value. Without "\", the last section is the value name. I don't remember offhand whether RegWrite will create a series of non-existing keys. You might need to go through those steps if OO hasn't written the values. I use something like the following as a simple "Does the key exist?" function: Public Function Exists(RegPath) Dim r On Error Resume Next Err.clear r = SH.RegRead(RegPath) If hex(Err.number) = "80070002" Then Exists = False Else Exists = True End If End Function If OO has already written all of the needed values then you just need to switch the extension value. In other words, the whole thing hinges on what Windows finds at HKCR\.doc. That value is like the train track switch: Everything from there will go in the direction you point it. For instance, on my own system I have the data "OpenOffice.org.doc" under HKCR\.doc\. If I switched that to "Txtfile" then Notepoad would open my .doc files. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Set File Type Associations mayayana wrote: Quote: > HKCR\txtfile\shell\open\command\ > default value: "C:\windows\notepad.exe %1" > a file to some utility (for example a txt file to an editor), I like to wrap the parameter in quotes: D:\TextEditors\EditPlus\Editplus.exe "%1" In case the filepath contains blanks, wrapping it in quotes will get the entire path sent to the utility, instead of just the path -- up to the first blank. cheers, jw |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Set File Type Associations Thanks for the assistance on this; it did point me in the right direction. I thought i would post my findings so if anyone else has the same problem. In my case it was trying to default to open office, but you could use it for any application. The only thing with HKCR is that you need to be a local admin to make changes. HKCR I think will also only change it for the PC/Server, probably not so much of a problem with local users but more of an issue with roaming profiles and locked down terminal server users. With a bit of monitoring with processmon i found that it is HKCU (which the user would have permissions to) - I know this because they could make the association manually. The actual key is "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\<.extension>\progid" <.extension> will be the .doc/.xls/.ppt/.rtf etc; progid will be the internal name of the application that is set to open that file type. I found what they were by using the commands assoc and ftype. For example setting ..docs progid to openoffice.org.doc will make a word document open with open office writer - it will also change the icon. I made a simple VBS script that used regwrite to create the progid key (it will create it if doesn't exist and overwrite if does) Thanks Matt "mr_unreliable" <kindlyReplyToNewsgroup@newsgroup> wrote in message news:uV2F0LXMKHA.5192@newsgroup Quote: > mayayana wrote: Quote: >> HKCR\txtfile\shell\open\command\ >> default value: "C:\windows\notepad.exe %1" >> > Whenever I am setting up a registry entry to send > a file to some utility (for example a txt file to > an editor), I like to wrap the parameter in quotes: > > D:\TextEditors\EditPlus\Editplus.exe "%1" > > In case the filepath contains blanks, wrapping > it in quotes will get the entire path sent to > the utility, instead of just the path -- up to > the first blank. > > cheers, jw |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Default File Type Associations - Restore | Tutorials | |||
| Program associations and file type extension | Vista mail | |||
| Can't Change File Type Associations | Vista General | |||
| Need help setting File Type Associations in Vista | Vista General | |||
| Restoring file type and protocol associations | Vista General | |||