Sida Loo Sameeyo Adeeg Daaqadaha

Mararka qaarkood waxaad u baahan tahay app ama qoraal si aad u sii wadato haddii aad gashay kombayutarkaaga iyo haddii kale. Waxaa laga yaabaa inay tahay qoraalka PowerShell si loola socdo dekedaha(PowerShell script to monitor ports) ama server-ka shabakada martigelinaya bogga shabakadaada guriga(web server hosting a page on your home network) .

Ujeedadu waxay tahay in haddii aad rabto in hab, script, ama barnaamij uu socdo ilaa inta uu kumbiyuutarku ku jiro, waxaad u baahan doontaa inaad abuurto Adeeg Windows ah(Windows Service) .

Maxaan u baahanahay si aan u sameeyo adeega Windows?(What Do I Need to Create a Windows Service?)

Si aad u abuurto adeegga Windows gudaha (Windows)Windows 10 , waxaa jira shuruudo dhowr ah: 

  • Gelitaanka maamulka(Administrator) ee kombiyuutarka
  • Wax loo socodsiiyo adeeg ahaan ( PowerShell Script , barnaamij, iwm.)
  • Maamulaha Adeegga(Service Manager) aan Nuugista ahayn ( NSSM ) ayaa la rakibay

Waa maxay Maamulaha Adeegga Aan Nuugista ahayn?(What Is the Non-Sucking Service Manager?)

Haa, ma tuuri kartid magac sidaas oo kale ah adigoon sharaxin. Hubaal in magacu yahay nasiib darro, haddana waa sax. Maamulaha Adeegga(Service Manager) aan Nuugista lahayn ( NSSM ) ayaa lagu doodi karaa inuu yahay habka ugu fudud ee lagu abuuri karo adeegga Windows kaas oo ah mid aad loogu kalsoon yahay oo la isku halayn karo. Waxaa dheer, waa bilaash iyo Open Source Software (OSS).

NSSM waxaa loo isticmaali karaa Windows Command Prompt , ama interface user garaaf ahaan ( GUI ). Taas macnaheedu waa qof kasta wuu isticmaali karaa. NSSM waxaa loo isticmaali karaa nooc kasta oo Windows ah oo dib ugu laabanaya, oo ay ku jiraan, Windows 2000 . Waxaa jira 32-bit iyo 64-bit(32-bit and 64-bit) versions. Haddii aad isticmaalayso kombiyuutar 64-bit ah, isku day noocaas marka hore. Haddii ay shaqayn waydo, dib ugu laabo nooca 32-bit. 

Waxaad NSSM ka soo dejisan kartaa shabakada(download NSSM from the website) , NSSM ka xidhi kartaa Git(clone NSSM from Git) , ama ku rakib NSSM Chocolatey(install NSSM with Chocolatey) . Chocolatey waa maamulaha xirmada ee Windows(Chocolatey is a package manager for Windows) . Hababka rakibidda(Installation) way kala duwanaan doonaan iyadoo ku xidhan dariiqa aad marto. Fadlan(Please) la tasho tilmaamaha NSSM . Tusaale ahaan, waxaanu ka soo dejisanaynaa shabakada NSSM oo aanu ku rakibnay (NSSM)C:\WINDOWS\system32 .

Abuur Adeeg Daaqadaha leh NSSM(Create a Windows Service With NSSM)

Tusaalahan, waxaan ka abuuri doonaa adeeg ka baxsan qoraalka PowerShell(PowerShell script) si aan u galno celceliska culeyska CPU(CPU average load percentage)

  1. Nuqul ka samee oo u keydi qoraalkan sidii log-CPULoadPercentage.ps1 meel aysan u badneyn inuu galo qof kale. Isku day inaad abuurto tusaha C:/Scripts oo ku kaydi halkaa. Sidoo kale, samee gal qoraallada(Scripts) ah oo la yiraahdo Logs . Ogsoonow in dariiqa qoraalku yahay C:/Scripts/log-CPULoadPercentage.ps1 . Waxaad u baahan doontaa taas hadhow.

Fiiro gaar(Note) ah: Dhammaan sadarrada hoose oo ay raacdo calaamadda # waa faallooyin oo ma saameynayso qoraalka.

CLS #Optional. I like to use this to clear the terminal when testing.

#Make sure you have a folder called Logs in the same directory as this script
#The log is where the records will be stored.
Start-Transcript -Path "$PSScriptRoot\Logs\log-CPULoadPercentage-$(get-date -f yyyy-MM-dd).txt" -Append

#While loop keeps it running until manually stopped
While ($True){
     #Creates a timestamp to know when the measurement was taken
     $timeStamp = get-date -f yyyy-MM-h:mm:ss

     #Gets the average load percentage at that time, then waits 5 seconds to do it again.
     $cpuLoadPercent = Get-CimInstance win32_processor | Measure-Object -Property LoadPercentage -Average | Select-Object Average;Start-Sleep -Seconds 5

     #Isolates just the average so there isn't a weird @{Average=13} string
     $cpuLoadPercent = $cpuLoadPercent.Average

     #writes results to screen, or in this case to the log
     Write-Host "$timeStamp CPU Load Percentage $cpuLoadPercent"
}

Stop-Transcript
  1. Tan waxaa lagu samayn karaa midkood Windows Command Prompt ama PowerShell. U fur maamule ahaan(Open it as Administrator) .
  2. Geli amarka nssm ku rakib logCPUAvg(nssm install logCPUAvg) oo socodsii. Daaqadda rakibaha adeegga NSSM(NSSM service installer) ayaa furmi doonta.

  1. Guji(Click) badhanka ellipses ee ku xiga Jidka:(Path:) garoonka, u gudub powershell.exe(powershell.exe ) oo sida caadiga ah ku yaal C:\Windows\System32\ . Dooro powershell.exe Jidka :(Path:) iyo Hagaha bilowga:(Startup directory:) beeraha si toos ah ayaa loo buux dhaafin doonaa.

  1. Geli kuwa soo socda doodaha:(Arguments:) goobta: -ExecutionPolicy Bypass -NoProfile -File “C:\PathToScript\get-Script.ps1” , halkaas oo qaybta ugu dambeysa ay tahay dariiqa loo maro qoraalkaaga PowerShell iyo qoraalka magaca.  

  1. Dooro tabka Faahfaahinta . (Details)Geli waxa aad rabto in adeega lagu muujiyo sida maamulaha Adeegyada (Services)Windows geli (Windows) magaca Muujinta:(Display name: ) goobta. Kadibna, gali waxa ay qabato ee Description: field. Nooca bilawga:(Startup type: ) waxaa loo dejin karaa si toos ah(Automatic) , Toos ah (Bilow dib u dhac ah)(Automatic (Delayed Start)) , Buug(Manual) , ama Naafo(Disabled) . Layligan, Toomaatig(Automatic) ayaa u wanaagsan.

  1. Dooro Log on tab. Dooro akoonkan :(This account) badhanka raadiyaha oo geli akoonka iyo erayga sirta ah ee adeeggu u shaqayn doono. Waxaad u baahan doontaa inaad doorato akoon uu adeeggu ku hoos socon doono. Fikrad ahaan, waxaad yeelan doontaa akoon Windows ah oo loo sameeyay kaliya in lagu socodsiiyo adeeggan. Oggolaanshaha akoonkan waa in lagu xaddidaa oo keliya waxa adeeggu u baahan yahay inuu sameeyo. Waxaad dooran kartaa koontada Nidaamka Maxaliga ah(Local System account) , laakiin laguma talinayo sababo ammaan dartood.

Waxaa jira dhowr tab oo kale oo loo isticmaali karo in lagu habeeyo adeegga. Layligan, qiimaha caadiga ah ee tabyadaas ayaa ku filan. Dooro badhanka adeegga ku rakib .(Install service )

  1. Marka adeegga la rakibo, waxaad arki doontaa Service “logCPUAvg” installed successfully! daaqada. Dooro OK si aad u xirto. Taasi waxay soo gabagabeyneysaa rakibidda.

  1. Fur Maareeyaha Adeegyada Windows(Windows Services Manager ) oo hubi in adeeggu jiro.

  1. Daar(Run) adeega si aad u hubiso in uu shaqaynayo.

  1. Si aad u xaqiijiso in adeegani socdo, isticmaal File Explorer si aad ugu socotid meesha logu talagalay in lagu kaydiyo si aad u aragto in uu jiro.

nssm-hubi-log.png(nssm-check-log.png)

Kasaarida Adeegga Daaqadaha ee NSSM(Removing a Windows Service With NSSM)

Waxaa laga yaabaa inaadan u baahnayn inaad la socoto culayska CPU gaaga(monitor your CPU) , markaa waxaad jeclaan lahayd inaad ka takhalusto adeegga. Nasiib wanaag, NSSM taas way fududahay. 

  1. Gudaha Maamulaha Adeegyada Windows(Windows Services Manager) , jooji adeegga. Tan samee adiga oo dooranaya Log CPU Celceliska Load(Log CPU Average Load ) Service ka dib ama dooranaya badhanka joogsiga labajibbaaran ee aaladda ama Jooji xidhiidhka adeegga(Stop the service) ee dhinaca bidix.

  1. Fur midkood Windows Command Prompt ama PowerShell maamule ahaan.
  2. Geli amarka nssm ka saar logCPUAvg(nssm remove logCPUAvg) oo fuli amarka. 

  1. NSSM waxay ku weydiin doontaa inaad xaqiijiso. Dooro Haa(Yes) .

  1. Marka adeegga la saaro, waxaad arki doontaa Service “logCPUAvg” removed successfully! Xaqiijinta. Dooro OK oo waad dhammaysay

Waa intaas. Waa fikrad wanaagsan in la hubiyo maamulaha adeegyada si loo hubiyo in adeeggu aanu meeshaas sii jirin. Haddii aad weli aragto adeegga, waxaa laga yaabaa inaad u baahato inaad dib u soo kiciso shaashadda oo waa inay tagto.

Adeegyadu waa hab fiican oo lagu socodsiiyo abka ama qoraallada u baahan inay mar walba shaqeeyaan, dib u bilaabaan naftooda haddii ay ku guuldareystaan, ama u baahan mudnaan ka duwan kan isticmaala hadda. Haddii aadan u baahnayn abkaaga ama qoraalkaaga si aad u samayso waxyaalahaas oo dhan, ka fiirso inaad isticmaasho Hawsha la qorsheeyay(using a Scheduled Task) .



About the author

Waxaan ahay khibrad Windows 10 iyo Windows 11/10 Maamule khibrad u leh Edge. Waxaan leeyahay aqoon iyo waayo-aragnimo badan oo aan ku bixiyo goobtan, taas oo ah sababta aan u aaminsanahay in xirfadahaygu ay u noqon doonaan hanti qiimo leh shirkaddaada. Sannadaha aan waayo-aragnimada u leeyahay labada Windows 10 iyo Edge waxay i siinayaan awood aan si degdeg ah u barto tignoolajiyada cusub, u xalliyo dhibaatooyinka si dhakhso ah, oo aan ula wareego marka ay timaaddo socodsiinta ganacsigaaga. Intaa waxaa dheer, waayo-aragnimadayda Windows 10 iyo Edge waxay iga dhigayaan aqoon badan oo ku saabsan dhammaan qaybaha nidaamka qalliinka, taas oo faa'iido u leh maareynta server-yada ama maareynta codsiyada software.



Related posts