Database 版 (精华区)
发信人: mengy (LEAR DLLS 命令时,将从内存中清除), 信区: Database
标 题: Visual FoxPro 3.0中获取WINDOWS用户信息
发信站: 哈工大紫丁香 (2000年12月13日09:15:42 星期三), 站内信件
Visual FoxPro 3.0中获取WINDOWS用户信息
在使用WINDOWS应用软件时我们可能都会注意到在应用软件的帮助菜单中有一
条名为“关于……”的菜单,点击它后会出现一个“关于……”的窗口。在窗口中
有一项是“本软件的使用权属于”,下面是安装应用软件或WINDOWS时输入的用户
名和用户单位。这些信息在WINDOWS 3.X中存储于WIN.INI,在WINDOWS 95或
WINDOWS NT中则存储于系统注册表中,在Visual FoxPro 3.0中我们也可以通过访
问WIN.INI 或系统注册表来获取这一信息定制自己的版权声明窗口。获取用户信
息源程序如下:
Set Talk off
Clear
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
DECLARE INTEGER GetProfileString IN Win32API AS GetProStr;
String cSection, String cKey, String cDefault,;
String @cBuffer, Integer nBufferSize
UserName = ""
UserCorp = ""
lnResult = 0
Buffer = SPACE(128)
BufferSize = LEN(Buffer)
IF UPPER(OS()) = "WINDOWS NT" OR UPPER(OS()) = "WINDOWS 4"
lcKey = IIF("NT" $ UPPER(OS()), "Software\Microsoft\Windows;
NT\CurrentVersion",;
"Software\Microsoft\Windows\CurrentVersion")
lnError = RegOpenKeyEx(-2147483646,lcKey , 0, 1, @lnresult)
IF lnError = 0
LnType = 0
Buffer = SPACE(128)
BufferSize = LEN(Buffer)
LnError = RegQueryValueEx(lnresult, "Registeredowner",;
0, @lnType, @Buffer, @BufferSize)
IF lnError = 0 AND Buffer <> CHR(0)
UserName = LEFT(Buffer, BufferSize - 1)
ENDIF
lnType = 0
Buffer = SPACE(128)
BufferSize = LEN(Buffer)
lnError = RegQueryValueEx(lnresult,;
"RegisteredOrganization", 0, @lnType,;
@Buffer, @BufferSize)
IF lnError = 0 AND Buffer <> CHR(0)
UserCorp = LEFT(Buffer, BufferSize - 1)
ENDIF
ENDIF
=RegCloseKey(lnResult)
ELSE
RetVal = GetProStr("MS USER INFO", "DEFNAME", "",;
@Buffer, BufferSize)
UserName = LEFT(Buffer, RetVal)
RetVal = GetProStr("MS USER INFO", "DEFCOMPANY", "",;
@Buffer, BufferSize)
UserCorp = LEFT(Buffer, RetVal)
ENDIF
@ 10 ,10 SAY "用户姓名:" + UserName
@ 12 ,10 SAY "用户单位:"+ UserCorp
Set Talk On
以上程序在Visual FoxPro 3.0和WINDOWS 95中运行通过。
返回
--
大海无边天做岸
山登绝顶我为风
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.227.121]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.891毫秒