开发者

How do I get the domain name in Windows 7

I've written a dll that runs an Excel add-in (some years ago).

I use this code to retrieve the domain name and that works fine in Windows XP, but it fails in Windows 7.

Only if I run as administrator does it work.

However I don't want to run as administrator because this code is part of an Excel add-in dll and Excel cannot find the user's files if running as admin.

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');

How do I retrieve the domain name in Windows 7 using Delphi under normal开发者_运维知识库 privileges?


Use NetWkstaGetInfo in the Win32 API, requesting info via level value = 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜