#184891 - 2008-01-28 11:02 PM
RFC: Associate2() - Create file association per user.
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Inspired by Glenn's Associate() UDF and by the MS article referenced in the comments I altered the Associate UDF a bit (hope you don't mind Glenn ) to create file associations on a per user basis. It sets the association in hkcu\software\classes so it can be used in a logon script. A per user file association will override a per machine file association.
I would like to hear suggestion/comments/whatever from you guys before posting it in the UDF forum.
;FUNCTION Associate2()
;
;ACTION:
; Associates a per user file extension with a particular action.
; A per use file association overrides the one set per system.
;
;AUTHOR:
; Mart
; Based on the Associate UDF by Glenn Barnas.
; Inspired by: http://support.microsoft.com/kb/257592
;
;SYNTAX:
; Associate2(extension, type, description, open, edit, icon)
;
;PARAMETERS:
; Extension (required)
; File extension to associate.
;
; Type (required)
; Short FileType description.
;
; Description (required)
; Description of File Type.
;
; Open Command (required)
; Command to Open (Execute) the associated file.
;
; Edit Command (optional)
; Command to EDIT the associated file.
;
; Icon (optional)
; Default icon for the specific filetype.
; Can either be a .ico file or something like shell32.dll,3 (third icon in shell32.dll).
; If none is given the default icon for unknown file types is used by windows.
;
;Remarks:
; Should work with Windows 2000 and up.
; Developed and tested on Windows XP SP2 and Kix4.60.
;
;RETURNS:
; System error codes.
;
;DEPENDENCIES:
; None
;
;EXAMPLES:
; ;Define a new association to open (execute) and edit .kix files and set an icon.
; Associate2(".kix", "KixScript", "Kixtart Script", "Kix32.exe", "notepad.exe", "c:\someicon.ico")
;
Function Associate2($extension, $type, $description, $opencmd, optional $editcmd, $icon)
Dim $rc
;Make sure the dot is specified.
If Left($extension, 1) <> "."
$extension = "." + $extension
EndIf
;Exit if a required parameter is empty.
Select
Case $extension = ""
Exit 87
Case $type = ""
Exit 87
Case $description = ""
Exit 87
Case $opencmd = ""
Exit 87
EndSelect
;Set file type and description.
$rc = WriteValue("HKCU\SOFTWARE\Classes\" + $extension, "", $type, "REG_SZ")
$rc = WriteValue("HKCU\SOFTWARE\Classes\" + $extension + "\" + $type, "", $description, "REG_SZ")
;Create the values for the open command.
$rc = WriteValue("HKCU\SOFTWARE\Classes\" + $extension + "\Shell\Open\Command", "", $opencmd, "REG_EXPAND_SZ")
;Create the definitions for the edit command.
If $editcmd <> ""
$rc = WriteValue("HKCU\SOFTWARE\Classes\" + $extension + "\Shell\Edit\Command", "", $editcmd, "REG_EXPAND_SZ")
EndIf
;Set icon.
If $icon <> ""
$rc = WriteValue("HKCU\SOFTWARE\Classes\" + $extension + "\DefaultIcon", "", $icon, "REG_SZ")
EndIf
If @ERROR = 0
$Asssociate2 = 0
Else
$Asssociate2 = @ERROR
EndIf
EndFunction
Edited by Mart (2008-01-28 11:04 PM) Edit Reason: Typo: His name is Glenn and not Gelnn.
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#184947 - 2008-01-30 10:26 AM
Re: RFC: Associate2() - Create file association per user.
[Re: Mart]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Ok. Tried all the examples below and they all work as expected. Deleting the association by specifying a null value fort the open command should be explained in the comments imho. Sure it can be found in the code but a small explanation in the comments would be nice.
This is much better then having an Associate2 UDF 
;Create per user association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,"system01","icon.ico",1)
;Delete per user association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,"system01",,)
;Create per system association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,"system01","icon.ico",)
;Delete per system association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,"system01",,)
;Create per user association on local system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,,"icon.ico",1)
;Delete per user association on local system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,,,)
;Create per system association on local system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,,"icon.ico",)
;Delete per system association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,,,)
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
#184971 - 2008-01-31 11:09 AM
Re: RFC: Associate2() - Create file association per user.
[Re: Glenn Barnas]
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
There was an error in two of the examples. New examples posted below.
;Create per user association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,"system01","icon.ico",1)
;Delete per user association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,"system01",,1)
;Create per system association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,"system01","icon.ico",)
;Delete per system association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,"system01",,)
;Create per user association on local system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,,"icon.ico",1)
;Delete per user association on local system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,,,1)
;Create per system association on local system.
Associate(".kix","Kix Script", "KiXtart script file", "kix32.exe", "notepad.exe",,,"icon.ico",)
;Delete per system association on remote system.
Associate(".kix","Kix Script", "KiXtart script file", "", "",,,,)
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2366 anonymous users online.
|
|
|