Results 1 to 14 of 14
  1. #1
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3

    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.
    Last edited by xephora; 04-23-2011 at 12:53 PM.

  2. #2
    mmbob's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    ja
    Posts
    653
    Reputation
    70
    Thanks
    1,157
    My Mood
    Bitchy
    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].

  3. #3
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    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.

  4. #4
    mmbob's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    ja
    Posts
    653
    Reputation
    70
    Thanks
    1,157
    My Mood
    Bitchy
    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

  5. #5
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    That worked! Thank You!!!!!!!!

  6. #6
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,689
    Reputation
    184
    Thanks
    1,149
    My Mood
    Aggressive
    What would we do without mmbob

  7. #7
    ғᴜᴋᴏᴊʀ's Avatar
    Join Date
    Jul 2010
    Gender
    male
    Posts
    1,557
    Reputation
    87
    Thanks
    141
    My Mood
    Inspired
    Quote Originally Posted by Stephen View Post
    What would we do without mmbob
    Die .


    [IMG]https://i186.photobucke*****m/albums/x253/Rypleys/MNC/biohazard2.jpg[/IMG]

    MPGH in 5 words:

    Quote Originally Posted by ZEROProJect View Post
    1 in a million community

  8. #8
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    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.
    Last edited by xephora; 04-24-2011 at 03:06 PM.

  9. #9
    mmbob's Avatar
    Join Date
    Dec 2009
    Gender
    male
    Location
    ja
    Posts
    653
    Reputation
    70
    Thanks
    1,157
    My Mood
    Bitchy
    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++.

  10. #10
    Fovea's Avatar
    Join Date
    Mar 2011
    Gender
    male
    Posts
    325
    Reputation
    101
    Thanks
    411
    My Mood
    Amused
    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.
    Last edited by Fovea; 04-24-2011 at 04:44 PM.

  11. #11
    258456's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    ghjghj
    Posts
    1,222
    Reputation
    18
    Thanks
    300
    My Mood
    Relaxed
    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?

  12. #12
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Use reshacker to add it. Why would you want to do that though?

  13. #13
    xephora's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Posts
    45
    Reputation
    8
    Thanks
    3
    Deployment? Binaries can't be read within another binary. I thought that's how it goes.

  14. #14
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    You'll need to extract to execute