Question for experienced C++ programmers

homeyg

Deity
Joined
Jan 12, 2004
Messages
3,631
Now, in school in my intro to business class (typing class), we found out how to send messages from one computer to the other in the class and the entire school through the Windows command prompt (using the 'net send' command). We have to be stealthy about it because when our old teacher sees that big black box on the screen, she can tell something's up. Several kids have even gotten several detentions when caught sending messages. My question is, though, whether it is possible to write an application in C++ that can access the command prompt's commands without the command prompt being open; a smaller window, maybe even a toolbar. Now, I'm horribly unexperienced in C++ or Windows programming (I'm learning C++ from the book in my av.), but I'm wondering if it could be done so that when I do completely learn the language, I have something to look forward to.

Thanks in advance-
 
I'm sure it can be done, but I'm not that experienced in C++.
 
short answer: yes.

i wouldn't use this as something to look forward to though.

EDIT:
and if you're learning C++ it shouldn't be anything particularly unusual to have the command prompt up.
 
Another short answer is that the function is called "spawn" or one of its various variants.

If you want to do this quick and easy:
- Write a bat file to call your net send command with %1, %2 etc for whatever parameters that you wan to be variable. Put the word exit on the last line of your bat file.
- Create a shortcut to the bat file. Mark it as "Run Minimised" and "Close on Exit"
- Run your shortcut (the pif) with parameters from the "Run" option on the "Start Menu".
 
And you can do that with a GUI... disguise itself as say, notepad, while it is actually sending messages around ;)
 
bobgote said:
and if you're learning C++ it shouldn't be anything particularly unusual to have the command prompt up.
Sure, if your talking about when I run programs. I don't really know very much about the command prompt otherwise.

Craig_San said:
Another short answer is that the function is called "spawn" or one of its various variants.

If you want to do this quick and easy:
- Write a bat file to call your net send command with %1, %2 etc for whatever parameters that you wan to be variable. Put the word exit on the last line of your bat file.
- Create a shortcut to the bat file. Mark it as "Run Minimised" and "Close on Exit"
- Run your shortcut (the pif) with parameters from the "Run" option on the "Start Menu".
I don't know anything about bat files (except that they mean batch files), my C++ knowlege is limited.

kcwong said:
And you can do that with a GUI... disguise itself as say, notepad, while it is actually sending messages around ;)
Don't know what a GUI is either.

I need some explanations on some of these things.
 
GUI is graphic user interface.

My advice...Take a C++ class.

P.S.: For even more fun, try using VNC to take over someone's computer. (If your school computers have VNC.) It's wicked fun to take over someone's computer and start opening their folder of programs and put it in the recycle bin, then going to the recycle bin, putting your pointer over the empty recycle bin button, and then holding it there for a few seconds and then releasing control. It's untraceable too, and it looks like you are doing work.
 
I plan on taking a class in C++ next year. I'm in 9th grade which means you have to take computer apps before you can take any computer sciences.

Also, I don't know what VNC is or if the computers have it, but I have heard of people doing the stuff you described (taking over someone else's computer).
 
homeyg said:
Now, in school in my intro to business class (typing class), we found out how to send messages from one computer to the other in the class and the entire school through the Windows command prompt (using the 'net send' command). We have to be stealthy about it because when our old teacher sees that big black box on the screen, she can tell something's up. Several kids have even gotten several detentions when caught sending messages. My question is, though, whether it is possible to write an application in C++ that can access the command prompt's commands without the command prompt being open; a smaller window, maybe even a toolbar. Now, I'm horribly unexperienced in C++ or Windows programming (I'm learning C++ from the book in my av.), but I'm wondering if it could be done so that when I do completely learn the language, I have something to look forward to.

Thanks in advance-
You can do that with the run dialog box without needing to resort to C++... just press Win+R (I think that's the shortcut for Run, I'm not completely sure), type out a quick net send, press ok, and away it goes. Also, the system command in C++ might work for that (i.e. system("/net send ...");). Also, batch files (someone already mentioned them) would be an easy way to do that (just make a text file containing the command with exit at the end, and then give it the file extension *.bat, and Windows will treat it as an executable)
 
Syterion said:
GUI is graphic user interface.

My advice...Take a C++ class.

P.S.: For even more fun, try using VNC to take over someone's computer. (If your school computers have VNC.) It's wicked fun to take over someone's computer and start opening their folder of programs and put it in the recycle bin, then going to the recycle bin, putting your pointer over the empty recycle bin button, and then holding it there for a few seconds and then releasing control. It's untraceable too, and it looks like you are doing work.

Ahh, VNC. We use that at work in Tech Support. :mischief: But, you shouldn't be advocating computer hacking though.
 
Thanks for your responses. I think I get it now. Since this thread is titled "Question for experienced C++ programmers", I've got another question on a program I've been trying to write (I'm pretty much done except for one annoying bug). The bug (in the program below) occurs right above where the bolded comment is and for the rest of the program, however, doesn't occur before this (I proved this with the numerous 'cout' statements). I don't know why it occurs or how it occurs, but it does. The program I'm writing tells two variations of the equation of the line that passes through the two points entered and the slope of that line. All goes well when initializing the pointArrays, the right values are stored (at least I think); x1 and y1 for pointArray11 and x2 and y2 for pointArray21. I've proved this by adding cout statements after each initialization index. Now this is where I'm stumped: in the cout statement that displays all of the values together, pointArray11[0] changes its value to the value stored in pointArray21[1] and all others still hold their correct values. I have no idea how this happens! pointArray11[0] retains the value stored in pointArray21[1] for the rest of the program. Can anyone see why this is happening? I sure can't. Thanks to anyone who spends their time to solve my pathetic program's problem.

Code:
#include <iostream>

using namespace std;

double yIntercept(double rise, double run, double xcoor, double ycoor);

int main()
{
    int cont;
    double pointArray11[1];
    double pointArray21[1];
    
    cout << "This program finds the slope and two variations of the equation of the line that passes through these two points."<<endl;
    while(cont!=0)
    {  
        cout << "Please enter the coordinates of the first point." << endl;
        for(int coor = 0; coor<2; coor++)
        {
            double* coordinateSpace1 = new double;
            cout << "Coordinate?";
            cin  >> *coordinateSpace1;
            pointArray11[coor] = *coordinateSpace1;
            delete coordinateSpace1;
        }
        cout << pointArray11[0]<<pointArray11[1]<<endl;
        
        
        cout << "Please enter the coordinates of the second point." << endl;
        for(int rooc = 0; rooc<2; rooc++)
        {
            double* coordinateSpace2 = new double;
            cout << "Coordinate?";
            cin  >> *coordinateSpace2;
            pointArray21[rooc] = *coordinateSpace2;
            delete coordinateSpace2;
        }
        cout << pointArray21[0]<<pointArray21[1]<<endl;    
        
        cout << pointArray11[0]<<pointArray11[1]
             << pointArray21[0]<<pointArray21[1]<<endl;
        [B]//pointArray11[0] changes to same value as pointArray21[1] during the cout statement above and for the rest of the program[/B]     
        
        double slope1 = pointArray21[1] - pointArray11[1];
        double slope2 = pointArray21[0] - pointArray11[0];
        cout << "The slope of the line is: " << slope1 <<"/" << slope2 << endl;
        cout << "The equation for the line is: y-" << pointArray11[1] << "=" << slope1 << "/"<<slope2 << "(x-"<< pointArray11[0] <<")"<<endl;
        cout << "The slope-intercept form of this equation is: y=" <<slope1<<"/"<<slope2<<"x+"<<yIntercept(slope1, slope2, pointArray11[0], pointArray11[1])<<endl;
        cout << "Continue? Press zero to quit and any number to continue." <<endl;
        cin  >> cont;
    }       
    
    return 0;
}
   
double yIntercept(double rise, double run, double xcoor,  double ycoor)  
{
    double b = rise/run*(0-xcoor)+ycoor;
    return b;
}
 
Honeyg,
Declaring an array with 1 element means that it only has 1 element - and that one element is the zero-th element, ie pointArray11[0] or pointArray21[0]. Accessing either pointArray11[1] or pointArray21[1] is overflowing your array.

(N.B. The reason that writing to pointArray21[1] over-writes pointArray11[0] is that both arrays are right next to each other in the stack. Because the stack pointer goes backwards, the later variable is in memory in front of the earlier variable - if that makes sense.)
 
couple of hints:

Code:
for(int coor = 0; coor<2; coor++)
{
    double* coordinateSpace1 = new double;
    cout << "Coordinate?";
    cin  >> *coordinateSpace1;
    pointArray11[coor] = *coordinateSpace1;
    delete coordinateSpace1;
}
firstly - don't use a pointer where it is not needed.
second - variable should be declared out of loop then re-used each iteration.

ie:
Code:
double coordinate;
for(int coor = 0; coor<2; coor++)
{            
    cout << "Coordinate?";
    cin  >> coordinate;
    pointArray11[coor] = coordinate;
}

also, for your example here, i would suggest the use of a "Point" class/struct to simplify the whole program. i really don't see the point of arrays here. while maybe you aren't up to structs yet, it would certainly be a good idea to work that out. unsure if there is a point class/struct in the std lib.

oh, and also be careful about taking stuff from cin and assuming it's a double. i imagine some sort of input validation would be a good idea here.

EDIT:
oh yeah, and just to confirm, the thing about array out of bounds is likely your problem. in C++, arrays don't have any error checking at all, unfortunately no functions such as .length neither (from memory), so you'll have to store size variables (or constants) locally and always use them for loops.
 
Thanks, guys. @bobgote: I was only using pointers to see if I could use them right. I wouldn't have otherwise. :D
 
As to the original question, the easiest way to execute the equivalent of a 'command prompt' command in C++ is using the standard library function, system().

As in,

#include <cstdlib>
...
system("netsend blah");

-Sirp.
 
Back
Top Bottom