KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Services manager

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
bruno
KiXforms Regular
KiXforms Regular


Joined: 19 May 2003
Posts: 44
Location: France (Europe)

PostPosted: Tue May 20, 2003 12:08 pm    Post subject: Services manager Reply with quote

Hello all,

There is a script I do to manage the services on the domain computers of my network. Please give me your comments.... Idea

Bruno.

Code:


Break on

;$=setconsole("minimize")
$=SetConsole("hide")

:top
$FORM1 = CreateObject("Kixtart.FORM")
If NOT $form1
   Copy ".\kixforms.dll" %windir%
   Shell 'regsvr32 /s %windir%\kixforms.dll'
   Goto top
EndIf
 
Global $uninstallkey[1]

$FORM1.CAPTION         = "Services manager v1.0"
$FORM1.SCALEHEIGHT      = 600
$FORM1.SCALEWIDTH      = 885
$FORM1.FONTNAME      = "Arial"
$FORM1.FONTSIZE      = 9
$FORM1.CENTER
$FORM1.icon         = ".\ico-ana.ico"

;---------------------- Entete -----------------------------

$entSelect         = $FORM1.Label
$entSelect.HEIGHT       = 30
$entSelect.Left       = 150
$entSelect.TOP         = 30
$entSelect.WIDTH       = 585
$entSelect.FONTNAME      = "Arial"
$entSelect.FONTSIZE      = 20
$entSelect.FONTBOLD      = 1
$entselect.CAPTION      = "Services manager"

$fraSelect         = $FORM1.Frame("")
$fraSelect.HEIGHT       = 500
$fraSelect.Left       = 8
$fraSelect.TOP       = 80
$fraSelect.WIDTH       = 870

;----------------------- Computer search ---------------------------

$lblComputer         = $fraSelect.Label
$lblComputer.CAPTION   = "Computer:"
$lblComputer.HEIGHT      = 20
$lblComputer.WIDTH      = 80
$lblComputer.Left      = 10
$lblComputer.TOP      = 20

$txtComputer         = $fraSelect.ComboBox
$txtComputer.HEIGHT      = 310
$txtComputer.Left      = 10
$txtComputer.TOP      = 40
$txtComputer.Text      = ""
$txtComputer.WIDTH      = 110
$txtComputer.Style      = 2
$txtcomputer.locked      = 1
$txtcomputer.FONTNAME   = "Fixedsys"
$txtcomputer.onclick   = "svcstatus()"

$ou=getcomputerlst()
For $Loop=0 to Ubound($ou)
   $txtcomputer.AddItem($ou[$Loop])
Next

;---------------------- srv lst -------------------------

$lblgrpl            = $fraSelect.Label
$lblgrpl.CAPTION      = "Services:"
$lblgrpl.HEIGHT      = 20
$lblgrpl.WIDTH         = 200
$lblgrpl.Left         = 150
$lblgrpl.TOP         = 20

$txtgrpl            = $fraSelect.listBox
$txtgrpl.HEIGHT      = 310
$txtgrpl.Left         = 150
$txtgrpl.TOP         = 40
$txtgrpl.Text         = ""
$txtgrpl.WIDTH         = 700
$txtgrpl.Style         = 2
$txtgrpl.FONTNAME      = "Fixedsys"
$txtgrpl.onclick      = "srvcrecap()"

;---------------------- srv box -------------------------

$servbox            = $fraselect.textbox
$servbox.HEIGHT       = 20
$servbox.Left          = 10
$servbox.TOP          = 390
$servbox.FONTNAME      = "Fixedsys"
$servbox.FONTSIZE      = 10
$servbox.Text          = ""
$servbox.WIDTH       = 220
$servbox.locked       = 1

;----------------------  Buttons -------------------------

$cmdStart             = $fraselect.CommandButton("Start service")
$cmdStart.FONTNAME      = "Arial"
$cmdStart.FONTSIZE      = 10
$cmdStart.FONTBOLD      = 1
$cmdStart.WIDTH      = 129
$cmdStart.HEIGHT      = 20
$cmdStart.TOP         = 460
$cmdStart.Left         = 60
$cmdStart.OnClick      = "SERVICESTART()"
$cmdStart.hide

$cmdStop             = $fraselect.CommandButton("Stop service")
$cmdStop.FONTNAME      = "Arial"
$cmdStop.FONTSIZE      = 10
$cmdStop.FONTBOLD      = 1
$cmdStop.WIDTH         = 129
$cmdStop.HEIGHT      = 20
$cmdStop.TOP         = 460
$cmdStop.Left         = 60
$cmdStop.OnClick      = "SERVICESTOP()"
$cmdStop.hide

$cmdquit             = $fraselect.CommandButton("Exit")
$cmdquit.FONTNAME      = "Arial"
$cmdquit.FONTSIZE      = 10
$cmdquit.FONTBOLD      = 1
$cmdquit.WIDTH         = 129
$cmdquit.HEIGHT      = 20
$cmdquit.TOP         = 460
$cmdquit.Left         = 710
$cmdquit.OnClick      = "quit"

;---------------------- Start mode ------------------------

$framode            = $fraselect.Frame("Start mode")
$framode.HEIGHT       = 130
$framode.Left          = 280
$framode.TOP          = 360
$framode.WIDTH       = 250

$chkboxbo             = $fraselect.checkbox("Boot")
$chkboxbo.TOP         = 390
$chkboxbo.Left         = 300
$chkboxbo.value      = 0
$chkboxbo.onclick      = "chmode('bo')"

$chkboxsy             = $fraselect.checkbox("System")
$chkboxsy.TOP         = 410
$chkboxsy.Left         = 300
$chkboxsy.value      = 0
$chkboxsy.onclick      = "chmode('sy')"

$chkboxau             = $fraselect.checkbox("Automatic")
$chkboxau.TOP         = 430
$chkboxau.Left         = 300
$chkboxau.value      = 0
$chkboxau.onclick      = "chmode('au')"

$chkboxma             = $fraselect.checkbox("Manual")
$chkboxma.TOP         = 390
$chkboxma.Left         = 400
$chkboxma.value      = 0
$chkboxma.onclick      = "chmode('ma')"

$chkboxdi             = $fraselect.checkbox("Disable")
$chkboxdi.TOP         = 410
$chkboxdi.Left         = 400
$chkboxdi.value      = 0
$chkboxdi.onclick      = "chmode('di')"

$cmdvali             = $fraselect.CommandButton("Valid Start mode")
$cmdvali.FONTNAME      = "Arial"
$cmdvali.FONTSIZE      = 10
$cmdvali.FONTBOLD      = 1
$cmdvali.WIDTH         = 129
$cmdvali.HEIGHT      = 20
$cmdvali.TOP         = 460
$cmdvali.Left         = 350
$cmdvali.OnClick      = "validstartmode()"

;---------------------- wait Box -------------------------

$waitbox             = CreateObject("Kixtart.FORM")
$waitbox.CAPTION       = "Admintools"
$waitbox.SCALEHEIGHT    = 80
$waitbox.SCALEWIDTH    = 300
$waitbox.FONTNAME       = "Arial"
$waitbox.FONTSIZE       = 9
$waitbox.CENTER
$waitbox.sysmenu      = 0


$txtwait            = $waitbox.TextBox
$txtwait.HEIGHT       = 19
$txtwait.Left          = 35
$txtwait.TOP          = 20
$txtwait.FONTNAME      = "Arial"
$txtwait.FONTSIZE      = 10
$txtwait.FONTBOLD      = 1
$txtwait.Text          = "Please wait..."
$txtwait.WIDTH       = 220

$proBar             = $waitbox.ProgressBar("")
$probar.Left         = 10
$probar.top         = 50
$probar.width         = 280
$probar.height         = 20
$proBar.Style          = 1

;------------------------- AFFICHAGE ---------------------


$FORM1.Show
While $FORM1.Visible
  $=Execute($FORM1.DoEvents)
Loop


;*****************************************************************************************

Function svcstatus()

  Dim $svcstatus
 
  $txtgrpl.clear
 
  $waitbox.show
  $proBar.Value = 25
 
  $computer=$txtComputer.Text

  $AD=GetObject("WinNT://"+$Computer+",computer")
  $AD.Filter="Service",""

  $co=25
 
  For Each $e in $ad
    $co=$co+1
    $probar.value=$co
   
    If $e.status=4
      $status="Running"
    Else
      $status="Stopped"
    EndIf
 
    $sername=$e.name
    $lon=Len($sername)
    While $lon < 35
      $sername=$sername+"-"
      $lon=Len($sername)
    Loop
 
 
    $line=$line+"**"+$status+"---"+$sername+"-"+$e.displayname
 
  Next
 
  $svcstatus=bsort(Split($line,"**"))
 
  For Each $x in $svcstatus
    If $x<>""
      $txtgrpl.additem($x)
    EndIf
  Next
 
  $waitbox.hide
 
EndFunction

;*****************************************************************************************

Function srvcrecap()

  $cmdStart.hide
  $cmdStop.hide


  $computer=$txtComputer.Text
 
  $line=$txtgrpl.Text

  $pos=InStr($line,"-")
  $status=Left($line,$pos-1)
  $reste=SubStr($line,$pos+3)
  $pos2=InStr($reste,"-")
  $service=Left($reste,$pos2-1)
  $servbox.Text=$service
  If $status="Running"
    $cmdStop.show
  Else
    $cmdStart.show
  EndIf
 
  $mode=servicemode("\\$computer\$service")
 
 
  $chkboxau.value = 0
  $chkboxbo.value = 0
  $chkboxsy.value = 0
  $chkboxma.value = 0
  $chkboxdi.value = 0
 
 
 
  Select
    Case $mode="Automatic"
      $chkboxau.value = 1
    Case $mode="Boot"
      $chkboxbo.value = 1
    Case $mode="System"
      $chkboxsy.value = 1
    Case $mode="Manual"
      $chkboxma.value = 1
    Case $mode="Disabled"
      $chkboxdi.value = 1
  EndSelect
 
EndFunction

;*****************************************************************************************

Function SERVICESTOP()

  $cmdStart.show
  $cmdStop.hide
  $service=$servbox.Text
  $computer=$txtComputer.Text
  Shell "%ComSpec% /c xnet stop \\$Computer\$service"
  MessageBox ("Service $service stopped on $computer", "Services Manager", 0, 10)
  svcstatus()
EndFunction

;*****************************************************************************************

Function SERVICESTART()

  $cmdStart.hide
  $cmdStop.show
  $service=$servbox.Text
  $computer=$txtComputer.Text
  Shell "%ComSpec% /c xnet start \\$Computer\$service"
  MessageBox ("Service $service started on $computer", "Services Manager", 0, 10)
  svcstatus()
EndFunction

;*****************************************************************************************

Function servicemode($servicename, optional $startupmode)
  Dim $servicesubkey, $mode, $currentmode, $startupmodelong, $remoteserver, $regformat, $retcode

  $servicename=Trim($servicename)
  $startupmode=Trim($startupmode)

  If @INWIN<>1
    Exit 1
  EndIf

  If $servicename=''
    Exit 87
  EndIf

  If InStr($servicename,'\')
    $remoteserver=Left($servicename,InStrRev($servicename,'\')-1)
    If Left($remoteserver,2)<>'\\'
      Exit 87
    EndIf
    $servicename=Right($servicename,Len($servicename)-InStrRev($servicename,'\'))
  Else
    $remoteserver=''
  EndIf

  $startupmodelong='Boot,System,Automatic,Manual,Disabled'
  $startupmodelong=Split($startupmodelong,',')

  If VarType($startupmode)
    Select
    Case $startupmode='Boot'
      $mode=0
    Case $startupmode='System'
      $mode=1
    Case $startupmode='Automatic'
      $mode=2
    Case $startupmode='Manual'
      $mode=3
    Case $startupmode='Disabled'
      $mode=4
    Case 1
      $mode=-1
    EndSelect
  Else
    $mode=-1
  EndIf

  $servicesubkey='HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\'+$servicename
  If $remoteserver<>''
    $servicesubkey=$remoteserver+'\'+$servicesubkey
  EndIf


  If KeyExist($servicesubkey)
    $currentmode=ReadValue($servicesubkey,'Start')
   
    Select
    Case $mode=-1
      $servicemode=$startupmodelong[$currentmode]
    Case $mode=$currentmode
      $servicemode=$startupmodelong[$mode]
    Case $mode<>$currentmode
      $regformat=ReadType($servicesubkey,'Start')
      $retcode=WriteValue($servicesubkey,'Start',$mode,$regformat)
      If @ERROR
        Exit @ERROR
      Else
        $servicemode=$startupmodelong[$mode]
      EndIf
    Case 1
      Exit @ERROR
    EndSelect
  Else
    Exit 1060
  EndIf
  Exit @ERROR
EndFunction

;*****************************************************************************************

Function chmode($mode)


  If $mode="bo"
    $chkboxsy.value = 0
    $chkboxau.value = 0
    $chkboxma.value = 0
    $chkboxdi.value = 0
  EndIf
 
  If $mode="sy"
    $chkboxbo.value = 0
    $chkboxau.value = 0
    $chkboxma.value = 0
    $chkboxdi.value = 0
  EndIf
 
  If $mode="au"
    $chkboxbo.value = 0
    $chkboxsy.value = 0
    $chkboxma.value = 0
    $chkboxdi.value = 0
  EndIf
 
  If $mode="ma"
    $chkboxbo.value = 0
    $chkboxsy.value = 0
    $chkboxau.value = 0
    $chkboxdi.value = 0
  EndIf

  If $mode="di"
    $chkboxbo.value = 0
    $chkboxau.value = 0
    $chkboxma.value = 0
    $chkboxsy.value = 0
  EndIf
 
EndFunction

;*****************************************************************************************

Function validstartmode()

  $service=$servbox.Text
  $computer=$txtComputer.Text
 
  Select
 
    Case $chkboxbo.value = 1
      $startmode="Boot"
 
    Case $chkboxsy.value = 1
      $startmode="System"

    Case $chkboxau.value = 1
      $startmode="Automatic"
     
    Case $chkboxma.value = 1
      $startmode="Manual"
   
    Case $chkboxdi.value = 1
      $startmode="Disabled"
  EndSelect


  servicemode("\\$computer\$service",$startmode)
 
  MessageBox ("The Start mode of $service on $computer is set to [$startmode]", "Services Manager", 0, 10)

EndFunction

;*****************************************************************************************

Function getcomputerlst()

  $tempfile="c:\temp\computer_lst.txt"
  Del $tempfile

  Shell '%Comspec% /C net view >$tempfile'

  $=Open(3,$tempfile)

  $computer = ReadLine(3)
  While @error = 0
    $computer = ReadLine(3)
    If InStr($computer,"\\")<>0
       $computer=Right($computer,Len($computer)-2)
       $pos=InStr($computer," ")
       $computer=Left($computer,$pos-1)
       $colst=$colst+"~~"+$computer
    EndIf
  Loop
  $=Close(3)

  $getcomputerlst=Split($colst,"~~")

EndFunction

;*****************************************************************************************

Function bsort($array, optional $order)

  Dim $i,$j,$m
  If Ubound($array)
    For $i = 0 to Ubound($array)
      $m = $array[$i]
      For $j = $i + 1 to Ubound($array)
        If ($array[$j] < $m AND NOT $order) OR ($array[$j] > $m AND $order)
          $m = $array[$j]
          $array[$j] = $array[$i]
          $array[$i] = $m
        EndIf
      Next
    Next
    $bsort = $array
  Else
    $bsort = 0
  EndIf
 
EndFunction

_________________
There is no stupid question. Whoever seeks is never stupid because he will know ...
Bruno.
Back to top
View user's profile Send private message
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Tue May 20, 2003 1:32 pm    Post subject: Reply with quote

getcomputerlst() can be replaced with COMNetView() form kixtart.org, in the UDF Forum.

Please read the thread about deploying the KiXforms DLL as you're way is just plain bad with regards to versioning, permissions, and registering COM objects.

_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Chris S.
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 241

PostPosted: Tue May 20, 2003 4:55 pm    Post subject: Reply with quote

Endless loop alert!!!

Code:

:top
$FORM1 = CreateObject("Kixtart.FORM")
If NOT $form1
   Copy ".\kixforms.dll" %windir%
   Shell 'regsvr32 /s %windir%\kixforms.dll'
   Goto top
EndIf

If the user doesn't have the permisions to register the DLL he is stuck in an endless loop.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group