Code: Select all
;Registry stuff found on the forum
#SHCNE_ASSOCCHANGED = $08000000
#SHCNF_IDLIST = $0
Procedure RegConvertRegKeyToTopKey(Key.s)
topKey.s=StringField(Key,1,"\")
topKey=UCase(topKey)
Select topKey
Case "HKEY_CLASSES_ROOT"
retour=#HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_USER"
retour=#HKEY_CURRENT_USER
Case "HKEY_LOCAL_MACHINE"
retour=#HKEY_LOCAL_MACHINE
Case "HKEY_USERS"
retour=#HKEY_USERS
Case "HKEY_CURRENT_CONFIG"
retour=#HKEY_CURRENT_CONFIG
EndSelect
ProcedureReturn retour
EndProcedure
Procedure.s RegConvertRegKeyToKeyName(Key.s)
PositionSlash=FindString(Key,"\",1)
retour.s=Right(Key,(Len(Key)-PositionSlash))
ProcedureReturn retour
EndProcedure
Procedure.s RegListSubKey(Key.s, Index, ComputerName.s)
topKey=RegConvertRegKeyToTopKey(Key)
KeyName.s=RegConvertRegKeyToKeyName(Key)
lpName.s
lpftLastWriteTime.FILETIME
If Left(KeyName, 1) = "\"
KeyName = Right(KeyName, Len(KeyName) - 1)
EndIf
If ComputerName = "."
GetHandle = RegOpenKeyEx_(topKey, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbName = 255
lpName = Space(255)
GetHandle = RegEnumKeyEx_(hKey, Index, @lpName, @lpcbName, 0, 0, 0, @lpftLastWriteTime)
If GetHandle = #ERROR_SUCCESS
ListSubKey.s = Left(lpName, lpcbName)
Else
ListSubKey.s = ""
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn ListSubKey
EndProcedure
Procedure.l RegDeleteKey(Key.s, ComputerName.s)
topKey=RegConvertRegKeyToTopKey(Key)
KeyName.s=RegConvertRegKeyToKeyName(Key)
If Left(KeyName, 1) = "\"
KeyName = Right(KeyName, Len(KeyName) - 1)
EndIf
If ComputerName = "."
GetHandle = RegDeleteKey_(topKey, @KeyName)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegDeleteKey_(lhRemoteRegistry, @KeyName)
EndIf
If GetHandle = #ERROR_SUCCESS
DeleteKey = #True
Else
DeleteKey = #False
EndIf
ProcedureReturn DeleteKey
EndProcedure
Procedure.l RegDeleteKeyWithAllSubInternal(Key.s,ComputerName.s)
topKey=RegConvertRegKeyToTopKey(Key)
KeyName.s=RegConvertRegKeyToKeyName(Key)
i=0
a$=""
Repeat
b$=a$
a$=RegListSubKey(Key,0,"")
If a$<>""
RegDeleteKeyWithAllSubInternal(Key+"\"+a$,"")
EndIf
Until a$=b$
RegDeleteKey(Key, ComputerName)
EndProcedure
Procedure.l RegKeyExists(Key.s, ComputerName.s)
topKey=RegConvertRegKeyToTopKey(Key)
KeyName.s=RegConvertRegKeyToKeyName(Key)
If Left(KeyName, 1) = "\"
KeyName = Right(KeyName, Len(KeyName) - 1)
EndIf
If ComputerName = "."
GetHandle = RegOpenKeyEx_(topKey, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
GetHandle = RegOpenKeyEx_(lhRemoteRegistry, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If GetHandle = #ERROR_SUCCESS
KeyExists = #True
Else
KeyExists = #False
EndIf
ProcedureReturn KeyExists
EndProcedure
Procedure.l RegDeleteKeyWithAllSub(Key.s,ComputerName.s)
retour1 = RegKeyExists(Key.s,ComputerName.s)
retour2+ RegDeleteKeyWithAllSubInternal(Key,ComputerName)
If retour1=1 And retour2=0 : retour=1 : EndIf
ProcedureReturn retour
EndProcedure
Procedure.l SetKey(fold,Key$,Subkey$,Type,Adr,len)
If RegCreateKeyEx_(fold, Key$, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
RegSetValueEx_(NewKey, Subkey$, 0, Type, Adr, len)
RegCloseKey_(NewKey)
EndIf
EndProcedure
;Assoc stuff
Procedure.l AssociateFileEx(ext$,ext_description$,programm$,Icon$,prgkey$,cmd_description$,cmd_key$)
cmd$=Chr(34)+programm$+Chr(34)+" "+Chr(34)+"%1"+Chr(34)
If GetVersion_() & $ff0000 ; Windows NT/XP
SetKey(#HKEY_CLASSES_ROOT, "Applications\"+prgkey$+"\shell\"+cmd_description$+"\command","",#REG_SZ,@cmd$,Len(cmd$)+1)
If ext_description$
Key$=ext$+"_auto_file"
SetKey(#HKEY_CLASSES_ROOT,"."+ext$,"",#REG_SZ,@Key$,Len(Key$)+1)
SetKey(#HKEY_CLASSES_ROOT,Key$,"",#REG_SZ,@ext_description$,Len(ext_description$)+1)
If Icon$
SetKey(#HKEY_CLASSES_ROOT,Key$+"\DefaultIcon","",#REG_SZ,@Icon$,Len(Icon$)+1)
EndIf
EndIf
SetKey(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"Application",#REG_SZ,@prgkey$,Len(prgkey$)+1)
Else ;Windows 9x
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\."+ext$,"",#REG_SZ,@prgkey$,Len(prgkey$)+1)
If ext_description$
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$,"",#REG_SZ,@ext_description$,Len(ext_description$)+1)
EndIf
If Icon$
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\DefaultIcon","",#REG_SZ,@Icon$,Len(Icon$)+1)
EndIf
If cmd_description$<>cmd_key$
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$,"",#REG_SZ,@cmd_description$,Len(cmd_description$)+1)
EndIf
SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$+"\command","",#REG_SZ,@cmd$,Len(cmd$)+1)
EndIf
EndProcedure
Procedure.l AssociateFile(ext$,ext_description$,programm$,Icon$)
AssociateFileEx(ext$,ext_description$,programm$,Icon$,GetFilePart(programm$),"open","open")
EndProcedure
Procedure.l RemoveAssociateFile(ext$,prgkey$)
If ext$ <> "" And prgkey$ <> ""
If GetVersion_() & $ff0000 ; Windows NT/XP
RegDeleteKeyWithAllSub("HKEY_CLASSES_ROOT\Applications\"+prgkey$,"")
Key$=ext$+"_auto_file"
RegDeleteKeyWithAllSub("HKEY_CLASSES_ROOT\."+ext$,"")
RegDeleteKeyWithAllSub("HKEY_CLASSES_ROOT\"+Key$,"")
RegDeleteKeyWithAllSub("HKEY_CURRENT_USER\"+"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"")
Else ;Windows 9x
RegDeleteKeyWithAllSub("HKEY_LOCAL_MACHINE\"+"Software\Classes\."+ext$,"")
RegDeleteKeyWithAllSub("HKEY_LOCAL_MACHINE\"+"Software\Classes\"+prgkey$,"")
EndIf
EndIf
EndProcedure
Procedure.l AssociationsRefresh()
ProcedureReturn SHChangeNotify_(#SHCNE_ASSOCCHANGED, #SHCNF_IDLIST, 0, 0)
EndProcedure
;little Example
;AssociateFile("pb","Pure Basic Source","C:\Programme\PureBasic\PureBasic.exe","F:\icon.bmp,0")
;and now an addition context-item
;AssociateFileEx("pb","","F:\alternate rich\jaPBe.exe","","PureBasic.exe","Open with jaPBe","open_with_japbe")