OK down below where my IDM button is under WM_COMMAND: is my checkbox processing body.
Under WM_CREATE is the checkbox being created. The problem is my application always starts
with the check box checked, and will NOT let me uncheck it with the mouse. Please help would
be great!

/********************************************************************/
                  /* Account Reset Tool*/
      /******************************************************/
         /*******Developed by: Cody Oebel******************/
            /****** Cody.Oebel@petco.com **************/
                /**************************/

// Preprocessor Directives for auotmation functionality
#include <windows.h>
#include <dos.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

#define IDC_MAIN_BUTTON 101         // Button identifier
#define IDC_MAIN_EDIT   102         // Edit box identifier

HWND hEdit;


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static char *title = TEXT("Account Reset Tool by: Cody Oebel");

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "PasswordResetTool" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);


  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, title,
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                150, 350, 430, 190, 0, 0, hInstance, 0);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

  switch(msg)
  {
      case WM_CREATE:
      {
          // Create an edit box
            hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                10,
                100,
                300,
                50,
                hwnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
            HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);

            SendMessage(hEdit,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));


            SendMessage(hEdit,
                WM_SETTEXT,
                NULL,
                (LPARAM)"Enter users name");

            // Create a push button
            HWND hWndButton=CreateWindowEx(NULL,
                "BUTTON",
                "Unlock and Reset Users Password to Petco1234",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON,
                40,
                60,
                250,
                24,
                hwnd,
                (HMENU)IDC_MAIN_BUTTON,
                GetModuleHandle(NULL),
                NULL);
            SendMessage(hWndButton,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));


        CreateWindow(TEXT("button"), TEXT("Unlock Account"),
                     WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
                     20, 20, 185, 35,
                     hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
        CheckDlgButton(hwnd, 1, BST_CHECKED);
        break;
      }

  case WM_COMMAND:


            switch(LOWORD(wParam))
            {


      case IDC_MAIN_BUTTON:
        {

          BOOL checked = IsDlgButtonChecked(hwnd, 1);
        if (checked)
            {
            CheckDlgButton(hwnd, 1, BST_UNCHECKED);
            MessageBox(0,
                        "Unlocking user and resetting users password to Petco1234",
                        "Unlocking account, and PW reset",
                        MB_ICONINFORMATION);

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

                /*MessageBox(0,
                (LPCSTR)buffer,
                "Information",
                MB_ICONINFORMATION);
                */

            // ADD THE USERS NAME TO ADMINISTRATORS GROUP

                ofstream out;
                out.open("c:\\UserReset.dat");
                out<<(LPCSTR)buffer;
                out.close();
                ifstream in;
                in.open("c:\\UserReset.dat");
                string userid;
                in>>userid;
                in.close();
                string cmd = "/C net user "+userid+" Petco1234 /domain /active:yes";
                LPCSTR lpcmd = cmd.c_str();
                //system(cmd.c_str());  Need to shellexcute command line invisible here
                ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
            //Unlock users account, and reset password to Petco1234
            }
            else
            {
                //CheckDlgButton(hwnd, 1, BST_UNCHECKED);
                MessageBox(0,
                        "Resetting users password to Petco1234",
                        "Reset Password",
                        MB_ICONINFORMATION);

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

                /*MessageBox(0,
                (LPCSTR)buffer,
                "Information",
                MB_ICONINFORMATION);
                */

            // ADD THE USERS NAME TO ADMINISTRATORS GROUP

                ofstream out;
                out.open("c:\\UserReset.dat");
                out<<(LPCSTR)buffer;
                out.close();
                ifstream in;
                in.open("c:\\UserReset.dat");
                string userid;
                in>>userid;
                in.close();
                string cmd = "/C net user "+userid+" Petco1234 /domain";
                LPCSTR lpcmd = cmd.c_str();
                //system(cmd.c_str());  Need to shellexcute command line invisible here
                ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
            //Unlock users account, and reset password to Petco1234
            };

        }
  }
        break;

      case WM_DESTROY:
      {
           PostQuitMessage(0);
           break;
      }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

Recommended Answers

All 4 Replies

ok whats supposed to happen is when I check mark the box then hit the reset password and unlock account button it processes the command. If I leave the checkbox un-checked, and press the button it only resets the password, but does NOT unlock the account.

The problem seems to be with the LOWORD(Lparam) switch-case. Other examples of having CheckDlgButton(hwnd, 1, BST_CHECKED); and CheckDlgButton(hwnd, 1, BST_UNCHECKED); seem to work fine, but in my program it is not!

There are a couple problems with that code

  1. LPWSTR is a pointer, not a character, so LPWSTR buffer[255] creates an array of 255 pointers. Correction: TCHAR buffer[255] is an array of TCHAR characters, and TCHAR is defined as either char or wchar_t depending on whether the program is compiled for UNICODE or not. tchar.h contains many such macros to make your program compile with or without UNICODE without source code changes.

  2. The else statement needs to add CheckDlgButton(hWnd, 1, BST_CHECKED); so that the checkbox can be checked again.

  3. You won't need to write the text in the edit box to a file and read it again into std::string. Just set std::string = buffer. No i/o needed. I didn't test this with UNICODE so you will most likely need std::wstring instead of std::string to do that.

I have no idea whether the shell command actually resets the password or not. Check it from cmd prompt.

Some of the code below was compiler generated. I just added your switch statements to it.

#include "stdafx.h"

#include "Win32Project1.h"
#include <shellapi.h>
#include <string>
#include <fstream>
using namespace std;

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
HWND hEdit = 0;
// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);


int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_WIN32PROJECT1, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT1));

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT1));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCE(IDC_WIN32PROJECT1);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
void ShowError(HWND hWnd)
{
    DWORD dwError = GetLastError();
    char buf[255] = {0};
    FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,0,dwError,0,buf,sizeof(buf),0);
    MessageBox(hWnd,buf,"Error",MB_OK);
}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)
   {
       ShowError(hWnd);
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    BOOL checked;
    HWND hWndButton;
    HGDIOBJ hfDefault = 0;
    switch (message)
    {
        case WM_CREATE:
          // Create an edit box
            hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                10,
                100,
                300,
                50,
                hWnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
            hfDefault=GetStockObject(DEFAULT_GUI_FONT);
            SendMessage(hEdit,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));
            SendMessage(hEdit,
                WM_SETTEXT,
                NULL,
                (LPARAM)"Enter users name");
            // Create a push button
            hWndButton=CreateWindowEx(NULL,
                "BUTTON",
                "Unlock and Reset Users Password to Petco1234",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON,
                40,
                60,
                250,
                24,
                hWnd,
                (HMENU)IDC_MAIN_BUTTON,
                GetModuleHandle(NULL),
                NULL);
            SendMessage(hWndButton,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));

            CreateWindow(TEXT("button"), TEXT("Unlock Account"),
                     WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
                     20, 20, 185, 35,
                     hWnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
            CheckDlgButton(hWnd, 1, BST_CHECKED);
        break;

    case WM_COMMAND:
        wmId    = LOWORD(wParam);
        wmEvent = HIWORD(wParam);
        // Parse the menu selections:
        switch (wmId)
        {
            case IDC_MAIN_BUTTON:
                checked = IsDlgButtonChecked(hWnd, 1);
                if (checked)
                {
                    CheckDlgButton(hWnd, 1, BST_UNCHECKED);
                    MessageBox(0,
                        "Unlocking user and resetting users password to Petco1234",
                        "Unlocking account, and PW reset",
                        MB_ICONINFORMATION);
                    TCHAR buffer[256];
                    SendMessage(hEdit,
                    WM_GETTEXT,
                        sizeof(buffer)/sizeof(buffer[0]),
                        reinterpret_cast<LPARAM>(buffer));
                    // ADD THE USERS NAME TO ADMINISTRATORS GROUP
                    string userid = buffer;
                    string cmd = "/C net user "+userid+" Petco1234 /domain /active:yes";
                        LPCSTR lpcmd = cmd.c_str();
                    //system(cmd.c_str());  Need to shellexcute command line invisible here
                    ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
                    //Unlock users account, and reset password to Petco1234
                }
                else
                {
                    //CheckDlgButton(hwnd, 1, BST_UNCHECKED);
                    MessageBox(0,
                        "Resetting users password to Petco1234",
                        "Reset Password",
                        MB_ICONINFORMATION);
                    TCHAR buffer[256] = {0};
                    SendMessage(hEdit,
                    WM_GETTEXT,
                        sizeof(buffer)/sizeof(buffer[0]),
                        reinterpret_cast<LPARAM>(buffer));
                    // ADD THE USERS NAME TO ADMINISTRATORS GROUP
                    string userid = buffer;
                    string cmd = "/C net user "+userid+" Petco1234 /domain";
                    LPCSTR lpcmd = cmd.c_str();
                    //system(cmd.c_str());  Need to shellexcute command line invisible here
                    ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
                    //Unlock users account, and reset password to Petco1234
                    CheckDlgButton(hWnd, 1, BST_CHECKED);
                }
                break;

        case IDM_ABOUT:
            DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
            break;
        case IDM_EXIT:
            DestroyWindow(hWnd);
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            // TODO: Add any drawing code here...
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        }
        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

OMG I hope your still alive Ancient Dragon. LOL Ok, so I'm working at a new job, and of course wanting to shine in prayers I get permanently employed this time. I'm coding some extras onto my application, and I just cannot figure out where I am going wrong here.

What's not working:

When I checkbox the Unlock User checkbox, it act's as though it's still un-checked. The program is not conditionally operating with my Unlock User checkbox, but the other checkbox works great, and does what it's supposed to.
It's as though my Unlock User checkbox is stuck in an unchecked state.

#include <windows.h>
#include <dos.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

#define IDC_MAIN_BUTTON 101         // Button identifier
#define IDC_MAIN_EDIT   102         // Edit box identifier
#define IDC_MAIN_EDIT2   103         // Edit box identifier 2

HWND hEdit;
HWND hEdit2;
HWND hwnd2;



LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static char *title = TEXT("MVMG NT RESET by: Cody Oebel");

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine, int nCmdShow )
{

  MSG  msg ;
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "PasswordResetTool" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);


  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, title,
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                300, 375, 350, 250, 0, 0, hInstance, 0);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{ 

  switch(msg)
  {

      case WM_CREATE:
      {



          // Create an edit box
            hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                10,
                100,
                300,
               30,
                hwnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
            HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);

            hEdit2=CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                10,
                140,
                300,
                30,
                hwnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
                 HGDIOBJ hfDefault2=GetStockObject(DEFAULT_GUI_FONT);



            SendMessage(hEdit,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));


            SendMessage(hEdit,
                WM_SETTEXT,
                NULL,
                (LPARAM)"Enter NT login ID here");

                  SendMessage(hEdit2,
                WM_SETFONT,
                (WPARAM)hfDefault2,
                MAKELPARAM(FALSE,0));

                SendMessage(hEdit2,
                WM_SETTEXT,
                NULL,
                (LPARAM)"If PW reset. Password will be displayed here");


            // Create a push button
            HWND hWndButton=CreateWindowEx(NULL,
                "BUTTON",
                "and... ACTION!!",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON,
                110,
                60,
                100,
                24,
                hwnd,
                (HMENU)IDC_MAIN_BUTTON,
                GetModuleHandle(NULL),
                NULL);

            SendMessage(hWndButton,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));


        CreateWindow(TEXT("button"), TEXT("Reset PW"),
                     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                     20, 20, 200, 35,
                     hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

        hwnd2=CreateWindow(TEXT("button"), TEXT("Unlock User"),
                     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                    230, 20, 125, 35,
                     hwnd, (HMENU) 1, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

        //break;
      }


  case WM_COMMAND:


            switch(LOWORD(wParam))
               {

     case IDC_MAIN_BUTTON:
               {    

             BOOL ResetPW = IsDlgButtonChecked(hwnd, 1);
             BOOL UnlockAC = IsDlgButtonChecked(hwnd2, 1);

            if(ResetPW)
            {
            SendMessage(hEdit2,WM_SETTEXT,NULL,(LPARAM)"Users new password is: Password123"); 

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

                /*MessageBox(0,
                (LPCSTR)buffer,
                "Information",
                MB_ICONINFORMATION);
                */
                ofstream out;
                out.open("c:\\UserReset.dat");
                out<<(LPCSTR)buffer;
                out.close();
                ifstream in;
                in.open("c:\\UserReset.dat");
                string userid;
                in>>userid;
                in.close();
                string defID = "Enter";
                if(userid == defID)
                {
                MessageBox(0,
                        "Please enter a users NT login",
                        "WHOOOPS TRY AGAIN",
                        MB_ICONINFORMATION);
                        break;
                };
                string cmd = "/C net user "+userid+" Password123 /domain /active:yes";
                LPCSTR lpcmd = cmd.c_str();
                //system(cmd.c_str());  Need to shellexcute command line invisible here
                ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);      
                   MessageBox(0,
                        "Reset users NT PW to: Password123",
                        "Resetting NT Password",
                        MB_ICONINFORMATION);
            //Unlock users account, and reset password to Password123
             }             
            else if(UnlockAC)
            {                       
                LPWSTR buffer[256];
                SendMessage(hEdit,
                WM_GETTEXT,
                sizeof(buffer)/sizeof(buffer[0]),
                reinterpret_cast<LPARAM>(buffer));

                /*MessageBox(0,
                (LPCSTR)buffer,
                "Information",
                MB_ICONINFORMATION);
                */

                ofstream out;
                out.open("c:\\UserReset.dat");
                out<<(LPCSTR)buffer;
                out.close();
                ifstream in;
                in.open("c:\\UserReset.dat");
                string userid;
                string defID="Enter NT login ID here";
                in>>userid;
                in.close();
                if(userid == defID)
                {
                MessageBox(0,
                        "Please enter a users NT login",
                        "WHOOOPS TRY AGAIN",
                        MB_ICONINFORMATION);
                        break;
                };
                string cmd = "/C net user "+userid+" Password123 /domain";
                LPCSTR lpcmd = cmd.c_str();
                //system(cmd.c_str());  Need to shellexcute command line invisible here
                ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);  
                 MessageBox(0,
                        "Unlocked User in Active Directory",
                        "Resetting NT Password",
                        MB_ICONINFORMATION);             
            //Unlock users account, and reset password to Password123
            }
            else
            { 
                MessageBox(0,
                        "OOOPS - You forgot a checkbox",
                        "WHOOPSY",
                        MB_ICONINFORMATION);
                        };


        };

  };

        break;

      case WM_DESTROY:
      {
           PostQuitMessage(0);
           break;
      }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

Solved ... Thanks to NULLptr in another post, and many many thanks to Ancient Dragon.

#include <windows.h>
#include <dos.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

#define IDC_MAIN_BUTTON 101         // Button identifier
#define IDC_MAIN_EDIT   102         // Edit box identifier
#define IDC_CHECKBOX   103         // Edit box identifier 2
#define IDC_CHECKBOX   104

HWND hEdit;
HWND hEdit2;
//HWND hwnd2;
HWND *hwndPTR;
HWND hwnd2;


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

static char *title = TEXT("MVMG NT RESET by: Cody Oebel");

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine, int nCmdShow )
{

  MSG  msg ;
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "PasswordResetTool" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0, IDC_ARROW);


  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, title,
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                300, 375, 350, 250, 0, 0, hInstance, 0);


  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

  switch(msg)
  {

      case WM_CREATE:
      {



          // Create an edit box
            hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                10,
                100,
                300,
               30,
                hwnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
            HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);

            hEdit2=CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|
                ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL,
                10,
                140,
                300,
                30,
                hwnd,
                (HMENU)IDC_MAIN_EDIT,
                GetModuleHandle(NULL),
                NULL);
                 HGDIOBJ hfDefault2=GetStockObject(DEFAULT_GUI_FONT);



            SendMessage(hEdit,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));


            SendMessage(hEdit,
                WM_SETTEXT,
                NULL,
                (LPARAM)"Enter NT login ID here");

                  SendMessage(hEdit2,
                WM_SETFONT,
                (WPARAM)hfDefault2,
                MAKELPARAM(FALSE,0));

                SendMessage(hEdit2,
                WM_SETTEXT,
                NULL,
                (LPARAM)"If PW reset. Password will be displayed here");


            // Create a push button
            HWND hWndButton=CreateWindowEx(NULL,
                "BUTTON",
                "and... ACTION!!",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON,
                110,
                60,
                100,
                24,
                hwnd,
                (HMENU)IDC_MAIN_BUTTON,
                GetModuleHandle(NULL),
                NULL);

            SendMessage(hWndButton,
                WM_SETFONT,
                (WPARAM)hfDefault,
                MAKELPARAM(FALSE,0));


        CreateWindow(TEXT("button"), TEXT("Reset PW"),
                     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                     20, 20, 200, 35,
                     hwnd, (HMENU) 103, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

     CreateWindow(TEXT("button"), TEXT("Unlock User"),
                     WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                    230, 20, 125, 35,
                     hwnd, (HMENU) 104, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

                hwndPTR = &hwnd2;

        break;
      }


  case WM_COMMAND:


            switch(LOWORD(wParam))
               {

     case IDC_MAIN_BUTTON:
               {

             BOOL ResetPW = IsDlgButtonChecked(hwnd, 103);
             BOOL UnlockAC = IsDlgButtonChecked(hwnd, 104);


            if(ResetPW)
            {
            SendMessage(hEdit2,WM_SETTEXT,NULL,(LPARAM)"Users new password is: Password123");

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

                /*MessageBox(0,
                (LPCSTR)buffer,
                "Information",
                MB_ICONINFORMATION);
                */
                ofstream out;
                out.open("c:\\UserReset.dat");
                out<<(LPCSTR)buffer;
                out.close();
                ifstream in;
                in.open("c:\\UserReset.dat");
                string userid;
                in>>userid;
                in.close();
                string defID = "Enter";
                if(userid == defID)
                {
                MessageBox(0,
                        "You forgot to enter their NT login ID",
                        "WHOOOPS TRY AGAIN",
                        MB_ICONINFORMATION);
                        break;

                };
                string cmd = "/C net user "+userid+" Password123 /domain /active:yes";
                LPCSTR lpcmd = cmd.c_str();
                //system(cmd.c_str());  Need to shellexcute command line invisible here
                ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
                   MessageBox(0,
                        "Reset users NT PW to: Password123",
                        "Resetting NT Password",
                        MB_ICONINFORMATION);
            //Unlock users account, and reset password to Password123
            break;
             }
            else if(UnlockAC)
            {
                LPWSTR buffer[256];
                SendMessage(hEdit,
                WM_GETTEXT,
                sizeof(buffer)/sizeof(buffer[0]),
                reinterpret_cast<LPARAM>(buffer));

                /*MessageBox(0,
                (LPCSTR)buffer,
                "Information",
                MB_ICONINFORMATION);
                */

                ofstream out;
                out.open("c:\\UserReset.dat");
                out<<(LPCSTR)buffer;
                out.close();
                ifstream in;
                in.open("c:\\UserReset.dat");
                string userid;
                string defID="Enter";
                in>>userid;
                in.close();
                if(userid == defID)
                {
                MessageBox(0,
                        "You forgot to enter their NT login ID",
                        "WHOOOPS TRY AGAIN",
                        MB_ICONINFORMATION);
                        break;

                };
                string cmd = "/C net user "+userid+" /domain "+"/active:yes";
                LPCSTR lpcmd = cmd.c_str();
                //system(cmd.c_str());  Need to shellexcute command line invisible here
                ShellExecute(0, "open","cmd.exe",lpcmd, 0, SW_HIDE);
                 MessageBox(0,
                        "Unlocked User in Active Directory",
                        "Resetting NT Password",
                        MB_ICONINFORMATION);
            //Unlock users account, and reset password to Password123
            break;
            }



        };

  };

        break;

      case WM_DESTROY:
      {
           PostQuitMessage(0);
           break;
      }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}
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.