CONST SFAF_HKEY_CLASSES_ROOT = &H80000000
FUNCTION SetFileAssociation (sFileExtension AS STRING, sCommand AS STRING) AS LONG
DEFSTR sDescriptor, sFileExt
DIM regFA AS QREGISTRY
WITH regFA
.RootKey = SFAF_HKEY_CLASSES_ROOT
IF sFileExtension = "" THEN
Result = 0
EXIT FUNCTION
END IF
IF LEFT$(sFileExtension, 1) <> "." THEN
sFileExt = "." & sFileExtension
ELSE
sFileExt = sFileEXtension
END IF
IF LEN(sFileExt) > 5 THEN
Result = 0
EXIT FUNCTION
END IF
sDescriptor = (sFileExt - ".") & "_File"
IF .KeyExists (sDescriptor) THEN
.DeleteKey (sDescriptor)
DOEVENTS
END IF
.OpenKey (sFileExt, 1)
.WriteString ("", sDescriptor)
.CloseKey
.OpenKey(sDescriptor & "\\Shell\\Open\\Command", 1)
.WriteString ("", sCommand)
.CloseKey
END WITH
Result = 1
END FUNCTION
|