如何调用win注册表

lpc444 2003-03-02 12:51:43
各位老师:请教了。
如何操作win的注册表?请给出主要的命令或函数,最好能举一两个例子。(用VFP)
...全文
48 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lpc444 2003-03-04
  • 打赏
  • 举报
回复
多谢,最好是能给出具体写入和读出注册表键值的代码。分数由你定!
rida 2003-03-03
  • 打赏
  • 举报
回复
vfp5.0中自带的例子Tasmanian Traders中选过来的

申明
*-- DECLARE DLL statements for reading/writing to system registry
DECLARE Integer RegOpenKeyEx IN Win32API ;
Integer nKey, String @cSubKey, Integer nReserved,;
Integer nAccessMask, Integer @nResult

DECLARE Integer RegQueryValueEx IN Win32API ;
Integer nKey, String cValueName, Integer nReserved,;
Integer @nType, String @cBuffer, Integer @nBufferSize

DECLARE Integer RegCloseKey IN Win32API ;
Integer nKey

调用
DO CASE
CASE UPPER(OS()) = "WINDOWS NT"
*-- Gets default user name, organization, and location of MSINFO.EXE from
*-- system registry
*-- First need to open the appropriate key
lnError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEY_SHARED_TOOLS_LOCATION, ;
lnReserved, KEY_QUERY_VALUE, @lnResult)

IF lnError = ERROR_SUCCESS
*-- Read the value for the MSINFO entry
lnError = RegQueryValueEx(lnResult, "MSINFO", lnReserved, ;
@lnType, @lcBuffer, @lnBufferSize)

IF lnError = ERROR_SUCCESS
*-- Strip off the "junk" at the end, and set the form property
thisform.cMSInfoDir = LEFT(lcBuffer, lnBufferSize - 1) + "\MSINFO32.EXE"
IF !FILE(thisform.cMSInfoDir)
*- try the older version
thisform.cMSInfoDir = LEFT(lcBuffer, lnBufferSize - 1) + "\MSINFO.EXE"
IF !FILE(thisform.cMSInfoDir)
thisform.cMSInfoDir = ""
ENDIF
ENDIF
ENDIF

*-- Close the key
=RegCloseKey(lnResult)

lnResult = 0
lcKey = KEY_NTCURRENTVERSION
lnError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lcKey, ;
lnReserved, KEY_QUERY_VALUE, @lnResult)

*-- The next 2 calls to RegQueryValueEx() retrieve the registered owner
*-- and registered organization of the operating system
IF lnError = ERROR_SUCCESS
lnType = 0
lcBuffer = SPACE(128)
lnBufferSize = LEN(lcBuffer)
lnError = RegQueryValueEx(lnResult, "RegisteredOwner", lnReserved, ;
@lnType, @lcBuffer, @lnBufferSize)

IF lnError = ERROR_SUCCESS AND lcBuffer <> CHR(0)
thisform.lblUserName.Caption = LEFT(lcBuffer, lnBufferSize - 1)
ENDIF
ENDIF

lnType = 0
lcBuffer = SPACE(128)
lnBufferSize = LEN(lcBuffer)
lnError = RegQueryValueEx(lnResult, "RegisteredOrganization", lnReserved, ;
@lnType, @lcBuffer, @lnBufferSize)

IF lnError = ERROR_SUCCESS AND lcBuffer <> CHR(0)
thisform.lblUserCorp.Caption = LEFT(lcBuffer, lnBufferSize - 1)
ENDIF
ENDIF

*-- Close the key
=RegCloseKey(lnResult)

CASE UPPER(OS()) = "WINDOWS 4"
*-- Gets default user name, organization, and location of MSINFO32.EXE from
*-- system registry
*-- First need to open the appropriate key
lnError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEY_WIN4_MSINFO, ;
lnReserved, KEY_QUERY_VALUE, @lnResult)

IF lnError = ERROR_SUCCESS
*-- Read the value for the MSINFO entry
lnError = RegQueryValueEx(lnResult, "PATH", lnReserved, ;
@lnType, @lcBuffer, @lnBufferSize)

IF lnError = ERROR_SUCCESS
*-- Strip off the "junk" at the end, and set the form property
thisform.cMSInfoDir = LEFT(lcBuffer, lnBufferSize - 1)
IF !FILE(thisform.cMSInfoDir)
thisform.cMSInfoDir = ""
ENDIF
ENDIF

*-- Close the key
=RegCloseKey(lnResult)

lnResult = 0
lcKey = KEY_WIN4CURRENTVERSION
lnError = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lcKey, ;
lnReserved, KEY_QUERY_VALUE, @lnResult)

*-- The next 2 calls to RegQueryValueEx() retrieve the registered owner
*-- and registered organization of the operating system
IF lnError = ERROR_SUCCESS
lnType = 0
lcBuffer = SPACE(128)
lnBufferSize = LEN(lcBuffer)
lnError = RegQueryValueEx(lnResult, "RegisteredOwner", lnReserved, ;
@lnType, @lcBuffer, @lnBufferSize)

IF lnError = ERROR_SUCCESS AND lcBuffer <> CHR(0)
thisform.lblUserName.Caption = LEFT(lcBuffer, lnBufferSize - 1)
ENDIF
ENDIF

lnType = 0
lcBuffer = SPACE(128)
lnBufferSize = LEN(lcBuffer)
lnError = RegQueryValueEx(lnResult, "RegisteredOrganization", lnReserved, ;
@lnType, @lcBuffer, @lnBufferSize)

IF lnError = ERROR_SUCCESS AND lcBuffer <> CHR(0)
thisform.lblUserCorp.Caption = LEFT(lcBuffer, lnBufferSize - 1)
ENDIF
ENDIF

*-- Close the key
=RegCloseKey(lnResult)

OTHERWISE
*-- Gets default user name, organization, and location of MSINFO.EXE from
*-- WIN.INI (for Windows 3.x machines)
*-- Gets default user name
lcRetVal = GetProStr("MS USER INFO", "DEFNAME", "", @lcBuffer, lnBufferSize)
thisform.lblUserName.Caption = LEFT(lcBuffer, lcRetVal)

*-- Get default corporation name
lcRetVal = GetProStr("MS USER INFO", "DEFCOMPANY", "", @lcBuffer, lnBufferSize)
thisform.lblUserCorp.Caption = LEFT(lcBuffer, lcRetVal)

*-- Get location of MSINFO.EXE name
lcRetVal = GetProStr("MICROSOFT SYSTEM INFO", "MSINFO", "", @lcBuffer, lnBufferSize)
thisform.cMSInfoDir = LEFT(lcBuffer, lcRetVal)

ENDCASE

2,722

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧