请问如何实现监督功能 ,就是说每隔一定时间进行一次检查 ,如果有与本程序无关的程序运行便将其窗口强行关闭

解决方案 »

  1.   

    这个好办呀
    定时检查可以用timer控件实现
    窗口可以用FindWindows这个API枚举
    对于每一个找到的窗口, 判断它为无关时就关闭它
      

  2.   

    窗体上放一个timer控件  
     
    Private  Declare  Function  PostMessage  Lib  "user32"  Alias  "PostMessageA"  (ByVal  hwnd  As  Long,  ByVal  wMsg  As  Long,  ByVal  wParam  As  Long,  ByVal  lParam  As  Long)  As  Long  
    Private  Declare  Function  FindWindow  Lib  "user32"  Alias  "FindWindowA"  (ByVal  lpClassName  As  String,  ByVal  lpWindowName  As  String)  As  Long  
    Private  Const  WM_CLOSE  =  &H10  
    Private  Const  xxx  As  String  =  "我的电脑"  
     
    Private  Sub  Form_Load()  
    Timer1.Interval  =  2000  
    End  Sub  
     
    Private  Sub  Timer1_Timer()  
    Dim  hWindow  As  Long  
    hWindow  =  FindWindow(vbNullString,  xxx)  
    If  hWindow  Then  PostMessage  hWindow,  WM_CLOSE,  0&,  0&  
    End  Sub  
     
    程序运行后,打开我的电脑,我的电脑会被自动关闭,你把“我的电脑”换成你想关闭的窗口标题就行了
      

  3.   

    vb.net:For Each pro As Process in Process.GetProcesses()
          if pro.Name <> "自己窗体" and pro.Name <> "System" and pro.Name <> "Explorer.exe" then pro.kill()     
    Next