Yes I know its a long code and it will get longer but there is a compiler error in the int main ()
First Visual C++ 2008 Express edition error
------ Build started: Project: MAC ADDRESS, Configuration: Debug Win32 ------
Compiling...
MAC ADDRESS.cpp
warning C4603: '_WIN32_WINNT' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
(3) : use of precompiled header
(2) : warning C4603: '_WIN32_IE' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
(3) : use of precompiled header
(53) : warning C4996: 'swscanf': This function or variable may be unsafe. Consider using swscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(575) : see declaration of 'swscanf'
(81) : warning C4996: 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(252) : see declaration of 'freopen'
(86) : warning C4996: 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(252) : see declaration of 'freopen'
(165) : error C2664: 'SHGetSpecialFolderPathW' : cannot convert parameter 2 from 'LPSTR' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
(181) : error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style castMAC ADDRESS - 2 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
And For Dev C++ Which I PREFER but for what ever reason the code will never compile in it and i think it may be due to the stdafx but i dont know... this is the error
[Linker error] undefined reference to `NetWkstaTransportEnum@28'
[Linker error] undefined reference to `NetApiBufferFree@4'
ld returned 1 exit status
#define _WIN32_WINNT 0x0500
#define _WIN32_IE 0x0500
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>
#pragma comment(lib, "Netapi32.lib")
using namespace std;
// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n",
MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
unsigned char MACData[8]; // Allocate data structure for MAC (6 bytes needed)
WKSTA_TRANSPORT_INFO_0 *pwkti; // Allocate data structure for Netbios
DWORD dwEntriesRead;
DWORD dwTotalEntries;
BYTE *pbBuffer;
// Get MAC address via NetBios's enumerate function
NET_API_STATUS dwStatus = NetWkstaTransportEnum(
NULL, // [in] server name
0, // [in] data structure to return
&pbBuffer, // [out] pointer to buffer
MAX_PREFERRED_LENGTH, // [in] maximum length
&dwEntriesRead, // [out] counter of elements actually enumerated
&dwTotalEntries, // [out] total number of elements that could be enumerated
NULL); // [in/out] resume handle
assert(dwStatus == NERR_Success);
pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer; // type cast the buffer
for(DWORD i=1; i< dwEntriesRead; i++) // first address is 00000000, skip it
{ // enumerate MACs and print
swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx",
&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
PrintMACaddress(MACData);
}
// Release pbBuffer allocated by above function
dwStatus = NetApiBufferFree(pbBuffer);
assert(dwStatus == NERR_Success);
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Please Type the Letter of the Removable Drive followed by [Enter]: \n";
char * buffer5; //Allows user to Input Drive Letter
char name5[1];
cin>> name5;
string base5="C:/Physical-Address.txt";
string str5=base5;
str5.replace(0,1,name5,0,100);
const char *name6;
name6=str5.c_str();
FILE *stream ; //Redirect Output from console to a TextFile
if((stream = freopen(name6, "w", stdout)) == NULL)
exit(-1);
GetMACaddress(); // Obtain MAC address of adapters
stream = freopen("CON", "w", stdout); //Redirect Output to the Screen
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout<<"Welcome to Brandon's Installation Helper\n";
cout<<"Press Enter to begin the program installation\n";
cin.get();
cout<<"Please Wait Reading Address...\n\n";
//Put HostID Into String
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
string HostID;
ifstream in("D:\\Physical-Address.txt");
if (!in)
{
cout << "There was a problem with opening the file for reading." << endl;
}
else
{
getline (in,HostID);
cout<<"Your Host Id is: "<< HostID << endl;
}
Sleep(1000);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"Now Creating Hacked License File... Do Not Exit...\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout<<"License File Created.\n\n";
//Allows user to Input Removable Drive Letter
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout<<"Do This Step CAREFULLY Or Else The Program will Just Exit\n";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
cout<<"Please Type the Letter of the Removable Drive followed by [Enter]: \n";
char * buffer2; //Allows user to Input Drive Letter
char name[1];
cin>> name;
string base2="E:\\Pro. Engineering F000\\ProELicense\\license.dat";
string str1=base2;
str1.replace(0,1,name,0,100);
const char *name2;
name2=str1.c_str();
std::ifstream ifile(name2,std::ios::binary);
ifile.seekg(0,std::ios_base::end);
long s=ifile.tellg();
char *buffer=new char[s];
ifile.seekg(0);
ifile.read(buffer,s);
ifile.close();
std::string txt(buffer,s);
delete[] buffer;
delete[] buffer2;
size_t off=0;
while ((off=txt.find("YOUR_HOST_ID",off))!=std::string::npos)
txt.replace(off,sizeof("YOUR_HOST_ID")-1,HostID);
std::ofstream ofile("D:\\license.dat");
ofile.write(txt.c_str(),txt.size());
//Create "ProELicense" Folder
cout<<"Creating ProELicense Folder!\n";
// get the path to the current users my documents folder
// storing it in an LPSTR
LPSTR userDocsPath = new CHAR[MAX_PATH];
SHGetSpecialFolderPath(0, userDocsPath, CSIDL_PERSONAL, 0);
// now copy the path into a std::string
std::string path = std::string(userDocsPath);
// delete the LPSTR as we don't need it any more...
delete userDocsPath;
// Now you've got the path to your users 'My Documents' folder
// stored in path, you can append any further directories onto it.
// e.g.
path.append("/ProELicense2");
// NOTE: using forward slashes works in file paths, double backslashes are not necessary!
// Not sure you need to bother creating an
// LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
CreateDirectory(path.c_str(), 0);
cout << "\nFolder Created!\n";
Sleep(2000);
return (0);
}