System(), any other way?

This is a discussion on System(), any other way? within the C++ Programming forums, part of the General Programming Boards category; Is there any other way to execute a command without using system() like because system() uses the command prompt to ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    System(), any other way?

    Is there any other way to execute a command without using system() like because system() uses the command prompt to execute the thing but i dont want to do that.
    Code:
    #include <iostream>
    #include <windows.h>
    
    int main()
    {
        char TheThingYouWantToDo[NULL];
        std::cout<<"What cha wanna do fool:";
        std::cin>>TheThingYouWantToDo;
        system(TheThingYouWantToDo);
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    On windows you can use ShellExecuteEx or CreateProcess.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    CreateProcess() has an option to create the new process without a window. Don't know is ShellExecuteEx() can do that or not.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    ShellExecuteEx will give the app a console if it's a console app.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    >> char TheThingYouWantToDo[NULL];

    BTW, this won't work. You have a 0 sized array that you are trying to read data into from cin.
    Last edited by Daved; 11-22-2005 at 11:59 AM.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    it lets me in DEV-C++ and i did it so i can bufferoverflow if i want

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    Ok, maybe it might "work" in some situations, but it is wrong. Besides, you could put 999 in there instead of NULL and it would be less typing and much closer to correct, so why would you use NULL?

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by bikr692002
    it lets me in DEV-C++ and i did it so i can bufferoverflow if i want
    You can make a program that could crash and or loose data if you want.
    I wonder if the compiler allocates the allignment setting or else what would such a structure's address be.
    Last edited by Quantum1024; 11-22-2005 at 12:26 PM.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    There's an FAQ entry on the subject.

    [edit]
    Here it is.
    [/edit]
    Last edited by dwks; 11-22-2005 at 12:52 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Code Ripper
    Join Date
    Jun 2004
    Posts
    30
    bikr692002,

    in windows, you can use WinExec() too

    jmgk

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    WinExec is 16-bit legacy and deprecated. Don't use it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Quote Originally Posted by Daved
    Ok, maybe it might "work" in some situations, but it is wrong. Besides, you could put 999 in there instead of NULL and it would be less typing and much closer to correct, so why would you use NULL?
    So then like if someone typed in a 14 character command it would only take 14 blocks and if someone typed 20 then it would take 20 blocks, at elast thats what i think, i'm a little new

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    That code is illegal. It will often lead to a crash (you are accessing memory that doesn't "belong" to you). It is also not smart to try and save space like that. It is rarely necessary, and of course having your program crash or having somebody hack your program to do bad things is much worse than a tiny amount of wasted memory.

    If you're concerned about the wasted memory, you could use the string class, which usually starts with a small amount of allocated memory and then grows as needed based on the size of the data entered by the user.

  14. #14
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I want to exploit it myself though, in my schools network to gain admin access someway or to execute commands, well this is what i have so far
    Code:
    #include <windows.h>
    #include <iostream>
    
    int main()
    {
        char szPath[] ="C:\\WINDOWS\\SYSTEM32\\MSG.EXE";
        char CommandString[NULL];
        
        std::cout<<"Please enter command argument:";
        std::cin>>CommandString;
        
        PROCESS_INFORMATION pif;
        
        STARTUPINFO si;
        
        ZeroMemory(&si,sizeof(si));
        si.cb=sizeof(si);
        
        BOOL bRet=CreateProcess(
                            szPath,
                            CommandString,
                            NULL,
                            NULL,
                            FALSE,
                            0,
                            NULL,
                            NULL,
                            &si,
                            &pif);
        if (bRet==FALSE)
        {
            MessageBox(HWND_DESKTOP,"Unable to start program","Error",MB_OK);
            return 1;
        }
        
        CloseHandle(pif.hProcess);
        CloseHandle(pif.hThread);
        return 0;
    }
    thanks for the FAQ dwks but this isnt working for some reason

  15. #15
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by bikr692002
    I want to exploit it myself though ...
    thanks for the FAQ dwks but this isnt working for some reason
    If you had read and understood previous posts you would know why that program doesn't work. char CommandString[NULL]; is a character array of 0 length and any attempt to put something in that array will fail. Add this line and you will see how many bytes that character array has (which is 0)
    Code:
        std::cout << "sizeof(ComandString) = " << sizeof(CommandString) << std::endl;

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 12:04 PM
  2. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 06:56 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM
  5. Number system base M, print numbers N digits wide...
    By biterman in forum C Programming
    Replies: 12
    Last Post: 11-19-2001, 03:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21