熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

Windows服務:方便地啟動Oracle服務

2022-06-13   來源: Oracle 

  Oracle i有多個系統服務必須都啟動之後才能正常工作但逐個啟動比較費事多數學習Oracle但機器又不是太好的朋友也不能容忍每次都自動啟動Oracle服務(那樣MB的內存在啟動時就所剩無幾了)所以通常都是要用了再啟動這裡給出了批量啟動windows系統服務的一個例子介紹了操控windows系統服務的技巧

首先新建一個Windows Application工程取名為Oracle Starter
粘貼如下代碼文件
FormDesignervb

Partial Public Class Form
    Inherits SystemWindowsFormsForm

  <SystemDiagnosticsDebuggerNonUserCode()> _
    Public Sub New()
        MyBaseNew()

  This call is required by the Windows Form Designer
        InitializeComponent()

  End Sub

  Form overrides dispose to clean up the component list
    <SystemDiagnosticsDebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            componentsDispose()
        End If
        MyBaseDispose(disposing)
    End Sub

  Required by the Windows Form Designer
    Private components As SystemComponentModelIContainer

  NOTE: The following procedure is required by the Windows Form Designer
    It can be modified using the Windows Form Designer 
    Do not modify it using the code editor
    <SystemDiagnosticsDebuggerStepThrough()> _
    Private Sub InitializeComponent()
        MeLabel = New SystemWindowsFormsLabel
        MeListBox = New SystemWindowsFormsListBox
        MeButton = New SystemWindowsFormsButton
        MeButton = New SystemWindowsFormsButton
        MeSuspendLayout()
       
        Label
       
        MeLabelAutoSize = True
        MeLabelFont = New SystemDrawingFont(Tahoma ! SystemDrawingFontStyleBold SystemDrawingGraphicsUnitPoint CType( Byte))
        MeLabelLocation = New SystemDrawingPoint( )
        MeLabelName = Label
        MeLabelSize = New SystemDrawingSize( )
        MeLabelTabIndex =
        MeLabelText = Oracle Starter
       
        ListBox
       
        MeListBoxFont = New SystemDrawingFont(Tahoma ! SystemDrawingFontStyleRegular SystemDrawingGraphicsUnitPoint CType( Byte))
        MeListBoxFormattingEnabled = True
        MeListBoxItemHeight =
        MeListBoxLocation = New SystemDrawingPoint( )
        MeListBoxName = ListBox
        MeListBoxSize = New SystemDrawingSize( )
        MeListBoxTabIndex =
       
        Button
       
        MeButtonLocation = New SystemDrawingPoint( )
        MeButtonName = Button
        MeButtonSize = New SystemDrawingSize( )
        MeButtonTabIndex =
        MeButtonText = Stop all services
       
        Button
       
        MeButtonLocation = New SystemDrawingPoint( )
        MeButtonName = Button
        MeButtonSize = New SystemDrawingSize( )
        MeButtonTabIndex =
        MeButtonText = Start all servies
       
        Form
       
        MeAutoScaleBaseSize = New SystemDrawingSize( )
        MeClientSize = New SystemDrawingSize( )
        MeControlsAdd(MeButton)
        MeControlsAdd(MeButton)
        MeControlsAdd(MeListBox)
        MeControlsAdd(MeLabel)
        MeName = Form
        MeText = Oracle Starter
        MeResumeLayout(False)
        MePerformLayout()

  End Sub
    Friend WithEvents Label As SystemWindowsFormsLabel
    Friend WithEvents ListBox As SystemWindowsFormsListBox
    Friend WithEvents Button As SystemWindowsFormsButton
    Friend WithEvents Button As SystemWindowsFormsButton

  End Class

  Formvb

Imports SystemServiceProcess
Imports SystemThreading

  Public Class Form

  Private procName As String
    Private procArray() As String

  Private Sub Form_Activated(ByVal sender As Object ByVal e As SystemEventArgs) Handles MeActivated

  End Sub


  Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
        procArray() = OracleMTSRecoveryService
        procArray() = OracleOraHomeAgent
        procArray() = OracleOraHomeTNSListener
        procArray() = OracleServiceSFSVDB
        procArray() = OracleOraHomeHTTPServer
    End Sub

  Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
        Dim backThread As Thread
        Dim i As Int
        For i = To
            backThread = New Thread(AddressOf procClassStopProc)
            backThreadIsBackground = True
            procClassprocName = procArray(i)
            LabelText = Stopping service: + procClassprocName +
            MeRefresh()
            backThreadStart()
            backThreadJoin()
            ListBoxItemsAdd(Service: + procClassprocName + Stopped)
            MeRefresh()
            backThread = Nothing
        Next
        LabelText = All services stopped
    End Sub

  Private Sub Button_Click(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles ButtonClick
        Dim backThread As Thread
        Dim i As Int
        For i = To
            backThread = New Thread(AddressOf procClassStartProc)
            procClassprocName = procArray(i)
            LabelText = Starting service: + procClassprocName +
            MeRefresh()
            backThreadStart()
            backThreadJoin()
            ListBoxItemsAdd(Service: + procClassprocName + Started)
            MeRefresh()
            backThread = Nothing
        Next
        LabelText = All services started
    End Sub

  Public Class procClass
        Public Shared procName As String

  Public Shared Sub StopProc()
            Dim servController As ServiceController = New ServiceController(procName)
            If servControllerStatus = ServiceControllerStatusStopped Then
            ElseIf servControllerStatus = ServiceControllerStatusPaused Then
                servControllerStop()
                servControllerWaitForStatus(ServiceControllerStatusStopped)
            ElseIf servControllerStatus = ServiceControllerStatusRunning Then
                servControllerStop()
                servControllerWaitForStatus(ServiceControllerStatusStopped)
            End If
        End Sub

  Public Shared Sub StartProc()
            Dim servController As ServiceController = New ServiceController(procName)
            If servControllerStatus = ServiceControllerStatusRunning Then
            ElseIf servControllerStatus = ServiceControllerStatusPaused Then
                servControllerContinue()
                servControllerWaitForStatus(ServiceControllerStatusRunning)
            ElseIf servControllerStatus = ServiceControllerStatusStopped Then
                servControllerStart()
                servControllerWaitForStatus(ServiceControllerStatusRunning)
            End If
        End Sub
    End Class
End Class

總結
這個實例只是運用了系統服務控制的基本功能高級功能還不甚了解對於多線程的運用還不是很明確望大家指正

改進
程序在運行時如果焦點離開用戶界面便會鎖死雖然嘗試了多線程仍然不理想應該還Join()方法有關多次修正未果請高手指點謝謝!

測試平台
Windows Server Visual VBNET Beta


From:http://tw.wingwit.com/Article/program/Oracle/201311/17456.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.