Code : Tout sélectionner
Procedure RegConvertRegKeyToTopKeyAndKeyName(Key.s)
Shared topKey,KeyName.s
temp.s=StringField(Key,1,"\")
temp=UCase(temp)
Select temp
Case "HKEY_CLASSES_ROOT"
topKey=#HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_USER"
topKey=#HKEY_CURRENT_USER
Case "HKEY_LOCAL_MACHINE"
topKey=#HKEY_LOCAL_MACHINE
Case "HKEY_USERS"
topKey=#HKEY_USERS
Case "HKEY_CURRENT_CONFIG"
topKey=#HKEY_CURRENT_CONFIG
EndSelect
PositionSlash=FindString(Key,"\",1)
KeyName.s=Right(Key,(Len(Key)-PositionSlash))
EndProcedure
ProcedureDLL RegSetValue(Key.s, ValueName.s, Value.s, Type, ComputerName.s) ; Sets a Value
;// Type can be #REG_SZ / #REG_DWORD / #REG_BINARY / #REG_EXPAND_SZ
;// For REG_BINARY type use Hexa value as String
;// Returns 1 if successful or 0 if it fails
Shared RegWow64.l,RegEx,topKey,KeyName.s
RegConvertRegKeyToTopKeyAndKeyName(Key)
If ComputerName = "."
If RegEx
GetHandle = RegOpenKeyEx_(topKey,KeyName,0,#KEY_ALL_ACCESS|RegWow64,@hKey)
Else
GetHandle = RegOpenKey_(topKey,KeyName,@hKey)
EndIf
Else
lReturnCode = RegConnectRegistry_(ComputerName,topKey,@lhRemoteRegistry)
If RegEx
GetHandle = RegOpenKeyEx_(lhRemoteRegistry,KeyName,0,#KEY_ALL_ACCESS|RegWow64,@hKey)
Else
GetHandle = RegOpenKey_(lhRemoteRegistry,KeyName,@hKey)
EndIf
EndIf
If GetHandle = #ERROR_SUCCESS
lpcbData = 255
lpData.s = Space(255)
Select Type
Case #REG_EXPAND_SZ
GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_EXPAND_SZ, @Value, Len(Value) + 1)
Case #REG_SZ
GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_SZ, @Value, Len(Value) + 1)
Case #REG_DWORD
lValue = Val(Value)
GetHandle = RegSetValueEx_(hKey, ValueName, 0, #REG_DWORD, @lValue, 4)
Case #REG_BINARY
LenBuffer=Len(Value)/2
*RegBuffer=AllocateMemory(LenBuffer)
For n=0 To LenBuffer-1
OctetHexa.s=Mid(Value,(n*2)+1,2)
Octet=Val("$"+OctetHexa)
PokeB(*RegBuffer+n,Octet)
Next
GetHandle= RegSetValueEx_(hKey,ValueName,0,#REG_BINARY,*RegBuffer,LenBuffer)
FreeMemory(*RegBuffer)
EndSelect
RegCloseKey_(hKey)
ergebnis = 1
ProcedureReturn ergebnis
Else
RegCloseKey_(hKey)
ergebnis = 0
ProcedureReturn ergebnis
EndIf
EndProcedure
;RegSetValue(Key.s, ValueName.s, Value.s, Type, ComputerName.s)
;HKEY_CURRENT_USER\Software\Microsoft\ Windows\CurrentVersion\Policies\ Explorer NoDesktop
;Ouvrez \Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
ProcedureDLL RegCreateKey(Key.s, ComputerName.s) ; Creates a Key
;// It create subkey if KeyPath don't exist
;// Returns 1 if successful or 0 if it fails
Shared RegWow64.l,RegEx,topKey,KeyName.s
RegConvertRegKeyToTopKeyAndKeyName(Key)
lpSecurityAttributes.SECURITY_ATTRIBUTEs
If ComputerName = "."
If RegEx
GetHandle = RegCreateKeyEx_(topKey,KeyName,0,0,#REG_OPTION_NON_VOLATILE,#KEY_ALL_ACCESS|RegWow64,@lpSecurityAttributes,@hNewKey,@GetHandle)
Else
GetHandle = RegCreateKey_(topKey,KeyName,@hNewKey)
EndIf
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
If RegEx
GetHandle = RegCreateKeyEx_(lhRemoteRegistry,KeyName,0,0,#REG_OPTION_NON_VOLATILE,#KEY_ALL_ACCESS|RegWow64,@lpSecurityAttributes,@hNewKey,@GetHandle)
Else
GetHandle = RegCreateKey_(lhRemoteRegistry,KeyName,@hNewKey)
EndIf
EndIf
If GetHandle = #ERROR_SUCCESS
GetHandle = RegCloseKey_(hNewKey)
CreateKey = #True
Else
CreateKey = #False
EndIf
ProcedureReturn CreateKey
EndProcedure
ProcedureDLL RegCreateKeyValue(Key.s,ValueName.s,Value.s,Type,ComputerName.s) ; Creates a Key and a Value in a Single Command
;// Type can be #REG_SZ or #REG_DWORD
;// Returns 1 if successful or 0 if it fails
RegCreateKey(Key,ComputerName)
ProcedureReturn RegSetValue(Key,ValueName,Value,Type,ComputerName)
EndProcedure
Debug RegSetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\","NoDesktop","1",#REG_DWORD,".")
RunProgram("calc.exe","","",#PB_Program_Wait)
Debug RegSetValue("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\","NoDesktop","0",#REG_DWORD,".")