VB dual-Process Protection

Source: Internet
Author: User

Class Module

Const th32cs_snapheaplist = & H1
Const th32cs_snapprocess = & H2
Const th32cs_snapthread = & h4
Const th32cs_snapmodule = & H8
Const th32cs_snapall = (th32cs_snapheaplist or th32cs_snapprocess or th32cs_snapthread or th32cs_snapmodule)
Const th32cs_inherit = & h80000000
Const max_path as integer = 260
Private type processentry32
Dwsize as long
Cntusage as long
Th32processid as long
Th32defaultheapid as long
Th32moduleid as long
Cntthreads as long
Th32parentprocessid as long
Pcpriclassbase as long
Dwflags as long
Szexefile as string * max_path
End type
Private declare function createmedilhelp32snapshot lib "Kernel32" (byval lflags as long, byval lprocessid as long) as long
Private declare function process32first lib "Kernel32" (byval hsnapshot as long, uprocess as processentry32) as long
Private declare function process32next lib "Kernel32" (byval hsnapshot as long, uprocess as processentry32) as long
Private declare sub exitprocess lib "Kernel32" (byval uexitcode as long)
Private declare function getexitcodeprocess lib "Kernel32" (byval hprocess as long, lpexitcode as long) as long


Function exitproc (byval exefile as string) as Boolean
Exitproc = false
Dim hsnapshot as long, uprocess as processentry32
Hsnapshot = createconlhelp32snapshot (th32cs_snapall, 0 &)
Uprocess. dwsize = Len (uprocess)
R = process32first (hsnapshot, uprocess)
Do While R
If left $ (uprocess. szexefile, IIF (instr (1, uprocess. szexefile, CHR $ (0)> 0, instr (1, uprocess. szexefile, CHR $ (0)-1, 0) = exefile then
Exitproc = true
Exit do
End if
R = process32next (hsnapshot, uprocess)
End Function


Timer1_timer ()

If exitproc ("spchost.exe") = false then 'checks whether the spchost.exe process exists
'Msgbox "does not exist"
Shell app. Path + "/spchost.exe"
End if


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.