في البرامج العادية استطيع منع تشغيل البرنامج مرة اخرى اذا كان مشغل بالاصل وهذا باستخدام الكود التالي
Public Function CheckApplicationRun() As Boolean
Dim Diag As New Diagnostics.Process
Dim Pr As Process
Dim MyDate As DateTime
Dim MyCount As Int32 = 0
Dim MyProcess() As Diagnostics.Process
Dim MyFile As IO.FileInfo
Dim Tbl As New DataTable("MyProcess")
Dim Rec As DataRow
Dim Col1 As New DataColumn("PrId")
Dim Col2 As New DataColumn("PrDate")
Dim i As Integer = 0
Col1.DataType = System.Type.GetType("System.Int32")
Tbl.Columns.Add(Col1)
Col2.DataType = System.Type.GetType("System.DateTime")
Tbl.Columns.Add(Col2)
'For Each Pr In Diag.GetProcesses
'MsgBox(Pr.ProcessName)
' If Pr.ProcessName.ToUpper() = My.Application.Info.ProductName.ToUpper() Then
' 'MsgBox(Pr.StartTime)
' 'Pr.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
' Else
' End If
'Next
MyFile = New IO.FileInfo(Application.ExecutablePath)
Dim MyF As String
MyF = MyFile.Name.Replace(MyFile.Extension, "")
'MsgBox(MyFile.Name)
MyProcess = Diag.GetProcessesByName(MyF)
MyCount = MyProcess.Length
'MsgBox(MyCount.ToString())
MyCount = 0
For Each Pr In MyProcess
Rec = Tbl.NewRow
Rec("PrId") = Pr.Id
Rec("PrDate") = Pr.StartTime
Tbl.Rows.Add(Rec)
Next
Dim RRFound() As DataRow = Tbl.Select("1=1", "PrDate")
If RRFound.Length > 1 Then
Rec = RRFound(0)
Pr = Process.GetProcessById(Rec("PrId"))
Pr.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
ShowMsg("النظام لايزال يعمل ....", 2, MessageBoxButtons.OK, MySounds.ApplicationStillWorking)
End If
For i = 1 To RRFound.Length - 1
Rec = RRFound(1)
Try
Pr = Process.GetProcessById(Rec("PrId"))
Pr.Kill()
Catch ex As Exception
End Try
Rec.Delete()
Next
If RRFound.Length > 0 Then
Rec = RRFound(0)
Pr = Process.GetProcessById(Rec("PrId"))
Pr.StartInfo.WindowStyle = ProcessWindowStyle.Maximized
End If
'If MyCount = 0 Then
' MyDate = Pr.StartTime
'Else
' If MyDate <= Pr.StartTime Then
' Pr.Kill()
' Else
' End If
'End If
'MyProcess(0).StartInfo.WindowStyle = ProcessWindowStyle.Normal
'MyProcess(0).StartInfo.WindowStyle = ProcessWindowStyle.Maximized
'MyProcess(0).Refresh()
'MyCount += 1
'Next
End Function
ولكن عندما نقلت الكود لبرنامج pc pocket
اعطى خطأ
الرجاء اعطائي الكود الصحيح لعمل هذه الدالة على جهاز PC pocket