Programma niet sluitbaar maken

Status
Niet open voor verdere reacties.

luck7

Gebruiker
Lid geworden
10 feb 2009
Berichten
791
hallo,

ik wil er graag voor zorgen dat mijn programma niet kan worden beëindigd. dan heb ik het niet over de rode knop rechts bovenin in, maar via de taskmanager. dus alleen nog via processtructuur beëindigen.
weet iemand hoe ik dat kan regelen?

bedankt!

Luck
 
maar dan kan het toch helemaal niet meer beëindigd worden?
 
op school draait er op de achtergrond een proces, dat is wel zichtbaar, maar als je het beëindigt (onder processen) dan start het zeg maar opnieuw. alleen als je de processtructuur beëindigd, dan sluit het helemaal af.
dat wil ik ook (:
 
Probeer het eens zo (gevonden op het internet):

Het gebruikt een timer en een listview

Code:
Public Class Form1
    Const WM_COMMAND As Int32 = &H111
    Const MF_ENABLED As Int32 = &H0
    Const MF_GRAYED As Int32 = &H1
    Const LVM_FIRST As Int32 = &H1000
    Const LVM_DELETEITEM As Int32 = (LVM_FIRST + 8)
    Const LVM_SORTITEMS As Int32 = (LVM_FIRST + 48)
    Private Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
    Private Declare Function apiFindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
    Private Declare Function apiEnableWindow Lib "user32" Alias "EnableWindow" (ByVal hwnd As Int32, ByVal fEnable As Int32) As Boolean
    Private Declare Function apiGetMenu Lib "user32" Alias "GetMenu" (ByVal hwnd As Int32) As Int32
    Private Declare Function apiGetSubMenu Lib "user32" Alias "GetSubMenu" (ByVal hMenu As Int32, ByVal nPos As Int32) As Int32
    Private Declare Function apiGetMenuItemID Lib "user32" Alias "GetMenuItemID" (ByVal hMenu As Int32, ByVal nPos As Int32) As Int32
    Private Declare Function apiEnableMenuItem Lib "user32" Alias "EnableMenuItem" (ByVal hMenu As Int32, ByVal wIDEnableItem As Int32, ByVal wEnable As Int32) As Int32
    Private Declare Function apiSendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
    Private Declare Function apiGetDesktopWindow Lib "user32" Alias "GetDesktopWindow" () As Int32
    Private Declare Function apiLockWindowUpdate Lib "user32" Alias "LockWindowUpdate" (ByVal hwndLock As Int32) As Int32

    Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '  Me.Text = pName 'Set form name to match process name given
        Me.ShowInTaskbar = False 'hide application from taskbar
        Timer1.Interval = 700 'Set to start fast
        Timer1.Enabled = True 'Actually start the timer
        ListView1.View = View.Details
        ListView1.Columns.Add("Process name", -2, HorizontalAlignment.Left)
        ListView1.Sorting = SortOrder.Ascending 'So that the list view automatically sorts the entries for us.
        'Me.Hide()  'uncomment when ready to terminate this program elsehow.
    End Sub
    Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        HideProcess("", False)
    End Sub
    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        HideProcess("explorer", True)
    End Sub


    Private Function HideProcess(ByVal pName As String, Optional ByVal pHide As Boolean = True)
        On Error Resume Next
        Dim lhWndParent As Int32 = apiFindWindow(Nothing, "Windows Task Manager") 'get handle to the task manager
        Dim lhWndDialog As Int32 = 0
        Dim lhWndProcessList As Int32 = 0
        Dim lhWndProcessHeader As Int32 = 0
        Dim hMenu As Int32 = apiGetMenu(lhWndParent) 'get it's menu handle
        Dim hSubMenu As Int32 = apiGetSubMenu(hMenu, 2) 'get it's submenu handle for "View"
        Dim hSubSubMenu As Int32 = apiGetSubMenu(hSubMenu, 1) 'get it;s subsub menu handle for "update speed"
        Dim hId1 As Int32 = apiGetMenuItemID(hSubMenu, 0) 'Get id for "refresh now" item
        Dim hId2 As Int32 = apiGetMenuItemID(hSubSubMenu, 0) 'Get id for "high update speed" item
        Dim hId3 As Int32 = apiGetMenuItemID(hSubSubMenu, 1) 'Get id for "normal update speed" item
        Dim hId4 As Int32 = apiGetMenuItemID(hSubSubMenu, 2) 'Get id for "low update speed" item
        Dim hId5 As Int32 = apiGetMenuItemID(hSubSubMenu, 3) 'Get id for "paused update speed" item
        If pHide = True Then
            Dim ProcessItemCount, ProcessItemIndex As Int32
            Dim itemString As String, p As New Process, Processes() As Process

            For i As Int32 = 1 To 7 'Loop through all seven child windows, for handles to the listviews, buttons, and header
                lhWndDialog = apiFindWindowEx(lhWndParent, lhWndDialog, Nothing, Nothing)
                If lhWndProcessList = 0 Then lhWndProcessList = apiFindWindowEx(lhWndDialog, 0, "SysListView32", "Processes")
                If lhWndProcessHeader = 0 Then lhWndProcessHeader = apiFindWindowEx(lhWndProcessList, 0, "SysHeader32", Nothing)
            Next

            apiSendMessage(lhWndParent, WM_COMMAND, hId5, 0) 'Click "paused update speed", so we can do it for the taskmgr

            apiEnableMenuItem(hMenu, hId1, MF_GRAYED) 'disable refresh now item
            apiEnableMenuItem(hMenu, hId2, MF_GRAYED) 'disable high update speed
            apiEnableMenuItem(hMenu, hId3, MF_GRAYED) 'disable normal update speed
            apiEnableMenuItem(hMenu, hId4, MF_GRAYED) 'disable low update speed
            apiEnableMenuItem(hMenu, hId5, MF_GRAYED) 'disable paused update speed

            apiEnableWindow(lhWndProcessHeader, 0) 'Disable process header, so it cannot be resorted by user

            If Me.ListView1.Items.Count > 0 Then Me.ListView1.Items.Clear() 'clear any old data that was on the list

            Processes = Process.GetProcesses() 'Get processes

            For Each p In Processes  'Count processes, and add them to the listview.
                ProcessItemCount += 1
                If p.ProcessName.ToString = "Idle" Then
                    With Me.ListView1.Items.Add("System Idle Process")
                    End With
                Else
                    With Me.ListView1.Items.Add(p.ProcessName.ToString)
                    End With
                End If
            Next p

            'Look for, the index of the process matching the string name of our caption then
            For z As Int32 = 0 To ProcessItemCount - 1
                itemString = ListView1.Items.Item(z).Text.ToString()
                If itemString = pName Then ProcessItemIndex = z
            Next

            apiLockWindowUpdate(lhWndProcessList) 'Lock the window from updating, to reduce flashing.
            apiSendMessage(lhWndParent, WM_COMMAND, hId1, 0) 'AutoClick refresh to update, then immediately sort and delete. 
            apiSendMessage(lhWndProcessList, LVM_SORTITEMS, 0, Nothing) ' Sort process items alphabetically
            apiSendMessage(lhWndProcessList, LVM_DELETEITEM, ProcessItemIndex, 0) 'Delete the  process, 
            apiLockWindowUpdate(False) 'unlock that window

            If lhWndParent = 0 Then
                If Timer1.Interval <> 800 Then Timer1.Interval = 800 'Set to react fast while task manager is closed.
            Else
                If Timer1.Interval <> 2500 Then Timer1.Interval = 2500 'Set to a normal looking update speed, while the task manager remains open.
            End If
        Else
            Timer1.Enabled = False 'kill the timer
            For i As Int32 = 1 To 7
                lhWndDialog = apiFindWindowEx(lhWndParent, lhWndDialog, Nothing, Nothing)
                If lhWndProcessList = 0 Then lhWndProcessList = apiFindWindowEx(lhWndDialog, 0, "SysListView32", "Processes")
                If lhWndProcessHeader = 0 Then lhWndProcessHeader = apiFindWindowEx(lhWndProcessList, 0, "SysHeader32", Nothing)
            Next
            apiEnableMenuItem(hMenu, hId1, MF_ENABLED) 're-enable refresh now
            apiEnableMenuItem(hMenu, hId2, MF_ENABLED) 're-enable high update speed
            apiEnableMenuItem(hMenu, hId3, MF_ENABLED) 're-enable normal update speed
            apiEnableMenuItem(hMenu, hId4, MF_ENABLED) 're-enable low update speed
            apiEnableMenuItem(hMenu, hId5, MF_ENABLED) 're-enable paused update speed
            apiSendMessage(lhWndParent, WM_COMMAND, hId3, 0) 'click normal update speed
            apiSendMessage(lhWndParent, WM_COMMAND, hId1, 0) 'click refresh now
            apiEnableWindow(lhWndProcessHeader, 1) 'Enable process header
        End If
        Return True
    End Function



End Class

[edit]
het kan ook simpeler, een 2de programma maken dat het eerste programma herstart zodra het wordt afgesloten. (doen ze bij ons op het werk)
 
Laatst bewerkt:
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan