Thread: How to pass variable to Windows System?

  1. #1
    Registered User
    Join Date
    Jan 2004

    How to pass variable to Windows System?

    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    int main(int argc, char *argv[])
        char comp_name [20];
        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
    Seattle, WA
    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."

  3. #3
    Been here, done that.
    Join Date
    May 2003
    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, 10:00 AM
  3. Windows file system
    By sterling in forum Windows Programming
    Replies: 1
    Last Post: 03-04-2003, 05:20 PM
  4. I'm programming an opration system like as windows or linux.
    By hadizadeh in forum A Brief History of
    Replies: 7
    Last Post: 12-20-2001, 04:35 PM
  5. Need help
    By awkeller in forum C Programming
    Replies: 2
    Last Post: 12-09-2001, 03:02 PM