Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Improve your rating!
HaraldSchurr
66
HaraldSchurr 2015.10.15 02:33 

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
4506
Marco vd Heijden 2015.10.15 08:26  

open command prompt and type

nbtstat /n
Ovo Cz
3049
Ovo Cz 2015.10.15 08:34  
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
66
HaraldSchurr 2015.10.15 19:50  
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