Ok so this is the code.

hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
        "EDIT",
        "",
        WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
        50,
        100,
        200,
        100,
        hWnd,
        (HMENU)IDC_MAIN_EDIT,
        GetModuleHandle(NULL),
        NULL);

ok so that creates the asset (our edit field to type into).
I can use the below code to display what is in the text box in a message box.

LPWSTR buffer[256];
SendMessage(hEdit,
        WM_GETTEXT,
        sizeof(buffer)/sizeof(buffer[0]),
        reinterpret_cast<LPARAM>(buffer));

MessageBox(NULL,
        (LPWSTR)buffer,
        "Information",
        MB_ICONINFORMATION);

Ok so here's what I am wanting to do. In this edit field a username will be entered example: JohnDoe I need to grab the strong "JohnDoe" and then add it in a simple dos command using the system("net localgroup administrators /add JohnDoe");
How can this be done? My brain is telling me I can declare a LPWSTR name; then name = GetDialogtext(hedit, ... or something like that? Any help would be appreciated.

First off -- LPWSTR is a pointer, declared like this:

typedef wchar_t* LPWSTR

That means LPWSTR buffer[256]; is an array of 256 pointers of type wchar_t*. I don't think that is what you intend.

What you want ot WCHAR buffer[255];

Now to answer your question. Once you get the text into buffer variable you need another buffer in which to format the string that will be passed to system() function. There are a few different ways to do it, one way is to use strcpy followed by strcat

WCHAR cmd[255];

_tcscpy(cmd,_T("net localgroup administrators /add  "));
_tcscat(cmd,buffer);
_wsystem(cmd);

One problem with system() and _wsystem() is that there is no way to prevent the cmd box from appearing on the scrren momentarily while the command is being executed. If you want to hide that then you need to call a different function, such as CreateProcess(). I'm not sure whether it can be hidden if ShellExecute() is called or not. But I know that it can be hidden with CreateProcess().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.