Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with registry keys
Message
De
29/12/1998 13:21:22
 
 
À
29/12/1998 12:16:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00171241
Message ID:
00171275
Vues:
30
>Hey everyone,
>I'm trying to add some values to a registry key and I have no problem with the string values but I need some help with hexadecimal values. How do I write a hexadecimal value to the registry? What about a binary?
>

You'll need to use the API calls directly to do these. The following is code that I've used in the past; it assumes that you've already opened the registry key with RegOpenKey() or RegCreateKey(), and that you'll close the key when you're done. Pardon the macro expansion:



LPARAMETERS thKey, tcValueName, tcValueData, tcValueType
*
* Set specified value on current registry key
*
LOCAL nResult,nLen,cOutBuff
LOCAL x,b,i,b0,b1,b2,b3,t
nResult = 0
#INCLUDE REGISTRY.H
DECLARE INTEGER RegSetValueEx IN Win32API ;
INTEGER nKeyHandle, ;
STRING cValueName, ;
INTEGER nReserved, ;
INTEGER nType, ;
STRING cBuffer, ;
INTEGER nBufferSize
*
* If no Registry Key is open, we fail. Pass the registry key in as first parm
*
IF TYPE('thKey') # 'N' OR thKey = 0
RETURN .F.
ENDIF
*
* Build a buffer to hold the output value based on the type specified in tcValueType
*
DO CASE
CASE tcValueType = 'STRING'
nLen = LEN(tcValueData)
cOutBuff = tcValueData + CHR(0)
nType = REG_SZ

CASE tcValueType = 'BIN'
nLen = LEN(tcValueData)
cOutBuff = tcValueData
nType = REG_BINARY

CASE tcValueType = 'MULTIZ'
nLen = LEN(tcValueData)
cOutBuff = tcValueData+CHR(0)
nType = REG_MULTI_SZ

CASE tcValueType = 'DWORD'
nLen = 4
x=int(tcValueData)
FOR i=3 to 0 step -1
t=CHR(48+i)
b=INT(x/(256^i))
b&t=b
x=x-b*(256^i)
ENDFOR
cOutBuff = CHR(b0)+CHR(b1)+CHR(b2)+CHR(b3)
nType = REG_DWORD
OTHERWISE
nType = 0
ENDCASE

nResult = RegSetValueEx(thkey, ;
tcValueName, ;
REG_OPTION_RESERVED, ;
nType, ;
cOutBuff, ;
nLen )


RETURN (nResult=0)
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform