How to pass variable to windows system?

This is a discussion on How to pass variable to windows system? within the Windows Programming forums, part of the Platform Specific Boards category; Code: #include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { char comp_name [20]; system("cls"); cout << ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    8

    How to pass variable to windows system?

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        char comp_name [20];
        system("cls");
        cout << "Please enter computer name: " ;
        cin >> comp_name;
        system("del \\comp_name\c$\WINNT\MS\SMS\CORE\BIN\SlowNet.exe");
        return 0;
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,677
    Code:
        char command_fmt[] = "del \\\\%s\\c$\\WINNT\\MS\\SMS\\CORE\\BIN\\SlowNet.exe";
        char command[512];
        sprintf(command, command_fmt, "MyComputerName");
        cout << command << endl;
    gg

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    8
    Originally posted by Codeplug
    Code:
        char command_fmt[] = "del \\\\%s\\c$\\WINNT\\MS\\SMS\\CORE\\BIN\\SlowNet.exe";
        char command[512];
        sprintf(command, command_fmt, "MyComputerName");
        cout << command << endl;
    gg
    Thanks for your help. I got much further than before but it seems it would only ECHO and not running the command line.
    Any idea?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,674
    > and not running the command line.
    Well we kinda hoped that you would figure out that

    system( command );

    would be the obvious thing to put in the code to replace your attempt.

    The cout is merely there to make sure everything is alright before you do something really dumb like "del c:"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    8
    Originally posted by Salem
    > and not running the command line.
    Well we kinda hoped that you would figure out that

    system( command );

    would be the obvious thing to put in the code to replace your attempt.

    The cout is merely there to make sure everything is alright before you do something really dumb like "del c:"
    Oh!!! Thanks!!!!

    Of course I've tried
    system ("command");
    and it didn't work. Since I am really new to C++, please forgive my igrnorance.
    Thank you very much everyone!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. system call variable
    By bradleyd in forum C Programming
    Replies: 5
    Last Post: 05-09-2007, 06:15 PM
  2. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 09:00 AM
  3. Windows file system
    By sterling in forum Windows Programming
    Replies: 1
    Last Post: 03-04-2003, 04:20 PM
  4. I'm programming an opration system like as windows or linux.
    By hadizadeh in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-20-2001, 03:35 PM
  5. Need help
    By awkeller in forum C Programming
    Replies: 2
    Last Post: 12-09-2001, 02:02 PM

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