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

نسخة كاملة : كيف الى تشغيل او ايقاف اي خدمة لويندوز7
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
الصفحات : 1 2 3
بقي الان كيف نستخدم الـ cmd بفيجوال بيسك
ببساطة

تشغيل
PHP كود :
Shell("net start W3SVC"
ايقاف
PHP كود :
Shell("net stop W3SVC"

تذكر يجب عليك تشغيل البرنامج كمسؤول لأن ايقاف الخدمة وتشغيلها يتطلب ذلك
كود تعطيل أو تفعيل الخدمة :
كود :
Imports System.IO


Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ServiceRunType("tlntsvr", False)
    End Sub


    Public Sub ServiceRunType(ByVal SrvName As String, ByVal SrvEnable As Boolean)
        Try
            Dim si As New ProcessStartInfo
            Dim command As String = ""
            With si
                .FileName = "cmd.exe"
                If SrvEnable = True Then
                    command = String.Format("/k sc config {0} start= auto", SrvName)
                Else
                    command = String.Format("/k sc config {0} start= disabled", SrvName)
                End If
                .Arguments = command
                .CreateNoWindow = True
                .RedirectStandardError = True
                .RedirectStandardOutput = True
                .UseShellExecute = False
            End With
            Dim p As Process = Process.Start(si)
            Dim so As StreamReader = p.StandardOutput
            Dim se As StreamReader = p.StandardError
            Dim StrContent As String = so.ReadToEnd
            If StrContent.ToLower.Contains("success") Then
                If SrvEnable = True Then
                    MsgBox("تم تفعيل الخدمة بنجاح", MsgBoxStyle.Exclamation, "تفعيل")
                Else
                    MsgBox("تم تعطيل الخدمة بنجاح", MsgBoxStyle.Exclamation, "تعطيل")
                End If
            ElseIf StrContent.ToLower.Contains("field") Then
                MsgBox("حدث خطأ . لا يمكن تفعيل أو تعطيل الخدمة حاول مرة أخرى", MsgBoxStyle.Exclamation, "خطأ")
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
        End Try
    End Sub


    
End Class

الخدمة tlntsvr وضعتها كمثال ضع بدلها اسم الخدمة تبعك


****
***
**
*
بارك الله فيك اخي
kslawy اضافة رائعة

ساجرب الكود في المرة القادمة لاني متعبSmile
استاذنكم
الصفحات : 1 2 3