2007-03-10

Prohibit application execute repeatly

Dim sAppName As String = Process.GetCurrentProcess.ProcessName
Dim Procs() As Process
Dim proc As Process
Procs = Process.GetProcesses()
Dim count As Integer = 0
For Each proc In Procs
  If proc.ProcessName.ToString.Equals("程式名稱") Then
    count += 1
  End If
Next proc
If count > 1 Then
  Application.Exit()
Else
  Application.Run(New 程式名稱())
End If

2007-03-01

找出windows己安裝的軟體

Dim InstalledApp As Object
Dim CurrentApp As Object  
   
 Dim str As String = "Office"  
 Dim GotIT As Boolean  = false
 Try  
     p_objSet = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_Product")   
     For Each CurrentApp In InstalledApp   
        If CurrentApp.name.ToString.IndexOf(str) >= 0 Then  
            GotIT = True  
            Exit For  
        End If  
     Next  
 Catch e As Exception   
     MessageBox.Show("WMI Exception" & vbcrlf & e.Message)   
 End Try