OEM-Informationen ändern
Verfasst: 24.03.2010 18:27
Windows 7 and Windows Vista:
Download: http://upload.alexander-n.de/=MzQuMTI2OTM2NjA2OA==
Code:
Download: http://upload.alexander-n.de/=MzQuMTI2OTM2NjA2OA==
Code:
Code: Alles auswählen
; gPreferences[460-5-1-1-1050-170-0-432-281]
; a14xerus
; http://alexander-n.de/
; 23.03.2010
EnableExplicit
UsePNGImageDecoder()
UseJPEGImageDecoder()
;registry.pbi (jaPBe)
Procedure.i Reg_SetValue(topKey.i, sKeyName.s, sValueName.s, vValue.s, lType.i, ComputerName.s = "")
Protected lpData.s=Space(255)
Protected *GetHandle, hKey.i, lReturnCode.i, lhRemoteRegistry.i, lpcbData, lValue.i, ergebnis.i
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
*GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
*GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If *GetHandle = #ERROR_SUCCESS
lpcbData = 255
Select lType
Case #REG_SZ
*GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_SZ, @vValue, Len(vValue) + 1)
Case #REG_DWORD
lValue = Val(vValue)
*GetHandle = RegSetValueEx_(hKey, sValueName, 0, #REG_DWORD, @lValue, 4)
EndSelect
RegCloseKey_(hKey)
ergebnis = 1
ProcedureReturn ergebnis
Else
RegCloseKey_(hKey)
ergebnis = 0
ProcedureReturn ergebnis
EndIf
EndProcedure
Procedure.s Reg_GetValue(topKey.i, sKeyName.s, sValueName.s, ComputerName.s = "")
Protected lpData.s=Space(255), GetValue.s
Protected *GetHandle, hKey.i, lReturnCode.i, lhRemoteRegistry.i, lpcbData.i, lType.i, lpType.i
Protected lpDataDWORD.i
If Left(sKeyName, 1) = "\"
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
If ComputerName = ""
*GetHandle = RegOpenKeyEx_(topKey, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
Else
lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
*GetHandle = RegOpenKeyEx_(lhRemoteRegistry, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
EndIf
If *GetHandle = #ERROR_SUCCESS
lpcbData = 255
*GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)
If *GetHandle = #ERROR_SUCCESS
Select lType
Case #REG_SZ
*GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lType, @lpData, @lpcbData)
If *GetHandle = 0
GetValue = Left(lpData, lpcbData - 1)
Else
GetValue = ""
EndIf
Case #REG_DWORD
*GetHandle = RegQueryValueEx_(hKey, sValueName, 0, @lpType, @lpDataDWORD, @lpcbData)
If *GetHandle = 0
GetValue = Str(lpDataDWORD)
Else
GetValue = "0"
EndIf
EndSelect
EndIf
EndIf
RegCloseKey_(hKey)
ProcedureReturn GetValue
EndProcedure
Procedure.i WriteOEM(Manufacturer.s, Model.s="", SupportURL.s="", SupportHours.s="", SupportPhone.s="", Logo.s="")
Protected Ret.i = #True
Ret * Reg_SetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Manufacturer", Manufacturer, #REG_SZ)
Ret * Reg_SetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Model", Model, #REG_SZ)
Ret * Reg_SetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "SupportHours", SupportHours, #REG_SZ)
Ret * Reg_SetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "SupportPhone", SupportPhone, #REG_SZ)
Ret * Reg_SetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "SupportURL", SupportURL, #REG_SZ)
Ret * Reg_SetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Logo",Logo, #REG_SZ)
ProcedureReturn Ret
EndProcedure
Global Window.l, image.l
Enumeration
#G_Manu
#G_Model
#G_SupportHours
#G_SupportPhone
#G_SupportURL
#G_Logo
#G_LogoBrowse
#G_Image
#G_Save
EndEnumeration
Procedure.d Min(Value1.d,Value2.d); Return the lower value
If Value1>Value2
ProcedureReturn Value2
Else
ProcedureReturn Value1
EndIf
EndProcedure
Procedure.s GetSpecialFolderPath(CSIDL.l)
Protected LibraryID
Protected Path.s = Space(#MAX_PATH)
LibraryID = OpenLibrary(#PB_Any, "shell32.dll")
If LibraryID
CallFunction(LibraryID, "SHGetSpecialFolderPathA", 0, @Path, CSIDL, 0)
CloseLibrary(LibraryID)
EndIf
ProcedureReturn Path
EndProcedure
Procedure OpenWindows()
Window = OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, 416, 204, "OEM-Branding for Windows 7 and Vista", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
If Window
;If CreateGadgetList(WindowID(Window))
Frame3DGadget(-1, 5, 5, 270, 165, "OEM-Informations")
TextGadget(-1, 15, 20, 100, 20, "Manufacturer")
StringGadget(#G_Manu, 115, 20, 150, 20, "")
TextGadget(-1, 15, 40, 100, 20, "Model")
StringGadget(#G_Model, 115, 40, 150, 20, "")
TextGadget(-1, 15, 60, 100, 20, "SupportURL")
StringGadget(#G_SupportURL, 115, 60, 150, 20, "")
TextGadget(-1, 15, 80, 100, 20, "SupportHours")
StringGadget(#G_SupportHours, 115, 80, 150, 20, "")
TextGadget(-1, 15, 100, 100, 20, "SupportPhone")
StringGadget(#G_SupportPhone, 115, 100, 150, 20, "")
TextGadget(-1, 15, 120, 100, 20, "Logo")
StringGadget(#G_Logo, 115, 120, 150, 20, "")
ButtonGadget(#G_LogoBrowse, 115, 140, 150, 20, "Browse")
Frame3DGadget(-1, 280, 5, 130, 165, "Logo")
ImageGadget(#G_Image, 285, 20, 120, 120, 0)
ButtonGadget(#G_Save, 330, 175, 80, 25, "Save")
ProcedureReturn #True
;EndIf
EndIf
ProcedureReturn #False
EndProcedure
Procedure LoadOEM(*dummy)
SetGadgetText(#G_Manu,Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Manufacturer"))
SetGadgetText(#G_Model,Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Model"))
SetGadgetText(#G_SupportHours,Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "SupportHours"))
SetGadgetText(#G_SupportPhone,Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "SupportPhone"))
SetGadgetText(#G_SupportURL,Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "SupportURL"))
Protected Logo.s
Logo = Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Logo")
SetGadgetText(#G_Logo,Logo)
If Logo
image = LoadImage(-1,Logo,#PB_Image_DisplayFormat)
SetGadgetState(#G_Image,ImageID(image))
EndIf
EndProcedure
Procedure browse(*Logo)
Protected factor.d, Logo.s = PeekS(*Logo)
Logo = OpenFileRequester("Choose OEM-Logo",Logo,"Supported images|*.jpg;*.jpeg;*.png;*.bmp",0)
If Logo
If image
If IsImage(image)
FreeImage(image)
image = 0
EndIf
EndIf
image = LoadImage(-1,Logo,#PB_Image_DisplayFormat)
If image
If ImageHeight(image) > 120 Or ImageWidth(image) > 120
factor = Min(120/ImageWidth(image), 120/ImageHeight(image))
ResizeImage(image,Round(factor * ImageWidth(image),0),Round(factor * ImageHeight(image),0))
EndIf
SetGadgetState(#G_Image,ImageID(image))
SetGadgetText(#G_Logo,Logo)
Else
MessageRequester("Error","Unable to load image "+Logo,#MB_ICONERROR)
SetGadgetText(#G_Logo,"")
EndIf
Else
Debug "no image selected"
EndIf
EndProcedure
Procedure save(*dummy)
Protected Logo.s = "", ok.i = #False
If image And GetGadgetText(#G_Logo)
If IsImage(image)
Logo = GetSpecialFolderPath(#CSIDL_WINDOWS)+"\oem-logo.bmp"
If Not SaveImage(image,Logo,#PB_ImagePlugin_BMP)
Logo = ""
EndIf
EndIf
EndIf
SetGadgetText(#G_Logo,Logo)
ok = #False
If WriteOEM(GetGadgetText(#G_Manu),GetGadgetText(#G_Model),GetGadgetText(#G_SupportURL),GetGadgetText(#G_SupportHours),GetGadgetText(#G_SupportPhone),GetGadgetText(#G_Logo))
; test manu-entry for validation (not safe, but more than nothing :D )
If GetGadgetText(#G_Manu) = Reg_GetValue(#HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\Windows\CurrentVersion\OEMInformation", "Manufacturer")
ok = #True
EndIf
EndIf
If ok
MessageRequester("Success","OEM-Information saved!",#MB_ICONINFORMATION)
Else
MessageRequester("Error","OEM-Information not saved!"+Chr(10)+"Program started as Administrator?",#MB_ICONERROR)
EndIf
EndProcedure
Procedure main_loop()
Protected event.i, g_event.i, tmp.s
Repeat
event = WindowEvent()
Select event
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
g_event = EventGadget()
Select g_event
Case #G_LogoBrowse
tmp = GetGadgetText(#G_Logo)
CreateThread(@browse(),@tmp)
Case #G_Save
CreateThread(@save(),0)
EndSelect
EndSelect
Delay(10)
ForEver
EndProcedure
Procedure init_Program()
If Not OpenWindows()
End
EndIf
CreateThread(@LoadOEM(),0)
main_loop()
EndProcedure
init_Program()