2009-12-10 26 views
6

Tôi đang viết một ứng dụng C# và nó lấy tệp làm đối số, tôi đã thêm nó vào trình đơn ngữ cảnh trình bao với mã được liệt kê bên dưới;Lấy nhiều tệp (đối số) từ trình đơn ngữ cảnh của Windows shell trên C#

if (((CheckBox)sender).CheckState == CheckState.Checked) 
      { 
       RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes\\*\\shell\\" + KEY_NAME + "\\command"); 

       if (key == null) 
       { 
        key = Registry.CurrentUser.CreateSubKey("Software\\Classes\\*\\shell\\" + KEY_NAME + "\\command"); 
        key.SetValue("", Application.ExecutablePath + " \"%1\""); 
       } 
      } 
      else if (((CheckBox)sender).CheckState == CheckState.Unchecked) 
      { 
       RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Classes\\*\\shell\\" + KEY_NAME); 

       if (key != null) 
       { 
        Registry.CurrentUser.DeleteSubKeyTree("Software\\Classes\\*\\shell\\" + KEY_NAME); 
       } 

Nó hoạt động tốt, nhưng nếu tôi chọn nhiều tệp, nhiều lần chạy ứng dụng. ví dụ nếu tôi chọn 5 tệp 5 ứng dụng đang mở, làm thế nào tôi có thể sửa lỗi này?

Trả lời

Các vấn đề liên quan