Protect cBot with machine ID - Error iphlpapi.dll
            
                 20 Apr 2023, 18:15
            
                    
Hi developers,
maybe some c# eperts can help me.
I'm trying to protect a cbot based on machine ID (MAC address).
but wenn I use my code I receive the error: "Crashed in OnTick with DllNotFoundException: Unable to load DLL 'iphlpapi.dll' or one of its dependencies: 0x80070005 (E_ACCESSDENIED)".
I checked my windows folder, the 'iphlpapi.dll' is in there. So how could I solve the problem? Any ideas what the reason is and how to solve it?
here is the code I use for checking the machine ID:
using System.Net.NetworkInformation;
...
...
...
  public string getMacAddress()
        {
            String firstMacAddress = NetworkInterface
                .GetAllNetworkInterfaces()
                .Where(nic => nic.OperationalStatus == OperationalStatus.Up && nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                .Select(nic => nic.GetPhysicalAddress().ToString())
                .FirstOrDefault();
            return firstMacAddress;
        }
I
Replies
                     SmartRetailTradingRobot
                     21 Apr 2023, 09:55
                                    
Hi Firemyst,
thanks a lot! You solved my problem on first try. The mistake of mine was as simple as stupid... I forgett to set the AccessRights to FullAccess.
Best regards!
Nik
@SmartRetailTradingRobot

firemyst
21 Apr 2023, 05:12
First of all, the error message says, "Access Denied". So have you tried granting your cBot full access?
Ex:
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
Second, if that doesn't work, and you've already added it as a "reference" to your solution in cTrader, then you'll probably have to use the DLL Import directive in C#.
And for that, I suggest you try using Google to find examples as there's plenty out there.
Blah blah blah :-)
@firemyst