Changing Hostname && Domain using C++ (Problem)

Posts 1–14 of 14 · Page 1 of 1
Changing Hostname && Domain using C++ (Problem)
Hey guys, sorry I am still working on c++ and trying to experiement a few things. I worked with MSDN and did alot of research, but I came across a few problems hopefully you could help me out.

I am basically trying to change the hostname and domain and hopefully anything else I come across by modifying the registry using C++.

Full Source:

Code:
#include <iostream>
#include <windows.h>

using namespace std; // Eliminating scope resolution operator

char const* text; // set variable text char type as const

HKEY hKey;

int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{

cout << "Hostname Value";
cin >> text; //Input Text into variable "text"

RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName", 0, KEY_SET_VALUE, &hKey);
	RegSetValueEx(hKey, "ComputerName", 0, REG_SZ, (LPBYTE)(LPTSTR)text, MAX_PATH);
	RegCloseKey(hKey);

return 0;
}
[Application]
Using Bloodshed devc++ -> Console Application

[Error]
The only error it seems to be pointing to is text is not a valid type of input. Like I tried to set it as a string to see if it accepts my input, tried char alone to see if it accepts my input, but it's pretty much the same outcome. It fails to compile.
I'm pretty sure chat const* causes the compiler to prevent any modifications to the pointed-to variable, so that's one problem.

Second problem is that your text pointer isn't even initialized, so trying to write to it would cause an access violation most likely. You can either allocate memory with new char[size] (and then delete it afterwards with delete[]) or use a static buffer like char text[size].
I don't know how I would apply that. Can you show me? char size and delete or the char text[size]. I'm at a hault atm. I am searching for this in MSDN.
For the new operator:
Code:
char* text = new char[256];  // allocate an array of 256 chars
// use variable "text"
delete[] text;  // delete array
Static buffer:
Code:
char text[256];  // static buffer of 256 bytes
// use variable "text"
// no cleanup needed
That worked! Thank You!!!!!!!!
What would we do without mmbob
Quote Originally Posted by Stephen View Post
What would we do without mmbob
Die .
Seriously you guys are the best! I really appreciated this. Is there any templates as for moving files, copying files or deleting files. Like I work in the board of education as an IT tech so I create some batch scripts to quickly resolve issues, but now I want to start securing my applications as binaries. What objects/functions should I focus on to manipulate files using C++. I saw quite a few functions, but I would like to know your oppinion on which is best to use. Anything else would be most appreciated as well.
Quote Originally Posted by xephora View Post
Seriously you guys are the best! I really appreciated this. Is there any templates as for moving files, copying files or deleting files. Like I work in the board of education as an IT tech so I create some batch scripts to quickly resolve issues, but now I want to start securing my applications as binaries. What objects/functions should I focus on to manipulate files using C++. I saw quite a few functions, but I would like to know your oppinion on which is best to use. Anything else would be most appreciated as well.
MoveFile Function (Windows)ⓘ
CopyFile Function (Windows)ⓘ
DeleteFile Function (Windows)ⓘ
File Management Functions (Windows)ⓘ

Sometimes things are named really obviously. That is for Win32. I'm not really sure how to do it in standard C++.
Boost FileSystem for de facto standard C++. Should encompass all of what you want.

Alternatively, you may use ifstream in conjunction with ofstream for copying files and cstdio for renaming and deletion.
sorry if i am hijaking this thread lol, but this question is kind of on topic.

Is there a function to store like let's say a file in the program itself? Like, i know you can do text files with .rc files but how can you store a file like an .exe inside your .exe?
Use reshacker to add it. Why would you want to do that though?
Deployment? Binaries can't be read within another binary. I thought that's how it goes.
You'll need to extract to execute
Posts 1–14 of 14 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us