Download MetaTrader 5

Retrieve PC's name in MetaTrader4

To add comments, please log in or register
HaraldSchurr
67
HaraldSchurr  

Hi folks,

 

I need your help with the following question:

is there a way to retrieve the name of the PC my EA is running on in MetraTrader4?

Because I'm running the same EA on the same account on two different Laptops.

One of them at work and the other one at home and only the one at home should be enabled to

send, modify and close orders. Sounds odd to use two identical EAs at the same time and only one

to be productive - but in my case it isn't. So the one at home should be able to be conscious of itself

and know that it is the one at home. Surely I could place a file with the name of each PC in the each

laptops' files directory to enable them to identify themselves but retrieving the PC name would be much

more elegant and less prone to human errors.

 

best regards

Harald 

Marco vd Heijden
Moderator
4753
Marco vd Heijden  

open command prompt and type

nbtstat /n
Ex Ovo Omnia
3191
Ex Ovo Omnia  
HaraldSchurr:

Hi folks,

 

I need your help with the following question:

is there a way to retrieve the name of the PC my EA is running on in MetraTrader4?

Because I'm running the same EA on the same account on two different Laptops.

One of them at work and the other one at home and only the one at home should be enabled to

send, modify and close orders. Sounds odd to use two identical EAs at the same time and only one

to be productive - but in my case it isn't. So the one at home should be able to be conscious of itself

and know that it is the one at home. Surely I could place a file with the name of each PC in the each

laptops' files directory to enable them to identify themselves but retrieving the PC name would be much

more elegant and less prone to human errors.

 

best regards

Harald 

 This is what I use for getting "computer/username" on MT4.

#import "Secur32.dll"
bool GetUserNameExW(int type, string& buffer, int &size);
#import

string readWinuser() {
   string pcNameBuffer;
   int size = 2047;
   createStringBuffer(pcNameBuffer,size);      
   GetUserNameExW(2, pcNameBuffer, size);
   return pcNameBuffer;
}

void createStringBuffer(string& buff, int minLen=1024) {
   buff = "_";
   while(StringLen(buff)<=minLen) {
      StringAdd(buff,buff);
   }   
}

HaraldSchurr
67
HaraldSchurr  
Ovo Cz:

 This is what I use for getting "computer/username" on MT4.

Hello Ovo Cz,

thank you very much for your competent reply - works absolutely great.

Do you have more tricks of that kind? Please let me know. Thanks in advance. 

To add comments, please log in or register