منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب

نسخة كاملة : استرجاع جميع السيرفس services في الجهاز التي تكون في حاله running C# و vb.net
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
كاتب الموضوع : AhmedEssawy

اولا يجب عليك اضافه

كود :
[FONT=Courier New][color=blue][COLOR=blue][FONT=Courier New]using[/FONT][/color][FONT=Courier New][color=#000000] System.ServiceProcess ;[/color][/FONT][/COLOR][/FONT]


و اضافه system.serviceprocess.dll في refrence المشروع




C#



كود :
[FONT=Courier New][color=blue][FONT=Courier New]private[/FONT][/color][FONT=Courier New][color=blue]void[/color][color=#000000] button1_Click([/color][color=blue]object[/color][color=#000000] sender, [/color][color=teal]EventArgs[/color][color=#000000] e)[/color][/FONT][/FONT]


[FONT=Courier New][FONT=Courier New][color=#000000]{[/color][/FONT][/FONT]


[FONT=Courier New][FONT=Courier New][color=teal]ServiceController[/color][color=#000000][] scServices;[/color][/FONT][/FONT][FONT=Courier New]


[FONT=Courier New][color=#000000]scServices = [/color][color=teal]ServiceController[/color][color=#000000].GetServices();[/color][/FONT]



[FONT=Courier New][color=green]// Display the list of services currently running on this computer.[/color][/FONT]



[FONT=Courier New][color=teal]MessageBox[/color][color=#000000].Show([/color][color=maroon]"Services running on the local computer:"[/color][color=#000000]);[/color][/FONT]


[FONT=Courier New][color=blue]foreach[/color][color=#000000] ([/color][color=teal]ServiceController[/color][color=#000000] scTemp [/color][color=blue]in[/color][color=#000000] scServices)[/color][/FONT]


[FONT=Courier New][color=#000000]{[/color][/FONT]


[FONT=Courier New][color=blue]if[/color][color=#000000] (scTemp.Status == [/color][color=teal]ServiceControllerStatus[/color][color=#000000].Running)[/color][/FONT]


[FONT=Courier New][color=#000000]{[/color][/FONT]


[FONT=Courier New][color=green]// Write the service name and the display name[/color][/FONT]


[FONT=Courier New][color=green]// for each running service.[/color][/FONT]



[FONT=Courier New][color=teal]MessageBox[/color][color=#000000].Show([/color][color=maroon]" Service : "[/color][color=#000000] + scTemp.ServiceName);[/color][/FONT]


[FONT=Courier New][color=teal]MessageBox[/color][color=#000000].Show([/color][color=maroon]" Display name: "[/color][color=#000000] + scTemp.DisplayName);[/color][/FONT]




[FONT=Courier New][color=#000000]}[/color][/FONT]


[FONT=Courier New][color=#000000]}[/color][/FONT]




[FONT=Courier New][color=#000000]}[/color][/FONT]



[/FONT]


vb



كود :
[FONT=Courier New][color=blue][FONT=Courier New]Dim[/FONT][/color][FONT=Courier New][color=#000000] scServices() [/color][color=blue]As[/color][color=#000000] ServiceController[/color][/FONT][/FONT]


[FONT=Courier New][FONT=Courier New][color=#000000]scServices = ServiceController.GetServices()[/color][/FONT][/FONT][FONT=Courier New]



[color=green][FONT=Courier New]' Display the list of services currently running on this computer.[/FONT][/color]


[FONT=Courier New][color=#000000]Console.WriteLine([/color][color=maroon]"Services running on the local computer:"[/color][color=#000000])[/color][/FONT]



[color=blue][FONT=Courier New]Dim[/FONT][/color][FONT=Courier New][color=#000000] scTemp [/color][color=blue]As[/color][color=#000000] ServiceController[/color][/FONT]


[color=blue][FONT=Courier New]For[/FONT][/color][FONT=Courier New][color=blue]Each[/color][color=#000000] scTemp [/color][color=blue]In[/color][color=#000000] scServices[/color][/FONT]



[FONT=Courier New][color=blue]If[/color][color=#000000] scTemp.Status = ServiceControllerStatus.Running [/color][color=blue]Then[/color][/FONT]


[color=green][FONT=Courier New]' Write the service name and the display name[/FONT][/color]


[color=green][FONT=Courier New]' for each running service.[/FONT][/color]


[FONT=Courier New][color=#000000]Console.WriteLine()[/color][/FONT]


[FONT=Courier New][color=#000000]Console.WriteLine([/color][color=maroon]" Service : {0}"[/color][color=#000000], scTemp.ServiceName)[/color][/FONT]


[FONT=Courier New][color=#000000]Console.WriteLine([/color][color=maroon]" Display name: {0}"[/color][color=#000000], scTemp.DisplayName)[/color][/FONT]




[FONT=Courier New][color=blue]End[/color][color=blue]If[/color][/FONT]



[color=blue][FONT=Courier New]Next[/FONT][/color][FONT=Courier New][color=#000000] scTemp[/color][/FONT]

[/FONT]
[/font]