Change file Associations with scripting Print E-mail
Written by Hans Straat, Tuesday, 03 October 2006

Sometimes you get the chalange that you have to change file associations for all users in your windows environment. This can be either a local workstation, on a plain terminal server or a citrixfarm wide change.

Most of the system engineers now the programs accoc or ftype. Type these commands in your command prompt with the /? parameter and you get all options. But heck, what if you need to do this for about 1000 users in there own user registryhyve?

Since I know sh*t of programming I looked realy Innocent to a colega of mine Marc Klaver who can actually program (he often trys to learn it me but hey...some things you really can't learn).

Marc wrote a script that let's you change file associations for all users or simply a single user if used in other logon scripts.

 

The vbs script marc wrote uses a few parameters.

First comes the scriptname.vbs [used filetype] [used extension] [ full path to executable]

This would look like the example

Example: 

SetFileAssociations.vbs phpfile .php "c:\program files\php\php.exe"

We provide you with a scripting solution that is made for my citrixfarm but heck why not give it to everybody that strugles with changing filetypes.

The script

Copy paste this in your notepad or what editor you use and preferly save it as SetFileAssociates.vbs if you have comments on the script register on this site and write your comments. We use version control on scripts so if this script is updated a new script will be posted according to the version.

'-------------------------------------------------------------------------------
' File name: SetFileAssociations.vbs
' System   : Windows 2003
' Use      : Set a file association for the currently logged in user.
'
' CVS      : $Revision: 1.1 $
'            $Date: 2006/02/24 12:08:05 $
'
' Note(s)  : 1) No check is made on valid arguments given!
'
'               Expected is:
'               SetFileAssociations <type> <extension> <path>
'
'                   <type>      - Type of file to associate with the program.
'                                 This name can be anything, or a defined type
'                                 (see ftype.exe for currently defined types).
'
'                   <extension> - The extension used to associate with the
'                                 above type.
'
'                   <path>      - Full path (including file extension) to the
'                                 executable to open files of type <type>.
'
'            2) If spaces are required, enclose the argument with quotes ("")!
'
'            3) The settings are written in the HKCU hive, which will take
'               precedence over the system settings!
'
'            4) There is no script for removing these settings!
'
'            5) No error handling is provided!
'-------------------------------------------------------------------------------
option explicit
on error resume next

 

'-----------------------------------------------------------------------
' Key where to write the settings.
'-----------------------------------------------------------------------
const STR_KEY = "HKEY_CURRENT_USER\Software\Classes\"

 

dim objArgs
dim shObj
dim strFileType
dim strFileExtension
dim strFilePath

 

'-----------------------------------------------------------------------
' Quit if invalid number of arguments is found.
'-----------------------------------------------------------------------
set objArgs = wscript.arguments
if objArgs.count <> 3 then
    wscript.quit
end if

 

'-----------------------------------------------------------------------
' Read arguments and make the settings.
'-----------------------------------------------------------------------
strFileType      = objArgs(0)
strFileExtension = objArgs(1)
strFilePath      = objArgs(2)
set shObj        = CreateObject("WScript.Shell")

shObj.RegWrite STR_KEY & strFileType & "\Shell\Open\Command\", """" & strFilePath & """", "REG_SZ"
shObj.RegWrite STR_KEY & strFileExtension & "\" , strFileType, "REG_SZ"

'end script

 Note: Have fun with this script, usage is free of charge

Comments
Add NewSearchRSS
Write comment
Name:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 

Powered by JoomlaCommentCopyright (C) 2006 Frantisek Hliva. All rights reserved.Homepage: http://cavo.co.nr/

 
< Prev   Next >