Retrieve PC's name in MetaTrader4

 

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 

 

open command prompt and type

nbtstat /n
 
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);
   }   
}

 
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.