473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem with executing cmd commands in C#

134 100+
Hello all,

I've got the code as shown below:
Expand|Select|Wrap|Line Numbers
  1. Process process = new Process();
  2.             ProcessStartInfo startInfo = new ProcessStartInfo();
  3.             startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  4.             startInfo.FileName = "cmd.exe";
  5.             startInfo.Arguments = "shutdown /r";
  6.             process.StartInfo = startInfo;
  7.             Process.Start(startInfo);
But somehow, it will start up cmd.exe but it won't execute the command shown at the startInfo.Arguments.
Anyone who can help me out?

Thanks in advance,

Michael
Jan 4 '13 #1

✓ answered by Jwalker

try this
Expand|Select|Wrap|Line Numbers
  1.  
  2. Process process = new Process();
  3. ProcessStartInfo startInfo = new ProcessStartInfo();
  4. startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  5. startInfo.FileName = "cmd.exe";
  6. startInfo.Arguments = "/C shutdown /r";
  7. process.StartInfo = startInfo;
  8. Process.Start(startInfo);
  9.  
pass "/C".

bye.

2 7537
try this
Expand|Select|Wrap|Line Numbers
  1.  
  2. Process process = new Process();
  3. ProcessStartInfo startInfo = new ProcessStartInfo();
  4. startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  5. startInfo.FileName = "cmd.exe";
  6. startInfo.Arguments = "/C shutdown /r";
  7. process.StartInfo = startInfo;
  8. Process.Start(startInfo);
  9.  
pass "/C".

bye.
Jan 4 '13 #2
michaeldebruin
134 100+
Thanks it solved the problem, I have no idea why but it's solved now. So Thanks a lot
Jan 4 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: n.o. | last post by:
Hi! Can you please help me with the following problem? My application calls (rval, outp) = commands.getstatusoutput("...") inside a pygtk timer.
0
by: tukaram.thatikonda | last post by:
Hi Guys, I have written a small windows application in VB.Net to test ADO.Net performance while executing long running query. The query works most of the time but fails sometime. I am trying...
20
by: Neil Robbins | last post by:
I am trying to execute a make table query in my vb.net program. The db that I am accessing is an Access 2000 format db. The SQL code that I am using has been cut and pasted from the SQL View having...
0
by: knowthediff | last post by:
Hello, I have a VS 2005 windows form app that I am creating. It uses Async socket to telnet which sends and receives commands. Everything seems to be working fine until I attempt to process a...
0
by: blueblueblue | last post by:
Hi, I am trying to execute my dts package from sql using command shell as exec master..xp_cmdshell 'dtsrun /Sfiutopiadb /Usa /P /NBulktest' The package works perfectly in enterprise...
10
by: olafilink | last post by:
Hello, we're running an Win2003server with IIS6 and PHP4 in fastCGI config. When i try to use system() command to execute ffmpeg.exe it works ok when i run the PHP script from the commandline on...
1
by: natsran | last post by:
Hi All, Is there any perl module which would help in executing commands remotely on a windows machine? For doing the same on unix machine, I found that we could use Net::Telnet module. But...
3
by: deepak | last post by:
Hi There, i am facing problems while executing the query using ADO.NET,the problem goes below: i am using ExecuteDataset(sqlTran, CommandType.Text, query) and my query is this SELECT * FROM...
0
vinoj
by: vinoj | last post by:
Hi All, These are the following things which i want to do:- 1. I will be taking the ipaddress, username and password from the user using cgi ffrom the browser. 2. Now i want...
2
by: Jorgen Bodde | last post by:
Hi all, This is slightly OT but it drives me nuts. Whenever I create a shortcut in the start menu (in Windows) of a python script, it will only execute it when the path where the script resides...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.