Results 1 to 8 of 8

Thread: run command from c#.net windows application

  1. #1

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    run command from c#.net windows application

    hi guyz!!! i have a question. How can I run a windows command like 'Runas','dir','net user', etc...using c# .net windows application. thanks in advance!!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: run command from c#.net windows application

    Code:
    // Run a command prompt with your desired command.
    Process.Start("cmd", "your command here");
    You should look up the Process class, the Process.Start method and the ProcessStartInfo class for more information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: run command from c#.net windows application

    THanks a bunch!!!

  4. #4
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: run command from c#.net windows application

    Also, you can use the /C switch of cmd.exe to exit upon completion..

    Code:
    Process.Start("cmd", "/C " + "your command here");
    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: run command from c#.net windows application

    You don't need the "cmd" (in my experience) and you can also stick all your args in with the program name in one string too.

    Process.Start(@"rasdial.exe nokia123 /disconnect");
    I don't live here any more.

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: run command from c#.net windows application

    Also if you use a ProcessStartInfo object then you can tell it to CreateNoWindow, so you don't get any annoying flashing cmd prompts spoining your nice GUI
    I don't live here any more.

  7. #7
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: run command from c#.net windows application

    Quote Originally Posted by wossname
    You don't need the "cmd" (in my experience) and you can also stick all your args in with the program name in one string too.

    Process.Start(@"rasdial.exe nokia123 /disconnect");
    Well Internal commands like DIR, Type, Prompt, Copy, etc will need CMD (as per my experience ).
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  8. #8
    New Member tracernet_v2's Avatar
    Join Date
    Aug 2006
    Posts
    5

    Re: run command from c#.net windows application

    Quote Originally Posted by Shuja Ali
    Well Internal commands like DIR, Type, Prompt, Copy, etc will need CMD (as per my experience ).
    Ok, but I think you can just use the .NET framework classes intended for them instead of using the CMD...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width