我写了一个运行Excel加载项的dll(几年前). 我使用此代码检索域名,并在Windows XP中正常工作,但在Windows 7中失败. 只有我以管理员身份运行才有效. 但是,我不想以管理员身份运行,因为此代码
我使用此代码检索域名,并在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.
