0

Hi everyone, I have been writing a program that resembles the "WHICH" program of LINUX for the Windows Platform. It accepts a program from User Input and tries to look for it in the registry. But unfortunately, there is a lot of memory corruption and i cannot even add lines of codes. Thanks for your help.

#include <windows.h>
#include <iostream.h>
#include <string.h>
int main()
{
 char rgvalue[100];
 LONG lnResult;
 DWORD Type;
 DWORD size1;
 HKEY hKey;

 char reg[100];
 strcpy(reg, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\");
 char prog[100];

 cout << "Enter: ";
 cin >> prog;

 char all[100];
 strcat(all, reg);
 strcat(all, prog);

 if (strcmp(prog, "iexplore.exe") == 0)
 {
    strcpy(rgvalue, "%ProgramFiles%\\intern~1");
 }
 else if (strcmp(prog, "cmd.exe") == 0)
 {
    strcpy(rgvalue, "%systemroot%\\system32");
 }
 else
 {

      if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE, all, 0, KEY_ALL_ACCESS, &hKey) )
      {
        cout << "Program does not Exist in Registry\n";
        return 0;
      }

     RegQueryValueEx(hKey, "Path", NULL, &Type, (LPBYTE)rgvalue,&size1);
     }

 /*strcpy(prog, "explorer.exe");
 strcat(prog, " ");
 strcat(prog, rgvalue);
 system(prog);*/

 cout << rgvalue << endl;





 return 0;
}
2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by Index
0

Maybe you should try to initialize "all" variable before strcat
char all[100] = "";
or change
strcat(all, reg);
to
strcpy(all, reg);

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.