How to pass variable to Windows System?

This is a discussion on How to pass variable to Windows System? within the C++ Programming forums, part of the General Programming 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;
    }
    How can I pass comp_name to Windows command?
    Thank you.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Just figure out a way to put comp_name into a c-string and then call the system function with that string...To make it simpler you could even use the std::string class, and then use the c_str() member function to return a const char*...Oh and use cstdlib instead of stdlib.h
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,157
    Any \ in any string must be \\
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

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