Saj zawg zog yooj yim thiab muaj zog ntawm cov lus Visual Basic. NET, yog ib qho ntawm cov cuab yeej tsim tshwj xeeb rau kev tsim cov ntawv thov rau Microsoft. NET platform, tso cai rau koj siv tag nrho nws lub peev xwm. Tshwj xeeb, cov khoom siv ntawm System. Diagnostics namespace tso cai rau koj sib cuam tshuam nrog cov txheej txheem, cov cav xwm txheej, thiab cov chaw ua haujlwm tau zoo. Piv txwv li, koj tuaj yeem kaw ib qhov kev pab cuam los ntawm Visual Basic siv tus txheej txheem chav kawm.
Tsim nyog
Microsoft Visual Studio
Cov Lus Qhia
Kauj ruam 1
Import Cov Txheej Txheem, System. Diagnostics, thiab System. Threading namespaces. Ntxiv cov kab hauv qab no ntawm cov cai ua pib ntawm tus qauv:
Cov Txheej Txheem Ntshuam
Cov Khoom Siv System. Diagnostics
Kev Siv Cov Txheej Txheem. Txhais
Qhov no tsuas yog rau kev yooj yim ntawm kev siv cov khoom siv txuam nrog cov npe no.
Kauj ruam 2
Tau txais cov ntaub ntawv ntawm cov txheej txheem yuav raug kaw. Siv cov kawm System. Diagnostics. Process chav kawm khoom plig. Tshaj tawm qhov sib txawv ntawm cov hoob kawm no:
Dim oProc Raws Li Txheej Txheem
Tom qab ntawd siv qee txoj hauv kev los nrhiav cov txheej txheem tsim nyog.
Kauj ruam 3
Yog tias qhov kev zov me nyuam, uas yuav tsum tau kaw yav tom ntej, yog tsim los ntawm daim ntawv thov raug tsim, tom qab ntawd tsuas yog khaws cov khoom xa rov qab los ntawm Kev Pib Siv thaum pib:
oProc = Txheej Txheem. Start ("app.exe")
Kauj ruam 4
Yog tias koj xav kaw cov txheej txheem nrog cov paub uas paub tus cim, siv txoj kev GetProcessById zoo li qub ntawm txheej txheem chav kawm kom tau txais qhov sib nug khoom:
oProc = Txheej Txheem. GetProcessById (nID)
Qhov twg nID yog tus lej cim ntawm cov txheej txheem.
Kauj ruam 5
Yog tias tsuas yog qee qhov ntawm cov cwj pwm ntawm cov hom phiaj paub, nrhiav nws. Tau txais cov npe ntawm cov txheej txheem uas khiav ntawm lub tshuab hauv zos ua cov khoom sib dhos ntawm cov txheej txheem chav. Siv cov GetProcesses (rov qab los ntawm txhua tus txheej txheem) lossis GetProcessesByName (tsuas yog cov txheej txheem nrog lub npe muab) cov hau kev:
Dim aoAllProcesses Raws Li Txheej Txheem () = Txheej Txheem. GetProcesses ()
Dim aoProcsByName Raws li Txheej Txheem () = Txheej Txheem. GetProcessesByName ("app.exe")
Sau cov khoom siv array siv ib lub voj:
Dim oProc Raws Li Txheej Txheem
Rau Txhua oProc Hauv aoAllProcesses
kev ua ntawm oProc
Ntxiv mus
Ntxees los ntawm cov khoom siv MainModule, MainWindowTitle, ProcessName, thiab lwm yam. nrhiav qhov khoom kwv yees.
Kauj Ruam 6
Sim ua kom tshem tawm txoj haujlwm los ntawm kev xa cov lus ze rau nws lub qhov rai tseem ceeb. Hu rau Txoj Haujlwm KawMainWindow ntawm cov khoom sib nug rau cov phiaj txheej txheem. Yog tias tsim nyog, tos rau daim ntawv thov kom tiav los ntawm kev hu rau WaitForExit, piv txwv:
oProc. CloseMainWindow ()
oProc. WaitForExit ().
Txoj kev no tsis tuaj yeem lav txog kev txiav tawm ntawm qhov kev zov me nyuam, vim tias lub qhov rooj kaw xov xwm feem ntau ua tiav thiab tuaj yeem tsis quav ntsej.
Kauj Ruam 7
Tos rau lub sijhawm luv luv tom qab hu rau CloseMainWindow txhawm rau paub meej tias qhov haujlwm tiav. Siv txoj kev pw tsaug zog hauv chav kawm Xov. Tom qab ntawv xyuas cov xwm txheej ntawm cov txheej txheem los ntawm kev kuaj cov cuab yeej ntawm HasExited thiab, yog tias nws tseem tsis tau ua tiav, hu rau Txoj Haujlwm tua:
Xov. Sleep (6000)
oProc. Rov Kho Dua Tshiab ()
Yog hais tias tsis oProc. HasExited Ces
oProc. Kov ()
Xaus Yog
Yog tias qhov xav tau, koj tuaj yeem xaiv cov xwm txheej ntawm cov txheej txheem hauv lub voj, muab cov sijhawm tawm mus rau cov neeg siv kom txiav tawm daim ntawv thov uas tsis khaws cov ntaub ntawv. Thiab tsuas yog tias koj pom zoo hu rau Kill.
Kauj ruam 8
Siv cov kev pab dawb nyob tom qab qhov program tas siv hom kaw:
oProc. Ko ()
Kauj Ruam 9
Txhawm rau zam kom tsis txhob muaj qhov yuam kev thaum lub sijhawm ua tiav daim ntawv thov, tso tag nrho cov program kaw algorithm hauv Try-Catch-End Sim block. Ua kom muaj kev saib xyuas txhua yam muaj txiaj ntsig nrog kev txheeb xyuas cov lus, yog tias tsim nyog