run command prompt commands from within a C# application

preview_player
Показать описание
run command prompt commands from within a C# application
-------------
May be you like this
--------------
Our channel:

KnockoutJs Playlist:
Wcf playlist :

Wcf restful playlist :

c# playlist:

google maps playlist:

Рекомендации по теме
Комментарии
Автор

The script for you guys :)


Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
= true;
= true;
= true;
= false;
process.Start();



svengroen
Автор

Thank you su much. It is brilliant video. All the other answers on Stack overflow or others are either false or incomplete. You have great explanatory skills!

dariorud
Автор

Thankyou, this was perfect for me as I needed to launch a file with arguments both before and after teh executable

gigajoules
Автор

This makes my research to end on my problem. Thank you man.

prabakarandhanavel
Автор

I got error like ->> 'Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.'


any solution please

joierocker
Автор

This works like a CHARM ! thanks a lot savior :D

LetCode
Автор

How do you run this from Specflow [BeforeScenario] block?

Calocarv
Автор

Thank you so much bro amazing video :))))

yashpreetbathla
Автор

Thank you so much it worked very well :D!!

rhysxh
Автор

Thank you you have saved me, I had been working for the last 2 days, I was having issues while running PSEXEC commands, it was running smoothly in CMD but no through C#. Seems the problem was that I was sending arguments as process.startinfo.arguments = "command" but now after using it worked.

In case anyone interested how to restart IIS, AppPool, Services and get Head/Tail of files from Remote Directory

public static void PSExec_Method()
{
try
{

string userName = @"ABC";
string password = "ABC";
string remoteMachine = "IP";
string command = string.Empty;
string fullcommand = string.Empty;

//string operation = "start";
//string apppoolname = "CCIS";
//string command = " + operation + " apppool /apppool.name:\"" + apppoolname + "\"";

//command = @"powershell Get-Content C:\tmp\SDDump\Infolog.csv -Head 5";
//command = @"whoami";
//command = "%computername%";
//command = "powershell Get-PSDrive C";


string PSPath = @"C:\PSTools\PsExec.exe";
//string fullcommand = PSPath + " -u " + userName + " -p " + password + " \\\\" + remoteMachine + " -h cmd.exe /c " + command;
///c powershell Get-Content C:\tmp\SDDump\test.csv -Head 5

//fullcommand = "ipconfig";


System.Diagnostics.Process process = new
process.StartInfo.WindowStyle =
= false;
= true;
= true;
= true;

process.StartInfo.FileName = "cmd.exe";
//process.StartInfo.Arguments = fullcommand;
process.Start();





process.WaitForExit();
Console.WriteLine("Again ?");

}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}

faisalu
Автор

I have doubt in this can anyone help me

krishanthsekaran
Автор

Is this possible in windows form? Like clicking a button will execute a command in cmd

rokiedebian
Автор

can you show me how to write multiple commands please

mrmakinist
Автор

How to execute multiple commands in same process

AadhyaCreativeWorks
Автор

can u say how to write "kill process" using port number in c#

tanojsai
Автор

thanks for the inputs but its not working for my code.
i have one .exe file so i gave Filename as total path for .exe
standardInput.WriteLine("*"); i am giving in the place of *.
my problem is i am getting the value after running the exe not the value after running the command.
hope u understand my prblm..
will wait for ur reply

annapurnavarada
Автор

Is this possible from any Web api Controller ?

md.akterhossain
Автор

two parameters? For example: ipconfig /all. ipconfig=first parameter and /all= second parameter

aeamongol
Автор

could you tell how to run command prompt as administrator from within the application?

shivarajas
Автор

is this windows form or is it console? cuz this code is not working at

davidwoods
visit shbcf.ru