Reputation: 76537
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?
Upvotes: 4
Views: 1568
Reputation: 54128
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.
Upvotes: 7