using System;
+using System.IO;
using System.Management;
// ##### 유기중.... 언젠가 해야지
}
return result;
}
- public static void test()
- {
- }
// 장치 비활성화
public static void DisableDevice(string where)
{
+ string textFile = @"c:\temp\newton-cn_log.txt";
+
string deviceId = getDeviceId(where);
try
{
foreach (ManagementObject device in searcher.Get())
{
ManagementBaseObject outParams = device.InvokeMethod("Disable", null, null);
+ if (!System.IO.File.Exists(textFile))
+ {
+ using (StreamWriter sw = File.CreateText(textFile))
+ {
+ sw.WriteLine($"장치 {deviceId}가 비활성화되었습니다.");
+ }
+ }
+ else
+ {
+ using (StreamWriter sw= File.AppendText(textFile))
+ {
+ sw.WriteLine($"장치 {deviceId}가 비활성화되었습니다.");
+ }
+ }
Console.WriteLine($"장치 {deviceId}가 비활성화되었습니다.");
}
}
catch (Exception ex)
{
+ if (!System.IO.File.Exists(textFile))
+ {
+ if (!System.IO.File.Exists(textFile))
+ {
+ using (StreamWriter sw = File.CreateText(textFile))
+ {
+ sw.WriteLine($"USB 장치 정보를 가져오는 중 오류 발생: {ex.Message}");
+ }
+ }
+ else
+ {
+ using (StreamWriter sw = File.AppendText(textFile))
+ {
+ sw.WriteLine($"USB 장치 정보를 가져오는 중 오류 발생: {ex.Message}");
+ }
+ }
+ }
Console.WriteLine($"USB 장치 정보를 가져오는 중 오류 발생: {ex.Message}");
}
}
// 장치 활성화
public static void EnableDevice(string where)
{
+ string textFile = @"c:\temp\newton-cn_log.txt";
string deviceId = getDeviceId(where);
try
{
foreach (ManagementObject device in searcher.Get())
{
ManagementBaseObject outParams = device.InvokeMethod("Enable", null, null);
+ if (!System.IO.File.Exists(textFile))
+ {
+ using (StreamWriter sw = File.CreateText(textFile))
+ {
+ sw.WriteLine($"장치 {deviceId}가 활성화되었습니다.");
+ }
+ }
+ else
+ {
+ using (StreamWriter sw = File.AppendText(textFile))
+ {
+ sw.WriteLine($"장치 {deviceId}가 활성화되었습니다.");
+ }
+ }
Console.WriteLine($"장치 {deviceId}가 활성화되었습니다.");
}
}
catch (Exception ex)
{
+ if (!System.IO.File.Exists(textFile))
+ {
+ using (StreamWriter sw = File.CreateText(textFile))
+ {
+ sw.WriteLine($"USB 장치 정보를 가져오는 중 오류 발생: {ex.Message}");
+ }
+ }
+ else
+ {
+ using (StreamWriter sw = File.AppendText(textFile))
+ {
+ sw.WriteLine($"USB 장치 정보를 가져오는 중 오류 발생: {ex.Message}");
+ }
+ }
Console.WriteLine($"USB 장치 정보를 가져오는 중 오류 발생: {ex.Message}");
}