回答編集履歴

1

修正

2016/11/12 05:23

投稿

MasahikoHirata
MasahikoHirata

スコア3747

test CHANGED
@@ -1,3 +1,69 @@
1
1
  参考までに。
2
2
 
3
3
  [WinUsb_ResetPipe function](https://msdn.microsoft.com/en-us/library/windows/hardware/ff540300(v=vs.85).aspx)
4
+
5
+
6
+
7
+ 質問の内容からC#やc++から`devcon.exe`を使いたいと判断して、その方法を考えました。
8
+
9
+ ```C#
10
+
11
+ //Processオブジェクトを作成
12
+
13
+ System.Diagnostics.Process p = new System.Diagnostics.Process();
14
+
15
+
16
+
17
+ //ComSpec(cmd.exe)のパスを取得して、FileNameプロパティに指定
18
+
19
+ p.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
20
+
21
+ //出力を読み取れるようにする
22
+
23
+ p.StartInfo.UseShellExecute = false;
24
+
25
+ p.StartInfo.RedirectStandardOutput = true;
26
+
27
+ p.StartInfo.RedirectStandardInput = false;
28
+
29
+ //ウィンドウを表示しないようにする
30
+
31
+ p.StartInfo.CreateNoWindow = true;
32
+
33
+ //コマンドラインを指定("/c"は実行後閉じるために必要)
34
+
35
+ p.StartInfo.Arguments = @"/c devcon.exe reboot ";
36
+
37
+
38
+
39
+ //起動
40
+
41
+ p.Start();
42
+
43
+
44
+
45
+ //出力を読み取る
46
+
47
+ string results = p.StandardOutput.ReadToEnd();
48
+
49
+
50
+
51
+ //プロセス終了まで待機する
52
+
53
+ //WaitForExitはReadToEndの後である必要がある
54
+
55
+ //(親プロセス、子プロセスでブロック防止のため)
56
+
57
+ p.WaitForExit();
58
+
59
+ p.Close();
60
+
61
+
62
+
63
+ //出力された結果を表示
64
+
65
+ Console.WriteLine(results);
66
+
67
+ ```
68
+
69
+ これだとどうでしょう?