用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧计算机应用

在VFP中获取Windows注册信息的方法

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-01-10 11:51:25
【本文由PB创新网为您整理】
关键词

 

    在Visual Foxpro软件的程序设计中,我们经常需要关注其程序设计的环境,尤其是获得Windows软件系统注册的用户名及单位名称。为此我们设计了一个在Windows 3.XWindow 95Windows 98Windows NT 4.0环境下均通用的一个子程序,可以满足上述的需要。

 

#DEFINE MACHINE_ID -2147483646

#DEFINE VER_PATH "Software/Microsoft/Windows/CurrentVersion"

 

*--声明Windows API 函数

DECLARE INTEGER GetProfileString IN Win32API AS GetProStr ;

String cSection, String cKey, String cDefault, ;

String @cBuffer, Integer nBufferSize

 

*-- 声明注册表函数

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

 

*-- 初始化DLL调用变量

OutBuffer = SPACE(128)

STORE 0 TO Reserved, Result, Type

BufferSize = LEN(OutBuffer)

 

STORE "" TO OutUser, OutCompany

 

*-- 通过VFP的OS()函数判定当前操作系统类型

DO CASE

CASE UPPER(OS()) = "WINDOWS 4"

*-- 系统为Windows 95 以上版本

Error = RegOpenKeyEx(MACHINE_ID, VER_PATH, ;

Reserved, 1, @Result)

 

IF Error = 0

Type = 0

OutBuffer = SPACE(128)

BufferSize = LEN(OutBuffer)

Error = RegQueryValueEx(Result, "RegisteredOwner", Reserved, ;

@Type, @OutBuffer, @BufferSize)

 

IF Error = 0 AND OutBuffer <> CHR(0)

OutUser = LEFT(OutBuffer, BufferSize - 1)

ENDIF

 

Type = 0

OutBuffer = SPACE(128)

BufferSize = LEN(OutBuffer)

Error = RegQueryValueEx(Result, "RegisteredOrganization", Reserved, ;

@Type, @OutBuffer, @BufferSize)

 

IF Error = 0 AND OutBuffer <> CHR(0)

OutCompany = LEFT(OutBuffer, BufferSize - 1)

ENDIF

ENDIF

=RegCloseKey(Result)

 

CASE UPPER(OS()) = "WINDOWS NT"

*-- 系统为Windows NT

Error = RegOpenKeyEx(MACHINE_ID, KEY_SHARED_TOOLS_LOCATION, ;

Reserved, 1, @Result)

 

IF Error = 0

Type = 0

OutBuffer = SPACE(128)

BufferSize = LEN(OutBuffer)

Error = RegQueryValueEx(Result, "RegisteredOwner", Reserved, ;

@Type, @OutBuffer, @BufferSize)

 

IF Error = 0 AND OutBuffer <> CHR(0)

OutUser = LEFT(OutBuffer, BufferSize - 1)

ENDIF

 

Type = 0

OutBuffer = SPACE(128)

BufferSize = LEN(OutBuffer)

Error = RegQueryValueEx(Result, "RegisteredOrganization", Reserved, ;

@Type, @OutBuffer, @BufferSize)

 

IF Error = 0 AND OutBuffer <> CHR(0)

OutCompany = LEFT(OutBuffer, BufferSize - 1)

ENDIF

ENDIF

=RegCloseKey(Result)

 

OTHERWISE

*-- 系统为Windows 3.X 版本

OutRetVal = GetProStr("MS USER INFO", "DEFNAME", "", @OutBuffer, BufferSize)

OutUser = LEFT(OutBuffer, OutRetVal)

 

OutRetVal = GetProStr("MS USER INFO", "DEFCOMPANY", "", @OutBuffer,BufferSize)

OutCompany = LEFT(OutBuffer, OutRetVal)

 

ENDCASE

 

If Error = 0

=MessageBox("用户:" + OutUser + Chr(13) + "单位:" + OutCompany)

Else

=MessageBox("未找到用户及单位。")

Endif

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:1,687.50000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号