https://technet.microsoft.com/en-us/library/cc940113.aspx
Hello again,
as hostname is an OS-command it is not possible to execute this within the MT4-Environment (as far as I know).
The hostname/ComputerName is needed here within an EA/Script, therefore I tried to use the system´s DLLs according to the historical posts.
Maybe I have an informational gap - can I execute the hostname-command directly from the MT4/5-environment and how to pass the output then back to MT4/5 ?
I guesss, that this would no tbe possible already for security-reasons ... (?)
Any comments are welcome :-)
Many thanks
dsalomon
Can you try this?
#import "kernel32.dll" int GetComputerNameW(short &lpBuffer[], int &nSize[]); #import //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { ushort buf[1024]; int len [1]; len[0] = 1024; string ComputerName = ""; //--- GetComputerNameW(buf, len); //--- Alert (ShortArrayToString(buf)); } //+------------------------------------------------------------------+
Can you try this?
Hello Vadim,
great ! This works with MT4 (Build 1090) running on Win7 32-Bit and on Win7 64-Bit too.
Seems, that char vs. ushort was the main-issue !
I will provide an update regarding Win10 once tested.
Thanks a lot !!
dsalomon

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everybody,
I need to retrieve the ComputerName from the local machine and I found some (older) posts regarding this question from 2011 and 2014, but actual NOT ONLY ONE of these exchanged solutions are working with MT4 running on Win7 (neither 32 nor 64-Bit OS).
Either I get EmptyStrings as result or strings containing just extra-character but not the ComputerName which am locking for.
I have tested ALL examples, which I found here in this forum, the code from my last test and the related output are placed below.
Can someone provide an actual axample, how the ComputerName can be retrieved while Running MT4 on Win7-OS ?
Many thanks in advance...
dsalomon
**********************************************
CODE:
OUTPUT:
**********************************************