在一个C#程序中,怎样写满足某条件,就调用本地的一个VBscript文件,就是直接运行,代码怎么写?
急求,拜托各位高手了,快啊啊
C#调用本地程序
答案:2 悬赏:60 手机版
解决时间 2021-02-09 13:53
- 提问者网友:凉末
- 2021-02-08 22:28
最佳答案
- 五星知识达人网友:街头电车
- 2021-02-08 23:55
01 using System;
02 using System.Collections.Generic;
03 using System.Linq;
04 using System.Text;
05 using System.Threading;
06 using System.Diagnostics;
07
08 namespace ConsoleApplication1
09 {
10 class command
11 {
12 public static string startcmd(string command)
13 {
14 string output = "";
15 try
16 {
17
18 Process cmd = new Process();
19 cmd.StartInfo.FileName = command;
20
21 cmd.StartInfo.UseShellExecute = false;
22
23 cmd.StartInfo.RedirectStandardInput = true;
24 cmd.StartInfo.RedirectStandardOutput = true;
25
26 cmd.StartInfo.CreateNoWindow = true;
27 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
28
29 cmd.Start();
30
31 output = cmd.StandardOutput.ReadToEnd();
32 Console.WriteLine(output);
33 cmd.WaitForExit();
34 cmd.Close();
35 }
36 catch (Exception e)
37 {
38 Console.WriteLine(e);
39 }
40 return output;
41 }
42 public static string startcmd(string command, string argument)
43 {
44 string output = "";
45 try
46 {
47 Process cmd = new Process();
48
49 cmd.StartInfo.FileName = command;
50 cmd.StartInfo.Arguments = argument;
51
52 cmd.StartInfo.UseShellExecute = false;
53
54 cmd.StartInfo.RedirectStandardInput = true;
55 cmd.StartInfo.RedirectStandardOutput = true;
56
57 cmd.StartInfo.CreateNoWindow = true;
58 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
59
60 cmd.Start();
61
62 output = cmd.StandardOutput.ReadToEnd();
63 Console.WriteLine(output);
64 cmd.WaitForExit();
65 cmd.Close();
66 }
67 catch (Exception e)
68 {
69 Console.WriteLine(e);
70 }
71 return output;
72 }
73 }
74 }
02 using System.Collections.Generic;
03 using System.Linq;
04 using System.Text;
05 using System.Threading;
06 using System.Diagnostics;
07
08 namespace ConsoleApplication1
09 {
10 class command
11 {
12 public static string startcmd(string command)
13 {
14 string output = "";
15 try
16 {
17
18 Process cmd = new Process();
19 cmd.StartInfo.FileName = command;
20
21 cmd.StartInfo.UseShellExecute = false;
22
23 cmd.StartInfo.RedirectStandardInput = true;
24 cmd.StartInfo.RedirectStandardOutput = true;
25
26 cmd.StartInfo.CreateNoWindow = true;
27 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
28
29 cmd.Start();
30
31 output = cmd.StandardOutput.ReadToEnd();
32 Console.WriteLine(output);
33 cmd.WaitForExit();
34 cmd.Close();
35 }
36 catch (Exception e)
37 {
38 Console.WriteLine(e);
39 }
40 return output;
41 }
42 public static string startcmd(string command, string argument)
43 {
44 string output = "";
45 try
46 {
47 Process cmd = new Process();
48
49 cmd.StartInfo.FileName = command;
50 cmd.StartInfo.Arguments = argument;
51
52 cmd.StartInfo.UseShellExecute = false;
53
54 cmd.StartInfo.RedirectStandardInput = true;
55 cmd.StartInfo.RedirectStandardOutput = true;
56
57 cmd.StartInfo.CreateNoWindow = true;
58 cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
59
60 cmd.Start();
61
62 output = cmd.StandardOutput.ReadToEnd();
63 Console.WriteLine(output);
64 cmd.WaitForExit();
65 cmd.Close();
66 }
67 catch (Exception e)
68 {
69 Console.WriteLine(e);
70 }
71 return output;
72 }
73 }
74 }
全部回答
- 1楼网友:几近狂妄
- 2021-02-09 00:32
去掉前面的void......
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯