Hello All,
I have a program where I am trying to get flag values for whether a program has been unchecked, checked, or installed. The purpose is for this program to reboot the system but still be able to continue where it left off following the reboot. This program is cut down to one program for the same of not frusterating me trying to figure this out. Does anyone have any tips? It creates the StateFile but I am not sure how to code it to store those values of RSAFlag.State, and change those values when neccessary.
UPDATE: Ok I have cleaned up the code and moved some things around. So regarding strlen, how should I go about fixing that? I am not very good with this more complex coding. My origional program that would allow users to select between 60 different programs to install worked well but it was basic. The issue was that we found that a couple of the programs required a restart, that is why I have to start delving into more complex coding. Also, what would I call to in order to pass the RSAFlag.State value too? I thought it would be to strlen but everything I am trying is not working. Finding the solution through online research appears to be pointless as anything I can find regards console projects and not a windows application.
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HANDLE StateFile = CreateFile("E:\\StateFile.txt", GENERIC_ALL, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_ARCHIVE, SECURITY_ANONYMOUS);
char DataBuffer[MAX_PATH];
DWORD dwBytesToWrite = (DWORD)strlen(DataBuffer);
DWORD dwBytesWritten = 0;
BOOL WriteStateFile = WriteFile(StateFile, DataBuffer, dwBytesToWrite, &dwBytesWritten, NULL);
enum STATE{Unchecked, Checked, Installed};
struct STATE_FLAG
{
STATE State;
STATE_FLAG(): State(Unchecked) {}
};
STATE_FLAG RSAFlag;
bool checked = true;
switch (message)
{
case WM_CTLCOLORSTATIC:
{
HDC hdc = (HDC) wParam;
SetTextColor(hdc, RGB(0,0,0));
SetBkMode (hdc, TRANSPARENT);
return (LRESULT)GetStockObject(NULL_BRUSH);
};
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hwnd, &ps );
TextOut( hdc, 20, 20, "Adobe Software:", 15);
TextOut( hdc, 20, 70, "Microsoft Software:", 19);
TextOut( hdc, 20, 225, "Other:", 6);
TextOut( hdc, 20, 415, "Model Software:", 15);
TextOut( hdc, 20, 515, "OSR Software:", 13);
EndPaint( hwnd, &ps );
};
break;
case WM_CREATE:
{
CreateWindowW(L"button", L"SecureID",
WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
20, 240, 188, 35,
hwnd, (HMENU) ID_RSA, NULL, NULL);
CreateWindow(TEXT("button"), TEXT("Install"),
WS_VISIBLE | WS_CHILD,
650, 600, 80, 25,
hwnd, (HMENU) ID_INSTALL, NULL, NULL);
CreateWindow(TEXT("Button"), TEXT("Cancel"),
WS_VISIBLE | WS_CHILD,
550, 600, 80, 25,
hwnd, (HMENU) ID_CANCEL, NULL, NULL);
};
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_CANCEL:
PostQuitMessage (0);
break;
};
switch (LOWORD(wParam))
{
case ID_RSA:
checked = IsDlgButtonChecked(hwnd, ID_RSA);
if (checked) {
CheckDlgButton(hwnd, ID_RSA, BST_UNCHECKED); } else {
CheckDlgButton(hwnd, ID_RSA, BST_CHECKED); } if(IsDlgButtonChecked(hwnd, ID_RSA)){
RSAFlag.State = Checked; }
break; };
switch (LOWORD(wParam))
{
case ID_INSTALL:
if(RSAFlag.State == Checked){
CreateProcess(NULL,"C:\\Windows\\System32\\msiexec /i E:\\programs\\RSA\\RSASecurIDToken400.msi /passive",
NULL,NULL,FALSE, CREATE_NEW_CONSOLE,
NULL,NULL,&si,&pi); WaitForSingleObject( pi.hProcess, INFINITE ); RSAFlag.State = Installed; }
CreateProcess(TEXT("E:\\Programs\\completion.bat"),
NULL,NULL,NULL,FALSE, CREATE_NEW_CONSOLE, NULL,NULL,&si,&pi);
WaitForSingleObject( pi.hProcess, INFINITE );
break;
};