Ok so this is the code.


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];


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.

Edited 3 Years Ago by pritaeas: Moved to C.

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  "));

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().

Edited 3 Years Ago by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.