实现对注册表的修改
如有需要将软体资讯写入 REGISTRY 请依 REGISTRY 使用规则写入
HKEY_LOCAL_MACHINE,SOFTWARE 中(例版本序号,安装资讯....)
//WIN32API宣告
//开启机码
DECLARE INTEGER RegOpenKey IN Win32API INTEGER nHKey,;
STRING cSubKey, INTEGER @nHandle
//建立机码
DECLARE Integer RegCreateKey IN Win32API INTEGER nHKey,;
STRING cSubKey, INTEGER @nHandle
//关闭开启的机码
DECLARE Integer RegCloseKey IN Win32API INTEGER nHKey
//删除机码
DECLARE INTEGER RegDeleteKey IN Win32API INTEGER nHKEY,;
STRING cSubkey
//删除某一机码下的值
DECLARE INTEGER RegDeletevalue IN Win32API INTEGER nHKEY,;
STRING cEntry
#DEFINE HKEY_CLASSES_ROOT -2147483648
#DEFINE HKEY_CURRENT_USER -2147483647
#DEFINE HKEY_LOCAL_MACHINE -2147483646
#DEFINE HKEY_USERS -2147483645
#DEFINE ERROR_SUCCESS 0
**************************************************
*** 删除机码 DeleteRegistryKey
*** 注意:删除机码将导致机码下的值全数被删除
*** 传回值:.T.表成功,.NULL.表无此机码
**************************************************
LPARAMETERS HKEY,SubKey
LOCAL nResult, nHandle
nHandle=0
nResult=RegOpenKey(HKey,SubKey,@nHandle)
IF nResult#ERROR_SUCCESS
//机码不存在或无法开启
RETURN .NULL.
ENDIF
nResult=RegDeleteKey(HKey,SubKey)
=RegCloseKey(nHandle)
IF nResult#ERROR_SUCCESS
RETURN .NULL.
ENDIF
RETURN .T.
**************************************************
*** 读取字串值 ReadRegistryString
*** 传回值:字串或.NULL.表无此机码
**************************************************
LPARAMETERS HKey, Subkey, Entry
LOCAL nHandle, nResult, nSize, cDataBuffer, nType
nHandle=0
//开启机码
nResult=RegOpenKey(HKey,SubKey,@nHandle)
IF nResult#ERROR_SUCCESS
RETURN .NULL.
ENDIF
// 使用RegQueryvalueEx决定资料型态
DECLARE INTEGER RegQueryvalueEx IN Win32API INTEGER nHKey,;
STRING lpszvalueName,INTEGER dwReserved,;
INTEGER @lpdwType, STRING @lpbData, INTEGER @lpcbData
//将值传回 buffer
cDataBuffer=space(256)
nSize=LEN(cDataBuffer)
nType=0
nResult= RegQueryvalueEx(nHandle,Entry,0,@nType,@cDataBuffer,@nSize)
=RegCloseKey(nHandle)
IF nResult#ERROR_SUCCESS
RETURN .NULL.
ENDIF
IF nSize <2 RETURN ""
//空字串
ENDIF
//去除空白字元及字串後的 NULL
RETURN SUBSTR(CHRTRAN(cDataBuffer,CHR(0),""),1,nSize-1)
************************************************** ***
写入字串值 WriteRegistryString *** 传回值:.T.成功,.NULL.失败
**************************************************
LPARAMETERS HKey, Subkey, Entry, value
LOCAL nHandle, nResult, nSize, cDataBuffer, nType nHandle="0" nResult="RegOpenKey(HKey,SubKey,@nHandle)"
IF nResult#ERROR_SUCCESS RETURN .NULL.
ENDIF
DECLARE INTEGER RegSetvalueEx IN Win32API INTEGER nHKey,; STRING lpszEntry,INTEGER dwReserved,; INTEGER fdwType, STRING lpbData, INTEGER cbData nSize="LEN(cvalue)" nResult="
RegSetvalueEx(nHandle,Entry,0,0," value,nSize)="RegCloseKey(nHandle)"
IF nResult#nERROR_SUCCESS RETURN .NULL.
ENDIF
RETURN .T.
**************************************************
使用方式: CurrentVersion="1.0"