当前位置 : 主页 > 编程语言 > delphi >

delphi – 如何在Windows 7中获取域名

来源:互联网 收集:自由互联 发布时间:2021-06-23
我写了一个运行Excel加载项的dll(几年前). 我使用此代码检索域名,并在Windows XP中正常工作,但在Windows 7中失败. 只有我以管理员身份运行才有效. 但是,我不想以管理员身份运行,因为此代码
我写了一个运行Excel加载项的dll(几年前).

我使用此代码检索域名,并在Windows XP中正常工作,但在Windows 7中失败.
只有我以管理员身份运行才有效.
但是,我不想以管理员身份运行,因为此代码是Excel加载项DLL的一部分,如果以管理员身份运行,Excel无法找到用户的文件.

MyReg:= TRegistry.Create;

MyReg.RootKey:= HKEY_LOCAL_MACHINE;
MyReg.OpenKey(RegKeyWin7,false);
NetworkID2:= lowercase(trim(MyReg.ReadString(RegValWin7)));
MyReg.CloseKey;

FreeAndNil(MyReg);

FNetworkOK:= (NetworkID2 = OKRes4);
//Temp check to pinpoint the problem.
if FNetWorkOK = false then ShowMessage('Error wrong domain: '+NetworkID2)
else ShowMessage('all ok');

如何在正常权限下使用Delphi检索Windows 7中的域名?

在Win32 API中使用 NetWkstaGetInfo,通过级别值= 100请求信息.

Return information about the workstation environment, including platform-specific information, the name of the domain and the local computer, and information concerning the operating system. The bufptr parameter points to a WKSTA_INFO_100 structure.

网友评论