Hello,
I'm trying to write a vector that has a list of installed program names to a text file. When I go to do this, the program shows the names of the installed applications, but in the text file it just repeats the number 52428. Any ideas? Here's the code:
#include "stdafx.h"
#include "windows.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
vector<WCHAR> programs;
bool EnumInstalledSoftware(void);
int main(void)
{
ofstream storage;
int branch;
int type;
char info1[256];
char info2[256];
char info3[256];
char info4[256];
char info5[256];
char info6[256];
char info7[256];
char info8[256];
char info9[256];
char info10[256];
char info11[256];
char info12[256];
char attachment[256] = "";
vector<string> at;
char info13[256];
char software[256] = "";
at.clear();
programs.clear();
cout << "FJSB Inventory\n\n";
cout << "Select a branch:\n";
cout << "1.Fort Jennings\n";
cout << "2.Ottoville\n";
cout << "3.Columbus Grove\n";
cout << "4.Ottowa\n";
cout << "5.Leipsic\n";
cout << "Choice: ";
cin >> branch;
cout << "\nSelect the type of device:\n";
cout << "1.Workstation\n";
cout << "2.Server\n";
cout << "3.Printer\n";
cout << "4.Router\n";
cout << "5.Switch\n";
cout << "6.Firewall\n";
cout << "Choice: ";
cin >> type;
if (type == 1 || type == 2)
{
cout << "\n\nMachine Make and Manufacturer: ";
cin.ignore();
cin.getline(info1,256);
cout << "\nMachine Serial Number: ";
cin.getline(info2,256);
cout << "\nComputer name: ";
cin.getline(info3,256);
cout << "\nUser name: ";
cin.getline(info4,256);
cout << "\nIP address: ";
cin.getline(info5,256);
cout << "\nOperating system: ";
cin.getline(info6,256);
cout << "\nService Pack Level: ";
cin.getline(info7,256);
cout << "\nInternet Explorer Version: ";
cin.getline(info8,256);
cout << "\nProcessor type: ";
cin.getline(info9,256);
cout << "\nRam: ";
cin.getline(info10,256);
cout << "\nHard Disk Size: ";
cin.getline(info11,256);
cout << "\nMapped drive letters: ";
cin.getline(info12,256);
cout << "\nAny attached hardware = make and model , excluding monitor, mouse and keyboard \n(things like printers, scanners, check readers): ";
char more = 'y';
int x = 0;
while (more == 'y')
{
cout << "\nAttachment: ";
if (x == 1)
cin.ignore();
cin.getline(attachment, 256);
at.push_back(attachment);
cout << "More? (y/n): ";
cin >> more;
x = 1;
}
cout << "\nAntivirus version: ";
cin.ignore();
cin.getline(info13,256);
EnumInstalledSoftware();
cout << "\n\nPlease hold while the data saves...";
storage.open("FJSB_Inventory.txt",fstream::app);
if (branch == 1)
storage << "Fort Jennings\n";
else if (branch == 2)
storage << "Ottoville\n";
else if (branch == 3)
storage << "Columbus Grove\n";
else if (branch == 4)
storage << "Ottowa\n";
else
storage << "Leipsic\n";
if (type == 1)
storage << "Workstation\n";
else if (type == 2)
storage << "Server\n";
else if (type == 3)
storage << "Printer\n";
else if (type == 4)
storage << "Router\n";
else if (type == 5)
storage << "Switch\n";
else
storage << "Firewall\n";
storage << "Machine Make and Manufacturer: " << info1 << "\n";
storage << "Machine Serial Number: " << info2 << "\n";
storage << "Computer name: " << info3 << "\n";
storage << "User name: " << info4 << "\n";
storage << "IP address: " << info5 << "\n";
storage << "Operating system: " << info6 << "\n";
storage << "Service Pack Level: " << info7 << "\n";
storage << "Internet Explorer Version: " << info8 << "\n";
storage << "Processor type: " << info9 << "\n";
storage << "Ram: " << info10 << "\n";
storage << "Hard Disk Size: " << info11 << "\n";
storage << "Mapped drive letters: " << info12 << "\n";
storage << "Attachments:\n";
for (int k = 0; k < at.size(); ++k)
storage << at[k] << "\n";
storage << "Antivirus version: " << info13 << "\n";
storage << "Programs:\n";
for (int l = 0; l < programs.size(); ++l)
{
storage << programs[l] << "\n";
}
storage << "\n";
storage.close();
cout << "\nDone!";
}
else
{
cout << "\n\nMachine Manufacturer: ";
cin.ignore();
cin.getline(info1,256);
cout << "\nModel number : ";
cin.getline(info2,256);
cout << "\nMachine Serial Number: ";
cin.getline(info3,256);
if (type == 5)
{
cout << "\nNumber of ports: ";
cin.getline(info4,256);
}
if (type == 3)
{
cout << "\nLogical name: ";
cin.getline(info4,256);
}
cout << "Please hold while the data saves...";
storage.open("FJSB_Inventory.txt", fstream::app);
if (branch == 1)
storage << "Fort Jennings\n";
else if (branch == 2)
storage << "Ottoville\n";
else if (branch == 3)
storage << "Columbus Grove\n";
else if (branch == 4)
storage << "Ottowa\n";
else
storage << "Leipsic\n";
if (type == 1)
storage << "Workstation\n";
else if (type == 2)
storage << "Server\n";
else if (type == 3)
storage << "Printer\n";
else if (type == 4)
storage << "Router\n";
else if (type == 5)
storage << "Switch\n";
else
storage << "Firewall\n";
storage << "Machine Manufacturer: " << info1 << "\n";
storage << "Model number: " << info2 << "\n";
storage << "Machine Serial Number: " << info3 << "\n";
if (type == 5)
storage << "Number of ports: " << info4 << "\n";
if (type == 3)
storage << "Logical name: " << info4 << "\n";
storage << "\n";
storage.close();
cout << "\nDone!";
}
return 0;
}
bool EnumInstalledSoftware(void)
{
HKEY hUninstKey = NULL;
HKEY hAppKey = NULL;
WCHAR sAppKeyName[1024];
WCHAR sSubKey[1024];
WCHAR sDisplayName[1024];
WCHAR *sRoot = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
long lResult = ERROR_SUCCESS;
DWORD dwType = KEY_ALL_ACCESS;
DWORD dwBufferSize = 0;
//Open the "Uninstall" key.
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, sRoot, 0, KEY_READ, &hUninstKey) != ERROR_SUCCESS)
{
return false;
}
for(DWORD dwIndex = 0; lResult == ERROR_SUCCESS; dwIndex++)
{
//Enumerate all sub keys...
dwBufferSize = sizeof(sAppKeyName);
if((lResult = RegEnumKeyEx(hUninstKey, dwIndex, sAppKeyName,
&dwBufferSize, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS)
{
//Open the sub key.
wsprintf(sSubKey, L"%s\\%s", sRoot, sAppKeyName);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, sSubKey, 0, KEY_READ, &hAppKey) != ERROR_SUCCESS)
{
RegCloseKey(hAppKey);
RegCloseKey(hUninstKey);
return false;
}
//Get the display name value from the application's sub key.
dwBufferSize = sizeof(sDisplayName);
if(RegQueryValueEx(hAppKey, L"DisplayName", NULL,
&dwType, (unsigned char*)sDisplayName, &dwBufferSize) == ERROR_SUCCESS)
{
wprintf(L"%s\n", sDisplayName);
}
RegCloseKey(hAppKey);
}
programs.push_back(sDisplayName[1024]);
}
RegCloseKey(hUninstKey);
return true;
}