Page 1 of 1 1
Topic Options
#175522 - 2007-04-20 10:56 AM KiXforms: Service Manager
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1865
Loc: Hilversum, The Netherlands
Playing around with kixforms and kixforms.net I wrote a script twice, once in 2.x and once in .Net. Mainly for educational purposes to see which things would be entirely different and such. The layout is a rip-off of Chris S's ProcessMon.

Thanks go to:
Benny: for showing me how to add listview items in .Net (and KiXforms Desginer obviously ;))
Shawn: for giving me the general idea on how to cancel the .net form close event in .Net (and for the KiXforms versions off course)
Jochen: for showing me how to enumerate items in a combobox in 2.x

Without further ado the code for Service Manager for KiXforms 2.x
 Code:
Break On
Global $svc, $Item, $StartMode
;KD1 START

$Form1 = CreateObject("Kixtart.Form")
$Form1.BackColor = 235,233,237
$Form1.FontSize = 8,25
$Form1.Height = 355 ;347
$Form1.Text = "Service Manager"
$Form1.Width = 403
$Form1.MaximizeBox = 0

;Dim $ListViewEx2
$ListViewEx2 = $Form1.Controls.ListView()
$ListViewEx2.FontSize = 8,25
$ListViewEx2.Height = 265
$ListViewEx2.Left = 15
$ListViewEx2.Top = 15
$ListViewEx2.Width = 365
$ListViewEx2.FullRowSelect = True

$=$ListViewEx2.Columns.Add("Service Name",130)
$=$ListViewEx2.Columns.Add("Status",54,2)
$=$ListViewEx2.Columns.Add("Startup Type",75,2)
$=$ListViewEx2.Columns.Add("Description",150)

;Dim $ComboBox1
$ComboBox1 = $Form1.Controls.ComboBox()
$ComboBox1.DropDownWidth = 120
$ComboBox1.FontSize = 8,25
$ComboBox1.Height = 21
$ComboBox1.Left = 15
$ComboBox1.Additem(@WKSTA)
$ComboBox1.Value = "@WKSTA"
$ComboBox1.Top = 289
$ComboBox1.Width = 120
$ComboBox1.Sorted = 1

;Dim $Button1
$Button1 = $Form1.Controls.Button()
$Button1.FontSize = 8,25
$Button1.Height = 21
$Button1.Left = 150
$Button1.Text = "Refresh"
$Button1.Top = 288
$Button1.Width = 75
$Button1.OnClick = "$$=fnGetServicesList($$ComboBox1.Text)"
$Button1.ToolTip = "Get the list of the selected Computer"

;Dim $Button2
$Button2 = $Form1.Controls.Button()
$Button2.FontSize = 8,25
$Button2.Height = 21
$Button2.Left = 227
$Button2.Text = "Clear"
$Button2.Top = 288
$Button2.Width = 75
$Button2.OnClick = "$$ListViewEx2.Items.Clear"
$Button2.ToolTip = "Clears the list of services"

;Dim $Button3
$Button3 = $Form1.Controls.Button()
$Button3.FontSize = 8,25
$Button3.Height = 21
$Button3.Left = 304
$Button3.Text = "Properties"
$Button3.Top = 288
$Button3.Width = 75
$Button3.OnClick = "$$=InitForm2($$ComboBox1.Text)"
$Button3.ToolTip = "Lets you change settings for the selected service"
;KD1 END

;KD2 START
;Dim $Form2
;$Form2 = $System.Form()
$Form2 = CreateObject("Kixtart.Form")
$Form2.BackColor = 235,233,237
$Form2.FontSize = 8,25
$Form2.Height = 300
$Form2.Left = 14
$Form2.Text = ""
$Form2.Top = 15
$Form2.Width = 325
$Form1.MaximizeBox = 0

;Dim $frm2lbl1
$frm2lbl1 = $Form2.Controls.Label()
$frm2lbl1.BackColor = 235,233,237
$frm2lbl1.FontSize = 8,25
$frm2lbl1.Height = 15
$frm2lbl1.Left = 15
$frm2lbl1.Text = "Service Name:"
$frm2lbl1.Top = 15
$frm2lbl1.Width = 81

;Dim $frm2lbl2
$frm2lbl2 = $Form2.Controls.Label()
$frm2lbl2.BackColor = 235,233,237
$frm2lbl2.FontSize = 8,25
$frm2lbl2.Height = 15
$frm2lbl2.Left = 15
$frm2lbl2.Text = "Display Name:"
$frm2lbl2.Top = 45
$frm2lbl2.Width = 78

;Dim $frm2lbl3
$frm2lbl3 = $Form2.Controls.Label()
$frm2lbl3.BackColor = 235,233,237
$frm2lbl3.FontSize = 8,25
$frm2lbl3.Height = 15
$frm2lbl3.Left = 15
$frm2lbl3.Text = "Description:"
$frm2lbl3.Top = 75
$frm2lbl3.Width = 67

;Dim $frm2lbl4
$frm2lbl4 = $Form2.Controls.Label()
$frm2lbl4.BackColor = 235,233,237
$frm2lbl4.FontSize = 8,25
$frm2lbl4.Height = 15
$frm2lbl4.Left = 15
$frm2lbl4.Text = "Path to Executable:"
$frm2lbl4.Top = 105
$frm2lbl4.Width = 102

;Dim $frm2lbl5
$frm2lbl5 = $Form2.Controls.Label()
$frm2lbl5.BackColor = 235,233,237
$frm2lbl5.FontSize = 8,25
$frm2lbl5.Height = 15
$frm2lbl5.Left = 15
$frm2lbl5.Text = "Startup Type:"
$frm2lbl5.Top = 175
$frm2lbl5.Width = 72

;Dim $frm2lbl6
$frm2lbl6 = $Form2.Controls.Label()
$frm2lbl6.BackColor = 235,233,237
$frm2lbl6.FontSize = 8,25
$frm2lbl6.Height = 15
$frm2lbl6.Left = 15
$frm2lbl6.Text = "Service Status:"
$frm2lbl6.Top = 205
$frm2lbl6.Width = 81

;Dim $frm2lbl7
$frm2lbl7 = $Form2.Controls.Label()
$frm2lbl7.BackColor = 235,233,237
$frm2lbl7.FontSize = 8,25
$frm2lbl7.Height = 15
$frm2lbl7.Left = 135
$frm2lbl7.Text = ""
$frm2lbl7.Top = 15
$frm2lbl7.Width = 165

;Dim $frm2lbl8
$frm2lbl8 = $Form2.Controls.Label()
$frm2lbl8.BackColor = 235,233,237
$frm2lbl8.FontSize = 8,25
$frm2lbl8.Height = 16
$frm2lbl8.Left = 135
$frm2lbl8.Text = ""
$frm2lbl8.Top = 205
$frm2lbl8.Width = 164

;Dim $frm2but1
$frm2but1 = $Form2.Controls.Button()
$frm2but1.FontSize = 8,25
$frm2but1.Height = 23
$frm2but1.Left = 15
$frm2but1.Text = "Start"
$frm2but1.Top = 235
$frm2but1.Width = 60
$frm2but1.OnClick = "$$=StartService($$ComboBox1.Text)"

;Dim $frm2but2
$frm2but2 = $Form2.Controls.Button()
$frm2but2.FontSize = 8,25
$frm2but2.Height = 23
$frm2but2.Left = 90
$frm2but2.Text = "Stop"
$frm2but2.Top = 235
$frm2but2.Width = 60
$frm2but2.OnClick = "$$=StopService($$ComboBox1.Text)"

;Dim $frm2but3
$frm2but3 = $Form2.Controls.Button()
$frm2but3.FontSize = 8,25
$frm2but3.Height = 23
$frm2but3.Left = 165
$frm2but3.Text = "Pause"
$frm2but3.Top = 235
$frm2but3.Width = 60
$frm2but3.OnClick = "$$=PauseService($$ComboBox1.Text)"

;Dim $frm2but4
$frm2but4 = $Form2.Controls.Button()
$frm2but4.FontSize = 8,25
$frm2but4.Height = 23
$frm2but4.Left = 240
$frm2but4.Text = "Resume"
$frm2but4.Top = 235
$frm2but4.Width = 60
$frm2but4.OnClick = "$$=ResumeService($$ComboBox1.Text)"

$frm2but5 = $Form2.Controls.Button()
$frm2but5.FontSize = 8,25
$frm2but5.Height = 23
$frm2but5.Left = 230
$frm2but5.Text = "Apply"
$frm2but5.Top = 172
$frm2but5.Width = 70
$frm2but5.OnClick = "$$=ApplyService($$ComboBox1.Text)"

;Dim $frm2tbx1
$frm2tbx1 = $Form2.Controls.TextBox()
$frm2tbx1.FontSize = 8,25
$frm2tbx1.Height = 20
$frm2tbx1.Left = 135
$frm2tbx1.ReadOnly = "True"
$frm2tbx1.Text = ""
$frm2tbx1.Top = 45
$frm2tbx1.Width = 164

;Dim $frm2tbx2
$frm2tbx2 = $Form2.Controls.RichTextBox()
$frm2tbx2.FontSize = 8,25
$frm2tbx2.Height = 44
$frm2tbx2.Left = 135
$frm2tbx2.Multiline = "True"
$frm2tbx2.ReadOnly = "True"
$frm2tbx2.Text = ""
$frm2tbx2.Top = 75
$frm2tbx2.Width = 164

;Dim $frm2tbx3
$frm2tbx3 = $Form2.Controls.TextBox()
$frm2tbx3.FontSize = 8,25
$frm2tbx3.Height = 20
$frm2tbx3.Left = 15
$frm2tbx3.ReadOnly = "True"
$frm2tbx3.Text = ""
$frm2tbx3.Top = 135
$frm2tbx3.Width = 285

;Dim $frm2cbx1
$frm2cbx1 = $Form2.Controls.ComboBox()
$frm2cbx1.DropDownWidth = 190
$frm2cbx1.FontSize = 8,25
$frm2cbx1.Height = 21
$frm2cbx1.Left = 135
$frm2cbx1.Sorted = "True"
$frm2cbx1.Text = ""
$frm2cbx1.Top = 173
$frm2cbx1.Width = 80
;KD2 END

$=fnGetServicesList($ComboBox1.Value)
$Form1.Center
$Form1.Show

While $Form1.Visible
  $=Execute($Form1.DoEvents)
Loop

Exit(0)

Function fnGetServicesList(Optional $strComputer)
  Dim $objWMIService, $colItems, $objItem, $s, $chk
  $chk = 0
  For $s = 0 to $ComboBox1.ListCount
    $ComboBox1.ListIndex = $s
    If $ComboBox1.Text = $strComputer $chk = 1 EndIf
  Next
  $ComboBox1.Text = $strComputer
  If $strComputer = "" $strComputer = "." EndIf
  $Form1.Text = "Service List for " + $strComputer
  $ListViewEx2.Items.Clear
  $ListViewEx2.BeginUpdate
  $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  If $chk = 0 AND @ERROR = 0 $=$ComboBox1.AddItem($strComputer) EndIf
  $colItems = $objWMIService.ExecQuery("Select * from Win32_Service",,48)
  For each $objItem in $colItems
    $Item = $ListViewEx2.Items.Add($objItem.Name)
    $Item.SubItems(1).Text = $objItem.State
    $Item.SubItems(2).Text = $objItem.StartMode
    $Item.SubItems(3).Text = $objItem.Description
  Next
  $ListViewEx2.EndUpdate
EndFunction

Function InitForm2(Optional $strComputer)
  $Form1.Hide
  $Form2.Center
  $Form2.Show
  fnGetServiceProps($strComputer)
  While $Form2.Visible
    $=Execute($Form2.DoEvents)
  Loop
  $Form1.Show
EndFunction

Function fnGetServiceProps(Optional $strComputer)
  Dim $objWMISvc, $i, $clItems, $itm
  For Each $i in $ListViewEx2.SelectedItems
     $svc = $i.SubItems(0).Text
  Next
  $Form2.Text = "Service: " + $svc
  $frm2cbx1.Clear
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    $frm2lbl7.Text = $itm.Name
    $frm2lbl8.Text = $itm.State
    $frm2tbx1.Text = $itm.DisplayName
    $frm2tbx2.Text = $itm.Description
    $frm2tbx3.Text = $itm.PathName
    $frm2cbx1.text = $itm.StartMode
    $StartMode = $itm.StartMode
  Next
  $frm2cbx1.AddItem("Auto")
  $frm2cbx1.AddItem("Manual")
  $frm2cbx1.AddItem("Disabled")
EndFunction

Function StartService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Stopped"
      $itm.StartService
    EndIf
    If $itm.State = "Paused"
      $=$Form2.MsgBox("The service " + $svc + " is paused!","Info")
    EndIf
    If $itm.State = "Running"
      $=$Form2.MsgBox("The service " + $svc + " is already running!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function StopService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Running"
      $itm.StopService
    EndIf
    If $itm.State = "Stopped"
      $=$Form2.MsgBox("The service " + $svc + " is already stopped!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function PauseService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Running"
      $itm.PauseService
    EndIf
    If $itm.State = "Paused"
      $=$Form2.MsgBox("The service " + $svc + " is already paused!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function ResumeService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Paused"
      $itm.ResumeService
    EndIf
    If $itm.State = "Stopped"
      $=$Form2.MsgBox("The service " + $svc + " is stopped!","Info")
    EndIf
    If $itm.State = "Running"
      $=$Form2.MsgBox("The service " + $svc + " is already running!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function ApplyService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $frm2cbx1.Text = "Auto"
      $=$itm.ChangeStartMode("Automatic")
    Else
      $=$itm.ChangeStartMode($frm2cbx1.Text)
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction


And the code for Service Manager for KixForms .Net
 Code:
Global $StartMode

$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

;Form1 Start

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.Size = $System.Size(403,355) ;(Width,Height)
$Form1.Text = "Service Manager .Net"
$Form1.Top = 0
$Form1.MaximizeBox = 0

$ListView1 = $System.ListView()
$ListView1.Height = 265
$ListView1.Left = 15
$ListView1.Top = 15
$ListView1.Width = 365
$ListView1.View = $System.View_Details
$ListView1.FullRowSelect = 1
$nul = $Form1.Controls.Add($ListView1)

$ListView1Column0 = $ListView1.Columns.Add($System.ColumnHeader("Service Name",130,$System.HorizontalAlignment_Left))
$ListView1Column1 = $ListView1.Columns.Add($System.ColumnHeader("Status",54,$System.HorizontalAlignment_Center))
$ListView1Column2 = $ListView1.Columns.Add($System.ColumnHeader("Startup Type",75,$System.HorizontalAlignment_Center))
$ListView1Column3 = $ListView1.Columns.Add($System.ColumnHeader("Description",150,$System.HorizontalAlignment_Left))

$ComboBox1 = $System.ComboBox()
$ComboBox1.DropDownWidth = 120
$ComboBox1.Height = 21
$ComboBox1.Left = 15
$ComboBox1.Text = @WKSTA
$ComboBox1.Top = 289
$ComboBox1.Width = 125
$nul = $Form1.Controls.Add($ComboBox1)

$Button1 = $System.Button()
$Button1.Height = 23
$Button1.Left = 155
$Button1.Text = "Refresh"
$Button1.Top = 288
$Button1.Width = 75
$Button1.Click = "$$=fnGetServicesList($$ComboBox1.Text)"
$nul = $Form1.Controls.Add($Button1)

$Button2 = $System.Button()
$Button2.Height = 23
$Button2.Left = 230
$Button2.Text = "Clear"
$Button2.Top = 288
$Button2.Width = 75
$Button2.Click = "$$ListView1.Items.Clear"
$nul = $Form1.Controls.Add($Button2)

$Button3 = $System.Button()
$Button2.Height = 23
$Button3.Left = 305
$Button3.Text = "Properties"
$Button3.Top = 288
$Button3.Width = 75
$Button3.Click = "$$=InitForm2($$ComboBox1.Text)"
$nul = $Form1.Controls.Add($Button3)

;Form1 End
;Form2 Start

$Form2 = $System.Form()
$Form2.Left = 0
$Form2.StartPosition = 0  ;FormStartPosition_Manual
$Form2.Size = $System.Size(325,300) ;(Width,Height)
$Form2.Text = ""
$Form2.Top = 262
$Form2.MaximizeBox = 0
$Form2.Closing = "$$=CancelClose($$System.EventArgs)"

$frm2lbl1 = $System.Label()
$frm2lbl1.BorderStyle = 0  ;FixedSingle
$frm2lbl1.Left = 10
$frm2lbl1.Text = "Service Name:"
$frm2lbl1.Top = 20
$nul = $Form2.Controls.Add($frm2lbl1)

$frm2lbl2 = $System.Label()
$frm2lbl2.BorderStyle = 0  ;FixedSingle
$frm2lbl2.Left = 10
$frm2lbl2.Text = "Display Name:"
$frm2lbl2.Top = 50
$nul = $Form2.Controls.Add($frm2lbl2)

$frm2lbl3 = $System.Label()
$frm2lbl3.BorderStyle = 0  ;FixedSingle
$frm2lbl3.Left = 10
$frm2lbl3.Text = "Description:"
$frm2lbl3.Top = 80
$nul = $Form2.Controls.Add($frm2lbl3)

$frm2lbl4 = $System.Label()
$frm2lbl4.BorderStyle = 0  ;FixedSingle
$frm2lbl4.Left = 10
$frm2lbl4.Text = "Path to Executable:"
$frm2lbl4.Top = 110
$frm2lbl4.Width = 110
$nul = $Form2.Controls.Add($frm2lbl4)

$frm2lbl5 = $System.Label()
$frm2lbl5.BorderStyle = 0  ;FixedSingle
$frm2lbl5.Left = 10
$frm2lbl5.Text = "Startup Type:"
$frm2lbl5.Top = 170
$nul = $Form2.Controls.Add($frm2lbl5)

$frm2lbl6 = $System.Label()
$frm2lbl6.BorderStyle = 0  ;FixedSingle
$frm2lbl6.Left = 10
$frm2lbl6.Text = "Service Status:"
$frm2lbl6.Top = 200
$nul = $Form2.Controls.Add($frm2lbl6)

$frm2lbl7 = $System.Label()
$frm2lbl7.BorderStyle = 0  ;FixedSingle
$frm2lbl7.Left = 140
$frm2lbl7.Text = ""
$frm2lbl7.Top = 20
$frm2lbl7.Width = 160
$nul = $Form2.Controls.Add($frm2lbl7)

$frm2lbl8 = $System.Label()
$frm2lbl8.BorderStyle = 0  ;FixedSingle
$frm2lbl8.Left = 140
$frm2lbl8.Text = ""
$frm2lbl8.Top = 200
$frm2lbl8.Width = 160
$nul = $Form2.Controls.Add($frm2lbl8)

$frm2btn1 = $System.Button()
$frm2btn1.Left = 10
$frm2btn1.Text = "Start"
$frm2btn1.Top = 230
$frm2btn1.Width = 60
$frm2btn1.Click = "$$=StartService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn1)

$frm2btn2 = $System.Button()
$frm2btn2.Left = 87
$frm2btn2.Text = "Stop"
$frm2btn2.Top = 230
$frm2btn2.Width = 60
$frm2btn2.Click = "$$=StopService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn2)

$frm2btn3 = $System.Button()
$frm2btn3.Left = 162
$frm2btn3.Text = "Pause"
$frm2btn3.Top = 230
$frm2btn3.Width = 60
$frm2btn3.Click = "$$=PauseService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn3)

$frm2btn4 = $System.Button()
$frm2btn4.Left = 240
$frm2btn4.Text = "Resume"
$frm2btn4.Top = 230
$frm2btn4.Width = 60
$frm2btn4.Click = "$$=ResumeService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn4)

$frm2btn5 = $System.Button()
$frm2btn5.Left = 230
$frm2btn5.Text = "Apply"
$frm2btn5.Top = 169
$frm2btn5.Width = 70
$frm2btn5.Click = "$$=ApplyService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn5)

$frm2tbx1 = $System.TextBox()
$frm2tbx1.Left = 140
$frm2tbx1.Text = ""
$frm2tbx1.Top = 50
$frm2tbx1.Width = 160
$frm2tbx1.ReadOnly = 1
$nul = $Form2.Controls.Add($frm2tbx1)

$frm2tbx2 = $System.RichTextBox()
$frm2tbx2.Height = 50
$frm2tbx2.Left = 140
$frm2tbx2.Text = ""
$frm2tbx2.Top = 80
$frm2tbx2.Width = 160
$frm2tbx2.ReadOnly = 1
$nul = $Form2.Controls.Add($frm2tbx2)

$frm2tbx3 = $System.TextBox()
$frm2tbx3.Left = 10
$frm2tbx3.Text = ""
$frm2tbx3.Top = 140
$frm2tbx3.Width = 290
$frm2tbx3.ReadOnly = 1
$nul = $Form2.Controls.Add($frm2tbx3)

$frm2cbx1 = $System.ComboBox()
$frm2cbx1.DropDownWidth = 160
$frm2cbx1.Left = 140
$frm2cbx1.Text = ""
$frm2cbx1.Top = 170
$frm2cbx1.Width = 80 ;160
$nul = $Form2.Controls.Add($frm2cbx1)

;Form2 End

$=fnGetServicesList($ComboBox1.Text)
$Form1.Center
$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit(0)

Function fnGetServicesList(Optional $strComputer)
  Dim $objWMIService, $colItems, $objItem, $s, $chk
  $chk = 0
  For Each $s in $ComboBox1.Items
    If $s = $strComputer $chk = 1 EndIf
  Next
  $Form1.Text = "Service List for " + $strComputer
  $ListView1.Items.Clear
  $ListView1.BeginUpdate
  $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  If $chk = 0 AND @ERROR = 0 $=$comboBox1.Items.Add($strComputer) EndIf
  $colItems = $objWMIService.ExecQuery("Select * from Win32_Service",,48)
  For Each $objItem in $colItems
    $item = $ListView1.Items.Add($System.ListViewItem($objItem.Name))
    $=$item.SubItems.Add($System.ListViewSubItem($objItem.State))
    $=$item.SubItems.Add($System.ListViewSubItem($objItem.StartMode))
    $=$item.SubItems.Add($System.ListViewSubItem($objItem.Description))
  Next
  $ListView1.EndUpdate
EndFunction

Function InitForm2(Optional $strComputer)
  $Form1.Hide
  fnGetServiceProps($strComputer)
  $Form2.Center
  $Form2.Show
  While $Form2.Visible
    $=Execute($Form2.DoEvents)
  Loop
  $Form1.Show
EndFunction

Function fnGetServiceProps(Optional $strComputer)
  Dim $objWMISvc, $i, $clItems, $itm
  For Each $i in $ListView1.SelectedItems
     $svc = $i.Text
  Next
  $Form2.Text = "Service: " + $svc
  $=$frm2cbx1.Items.Clear
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    $frm2lbl7.Text = $itm.Name
    $frm2lbl8.Text = $itm.State
    $frm2tbx1.Text = $itm.DisplayName
    $frm2tbx2.Text = $itm.Description
    $frm2tbx3.Text = $itm.PathName
    $frm2cbx1.text = $itm.StartMode
    $StartMode = $itm.StartMode
  Next
  $=$frm2cbx1.Items.Add("Auto")
  $=$frm2cbx1.items.Add("Manual")
  $=$frm2cbx1.items.Add("Disabled")
EndFunction

Function CancelClose($args)
  $args.Cancel = 1
  $Form2.Hide
EndFunction

Function StartService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Stopped"
      $itm.StartService
    EndIf
    If $itm.State = "Paused"
      $=MessageBox("The service " + $svc + " is paused!","Info")
    EndIf
    If $itm.State = "Running"
      $=MessageBox("The service " + $svc + " is already running!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function StopService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Running"
      $itm.StopService
    EndIf
    If $itm.State = "Stopped"
      $=MessageBox("The service " + $svc + " is already stopped!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function PauseService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Running"
      $itm.PauseService
    EndIf
    If $itm.State = "Paused"
      $=MessageBox("The service " + $svc + " is already paused!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function ResumeService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Paused"
      $itm.ResumeService
    EndIf
    If $itm.State = "Stopped"
      $=MessageBox("The service " + $svc + " is stopped!","Info")
    EndIf
    If $itm.State = "Running"
      $=MessageBox("The service " + $svc + " is already running!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function ApplyService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $frm2cbx1.Text = "Auto"
      $=$itm.ChangeStartMode("Automatic")
    Else
      $=$itm.ChangeStartMode($frm2cbx1.Text)
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Top
#175538 - 2007-04-20 03:20 PM Re: KiXforms: Service Manager [Re: Arend_]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Very Nice!
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#175554 - 2007-04-20 04:47 PM Re: KiXforms: Service Manager [Re: Benny69]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Nice. I tweaked the .net version to allow one to stretch the main form ...

 Code:
Break On

Global $StartMode

$System = CreateObject("Kixforms.System")
If Not $System
   $nul= MessageBox("KiXforms.Net Not Initiated. This Script Will Now Close.","Error",16)
   Quit()
EndIf
$nul = $System.Application.EnableVisualStyles

;Form1 Start

$Form1 = $System.Form()
$Form1.Left = 0
$Form1.StartPosition = 0  ;FormStartPosition_Manual
$Form1.Size = $System.Size(403,355) ;(Width,Height)
$Form1.Text = "Service Manager .Net"
$Form1.Top = 0
$Form1.MaximizeBox = 0
$Form1.DockPadding.All = 5

$ListView1 = $System.ListView()
$ListView1.Height = 265
$ListView1.Left = 15
$ListView1.Top = 15
$ListView1.Width = 365
$ListView1.View = $System.View_Details
$ListView1.FullRowSelect = 1
$ListView1.Dock = $System.DockStyle_Fill
$nul = $Form1.Controls.Add($ListView1)

$ListView1Column0 = $ListView1.Columns.Add($System.ColumnHeader("Service Name",130,$System.HorizontalAlignment_Left))
$ListView1Column1 = $ListView1.Columns.Add($System.ColumnHeader("Status",54,$System.HorizontalAlignment_Center))
$ListView1Column2 = $ListView1.Columns.Add($System.ColumnHeader("Startup Type",75,$System.HorizontalAlignment_Center))
$ListView1Column3 = $ListView1.Columns.Add($System.ColumnHeader("Description",150,$System.HorizontalAlignment_Left))

$Panel1 = $System.Panel()
$Panel1.Height = 40
$Panel1.DockPadding.All = 10
$Panel1.Dock = $System.DockStyle_Bottom

$nul = $Form1.Controls.Add($Panel1)

$ComboBox1 = $System.ComboBox()
$ComboBox1.DropDownWidth = 120
$ComboBox1.Height = 21
$ComboBox1.Left = 15
$ComboBox1.Text = @WKSTA
$ComboBox1.Top = 10
$ComboBox1.Width = 125
$nul = $Panel1.Controls.Add($ComboBox1)

$Button1 = $System.Button()
$Button1.Height = 23
$Button1.Left = $ComboBox1.Right + 5
$Button1.Text = "Refresh"
$Button1.Top = 10
$Button1.Width = 75
$Button1.Click = "$$=fnGetServicesList($$ComboBox1.Text)"
$nul = $Panel1.Controls.Add($Button1)

$Button2 = $System.Button()
$Button2.Height = 23
$Button2.Left = $Button1.Right + 5
$Button2.Text = "Clear"
$Button2.Top = 10
$Button2.Width = 75
$Button2.Click = "$$ListView1.Items.Clear"
$nul = $Panel1.Controls.Add($Button2)

$Button3 = $System.Button()
$Button2.Height = 23
$Button3.Left = $Button2.Right + 5
$Button3.Text = "Properties"
$Button3.Top = 10
$Button3.Width = 75
$Button3.Click = "$$=InitForm2($$ComboBox1.Text)"
$nul = $Panel1.Controls.Add($Button3)

;Form1 End
;Form2 Start

$Form2 = $System.Form()
$Form2.Left = 0
$Form2.StartPosition = 0  ;FormStartPosition_Manual
$Form2.Size = $System.Size(325,300) ;(Width,Height)
$Form2.Text = ""
$Form2.Top = 262
$Form2.MaximizeBox = 0
$Form2.Closing = "$$=CancelClose($$System.EventArgs)"

$frm2lbl1 = $System.Label()
$frm2lbl1.BorderStyle = 0  ;FixedSingle
$frm2lbl1.Left = 10
$frm2lbl1.Text = "Service Name:"
$frm2lbl1.Top = 20
$nul = $Form2.Controls.Add($frm2lbl1)

$frm2lbl2 = $System.Label()
$frm2lbl2.BorderStyle = 0  ;FixedSingle
$frm2lbl2.Left = 10
$frm2lbl2.Text = "Display Name:"
$frm2lbl2.Top = 50
$nul = $Form2.Controls.Add($frm2lbl2)

$frm2lbl3 = $System.Label()
$frm2lbl3.BorderStyle = 0  ;FixedSingle
$frm2lbl3.Left = 10
$frm2lbl3.Text = "Description:"
$frm2lbl3.Top = 80
$nul = $Form2.Controls.Add($frm2lbl3)

$frm2lbl4 = $System.Label()
$frm2lbl4.BorderStyle = 0  ;FixedSingle
$frm2lbl4.Left = 10
$frm2lbl4.Text = "Path to Executable:"
$frm2lbl4.Top = 110
$frm2lbl4.Width = 110
$nul = $Form2.Controls.Add($frm2lbl4)

$frm2lbl5 = $System.Label()
$frm2lbl5.BorderStyle = 0  ;FixedSingle
$frm2lbl5.Left = 10
$frm2lbl5.Text = "Startup Type:"
$frm2lbl5.Top = 170
$nul = $Form2.Controls.Add($frm2lbl5)

$frm2lbl6 = $System.Label()
$frm2lbl6.BorderStyle = 0  ;FixedSingle
$frm2lbl6.Left = 10
$frm2lbl6.Text = "Service Status:"
$frm2lbl6.Top = 200
$nul = $Form2.Controls.Add($frm2lbl6)

$frm2lbl7 = $System.Label()
$frm2lbl7.BorderStyle = 0  ;FixedSingle
$frm2lbl7.Left = 140
$frm2lbl7.Text = ""
$frm2lbl7.Top = 20
$frm2lbl7.Width = 160
$nul = $Form2.Controls.Add($frm2lbl7)

$frm2lbl8 = $System.Label()
$frm2lbl8.BorderStyle = 0  ;FixedSingle
$frm2lbl8.Left = 140
$frm2lbl8.Text = ""
$frm2lbl8.Top = 200
$frm2lbl8.Width = 160
$nul = $Form2.Controls.Add($frm2lbl8)

$frm2btn1 = $System.Button()
$frm2btn1.Left = 10
$frm2btn1.Text = "Start"
$frm2btn1.Top = 230
$frm2btn1.Width = 60
$frm2btn1.Click = "$$=StartService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn1)

$frm2btn2 = $System.Button()
$frm2btn2.Left = 87
$frm2btn2.Text = "Stop"
$frm2btn2.Top = 230
$frm2btn2.Width = 60
$frm2btn2.Click = "$$=StopService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn2)

$frm2btn3 = $System.Button()
$frm2btn3.Left = 162
$frm2btn3.Text = "Pause"
$frm2btn3.Top = 230
$frm2btn3.Width = 60
$frm2btn3.Click = "$$=PauseService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn3)

$frm2btn4 = $System.Button()
$frm2btn4.Left = 240
$frm2btn4.Text = "Resume"
$frm2btn4.Top = 230
$frm2btn4.Width = 60
$frm2btn4.Click = "$$=ResumeService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn4)

$frm2btn5 = $System.Button()
$frm2btn5.Left = 230
$frm2btn5.Text = "Apply"
$frm2btn5.Top = 169
$frm2btn5.Width = 70
$frm2btn5.Click = "$$=ApplyService($$ComboBox1.Text)"
$nul = $Form2.Controls.Add($frm2btn5)

$frm2tbx1 = $System.TextBox()
$frm2tbx1.Left = 140
$frm2tbx1.Text = ""
$frm2tbx1.Top = 50
$frm2tbx1.Width = 160
$frm2tbx1.ReadOnly = 1
$nul = $Form2.Controls.Add($frm2tbx1)

$frm2tbx2 = $System.RichTextBox()
$frm2tbx2.Height = 50
$frm2tbx2.Left = 140
$frm2tbx2.Text = ""
$frm2tbx2.Top = 80
$frm2tbx2.Width = 160
$frm2tbx2.ReadOnly = 1
$nul = $Form2.Controls.Add($frm2tbx2)

$frm2tbx3 = $System.TextBox()
$frm2tbx3.Left = 10
$frm2tbx3.Text = ""
$frm2tbx3.Top = 140
$frm2tbx3.Width = 290
$frm2tbx3.ReadOnly = 1
$nul = $Form2.Controls.Add($frm2tbx3)

$frm2cbx1 = $System.ComboBox()
$frm2cbx1.DropDownWidth = 160
$frm2cbx1.Left = 140
$frm2cbx1.Text = ""
$frm2cbx1.Top = 170
$frm2cbx1.Width = 80 ;160
$nul = $Form2.Controls.Add($frm2cbx1)

;Form2 End

$=fnGetServicesList($ComboBox1.Text)
$Form1.Center
$Form1.Show  ;Displays the Form

While $Form1.Visible
   $Nul = Execute($Form1.DoEvents())
Loop
Exit(0)

Function fnGetServicesList(Optional $strComputer)
  Dim $objWMIService, $colItems, $objItem, $s, $chk
  $chk = 0
  For Each $s in $ComboBox1.Items
    If $s = $strComputer $chk = 1 EndIf
  Next
  $Form1.Text = "Service List for " + $strComputer
  $ListView1.Items.Clear
  $ListView1.BeginUpdate
  $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  If $chk = 0 AND @ERROR = 0 $=$comboBox1.Items.Add($strComputer) EndIf
  $colItems = $objWMIService.ExecQuery("Select * from Win32_Service",,48)
  For Each $objItem in $colItems
    $item = $ListView1.Items.Add($System.ListViewItem($objItem.Name))
    $=$item.SubItems.Add($System.ListViewSubItem($objItem.State))
    $=$item.SubItems.Add($System.ListViewSubItem($objItem.StartMode))
    $=$item.SubItems.Add($System.ListViewSubItem($objItem.Description))
  Next
  $ListView1.EndUpdate
EndFunction

Function InitForm2(Optional $strComputer)
  $Form1.Hide
  fnGetServiceProps($strComputer)
  $Form2.Center
  $Form2.Show
  While $Form2.Visible
    $=Execute($Form2.DoEvents)
  Loop
  $Form1.Show
EndFunction

Function fnGetServiceProps(Optional $strComputer)
  Dim $objWMISvc, $i, $clItems, $itm
  For Each $i in $ListView1.SelectedItems
     $svc = $i.Text
  Next
  $Form2.Text = "Service: " + $svc
  $=$frm2cbx1.Items.Clear
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    $frm2lbl7.Text = $itm.Name
    $frm2lbl8.Text = $itm.State
    $frm2tbx1.Text = $itm.DisplayName
    $frm2tbx2.Text = $itm.Description
    $frm2tbx3.Text = $itm.PathName
    $frm2cbx1.text = $itm.StartMode
    $StartMode = $itm.StartMode
  Next
  $=$frm2cbx1.Items.Add("Auto")
  $=$frm2cbx1.items.Add("Manual")
  $=$frm2cbx1.items.Add("Disabled")
EndFunction

Function CancelClose($args)
  $args.Cancel = 1
  $Form2.Hide
EndFunction

Function StartService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Stopped"
      $itm.StartService
    EndIf
    If $itm.State = "Paused"
      $=MessageBox("The service " + $svc + " is paused!","Info")
    EndIf
    If $itm.State = "Running"
      $=MessageBox("The service " + $svc + " is already running!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function StopService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Running"
      $itm.StopService
    EndIf
    If $itm.State = "Stopped"
      $=MessageBox("The service " + $svc + " is already stopped!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function PauseService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Running"
      $itm.PauseService
    EndIf
    If $itm.State = "Paused"
      $=MessageBox("The service " + $svc + " is already paused!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function ResumeService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $itm.State = "Paused"
      $itm.ResumeService
    EndIf
    If $itm.State = "Stopped"
      $=MessageBox("The service " + $svc + " is stopped!","Info")
    EndIf
    If $itm.State = "Running"
      $=MessageBox("The service " + $svc + " is already running!","Info")
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Function ApplyService(Optional $strComputer)
  Dim $objWMISvc, $clItems, $itm
  $objWMISvc = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
  $clItems = $objWMISvc.ExecQuery("select * from Win32_Service where Name=" + chr(34) + $svc + chr(34))
  For Each $itm in $clItems
    If $frm2cbx1.Text = "Auto"
      $=$itm.ChangeStartMode("Automatic")
    Else
      $=$itm.ChangeStartMode($frm2cbx1.Text)
    EndIf
  Next
  fnGetServiceProps($strComputer)
EndFunction

Top
#175572 - 2007-04-23 09:12 AM Re: KiXforms: Service Manager [Re: Shawn]
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1865
Loc: Hilversum, The Netherlands
Shouln't that be done with the .Anchor property instead of using a panel ?
Top
#175574 - 2007-04-23 03:18 PM Re: KiXforms: Service Manager [Re: Arend_]
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Could've used Anchor sure.
Top
#175578 - 2007-04-23 04:50 PM Re: KiXforms: Service Manager [Re: Shawn]
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1865
Loc: Hilversum, The Netherlands
 Originally Posted By: Shawn
Could've used Anchor sure.


Just checking ;\)

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 170 anonymous users online.
Newest Members
gkustra, emnipetro, Hirze, thequeen, ameliaryan
17642 Registered Users

Generated in 0.031 seconds in which 0.01 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org