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

ServiceMgmt() - Service Manager

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


Joined: 05 Mar 2003
Posts: 76
Location: Philadelphia, PA

PostPosted: Fri Apr 25, 2003 3:18 pm    Post subject: ServiceMgmt() - Service Manager Reply with quote

Howdy! Here's a service manager that I've been working on.

I'll be releasing several other 'modules' to replace/enhance existing microsoft garbage. Anyhow, they'll all come out in function form due to how I'm using them collectively.

Thanks to Shawn and the community for help with the listview syntax.

Code:

;FUNCTION         ServiceMgmt($Comp)
;
;AUTHOR           Jim Tokach
;
;ACTION           Replacement for the Microsoft supplied service control panel
;
;SYNTAX           ServiceMgmt($Comp)
;
;PARAMETERS       $Comp (Required) [String]
;                    The hostname of the computer to manage services on.
;
;REMARKS          None
;
;RETURNS          Nothing
;
;DEPENDENCIES     Kixtart 4.20
;                 KixForms 2.3.0.38
;                 WMI
;
;EXAMPLES         ServiceMgmt(@wksta)

; Unremark the following line to run locally
;ServiceMgmt(@wksta)

Function ServiceMgmt($Comp)
    $frmServices = CreateObject("Kixtart.Form")
    $frmServices.ClientSize = 600,382
   
    $frmServices.Text="Service Manager for $Comp"

    Dim $l,$t,$w,$h
    $l=24
    $t=30
    $w=91
    $h=24

    $fraTools= $frmServices.frame("Service Management",10,10,$frmServices.ClientWidth-22,54)
    $fraTools.fontbold=1

    $refresh = $frmServices.button("Refresh All",$l,$t,$w,$h)
    $refresh.onclick = "refresh_click($Comp)"
    $refresh.setasdefault
   
    $refreshSrvc = $frmServices.button("Refresh Service",$Refresh.right,$t,$w,$h)
    $refreshSrvc.onclick = "refresh_srvc_click($Comp)"

    $start = $frmServices.button("Start",$RefreshSrvc.right,$t,$w,$h)
    $start.onclick = "start_click($Comp)"
   
    $stop = $frmServices.button("Stop",$start.right,$t,$w,$h)
    $stop.onclick = "stop_click($Comp)"
   
    $continue = $frmServices.button("Continue",$stop.right,$t,$w,$h)
    $continue.onclick = "continue_click($Comp)"
   
    $pause = $frmServices.button("Pause",$continue.right,$t,$w,$h)
    $pause.onclick = "pause_click($Comp)"

    $lstServices = $frmServices.ListView()
    $lstServices.FontSize=8
    $lstServices.FontName="Tahoma"
    $lstServices.Left = 10
    $lstServices.Top = 72
    $lstServices.Width = $frmServices.ClientWidth-22
    $lstServices.Height = 297
   
    $lstServices.SmallImageList = $frmServices.ImageList
    $lstServices.SmallImageList.Images.Add($frmServices.SmallImageList.Images(33)) ;Red     0
    $lstServices.SmallImageList.Images.Add($frmServices.SmallImageList.Images(53)) ;Yellow  1
    $lstServices.SmallImageList.Images.Add($frmServices.SmallImageList.Images(34)) ;Green   2
    $lstServices.SmallImageList.Images.Add($frmServices.SmallImageList.Images(32)) ;Black   3
    $lstServices.SmallImageList.Images.Add($frmServices.SmallImageList.Images(35)) ;Blue    4
    $lstServices.SmallImageList.Images.Add($frmServices.SmallImageList.Images(37)) ;X       5

    ;$lstServices.SmallImageList = $frmServices.SmallImageList
    $lstServices.OnCLick = "getcurrentservice()"
    $lstServices.Sorted = 1
    $lstServices.View = 3
    $lstServices.FullRowSelect = 1

    $=$lstServices.Columns.Add("Service",200)
    $=$lstServices.Columns.Add("Name",100)
    $=$lstServices.Columns.Add("Status",75)
    $=$lstServices.Columns.Add("Startup Type",75)
    $=$lstServices.Columns.Add("Log On As",100)
    $=$lstServices.Columns.Add("Path",205)

    SupplySrvc($Comp)
    $frmServices.Center
    $frmServices.Show
   
    While $frmServices.Visible
     $= Execute($frmServices.DoEvents)
    Loop

$frmServices=0
EndFunction


;/////////////////////////////////////////

Function Start_Click($Comp)
   $frmServices.MousePointer = 11
    $CurrentService.StartService()
   Sleep 2
   Update_Service($Comp)
   $frmServices.MousePointer = 0
EndFunction

Function Stop_Click($Comp)
    $frmServices.MousePointer = 11
   $CurrentService.StopService()
   Sleep 2
   Update_Service($Comp)
   $frmServices.MousePointer = 0
EndFunction

Function Pause_Click($Comp)
    $frmServices.MousePointer = 11
   $CurrentService.PauseService()
   Sleep 2
   Update_Service($Comp)
   $frmServices.MousePointer = 0
EndFunction

Function Continue_Click($Comp)
    $frmServices.MousePointer = 11
   $CurrentService.ResumeService()
   Sleep 2
   Update_Service($Comp)
   $frmServices.MousePointer = 0
EndFunction

Function Update_Service($Comp)
    $Connect = GetObject("winmgmts:{impersonationLevel=impersonate}!//$Comp")
    $Services = $Connect.instancesof("Win32_Service")
    GetCurrentService()
    Select
        Case $CurrentService.StartMode="Disabled"   $v=3
        Case $CurrentService.State="Stopped"        $v=0
        Case $CurrentService.State="Paused"         $v=1
        Case $CurrentService.State="Running"        $v=2
        Case 1 $v=4
    EndSelect
    $lstServices.FocusedItem.subitems(0).ImageIndex=$v
    $lstServices.FocusedItem.SubItems(0).Text=$CurrentService.DisplayName
    $lstServices.FocusedItem.SubItems(1).Text=$CurrentService.Name
    $lstServices.FocusedItem.SubItems(2).Text=$CurrentService.State
    $lstServices.FocusedItem.SubItems(3).Text=$CurrentService.StartMode
    $lstServices.FocusedItem.SubItems(4).Text=$CurrentService.StartName
    $lstServices.FocusedItem.SubItems(5).Text=$CurrentService.PathName
    $lstServices.SetFocus
EndFunction

Function Refresh_Click($Comp)
   SupplySrvc($Comp)
EndFunction

Function Refresh_Srvc_Click($Comp)
   Update_Service($Comp)
EndFunction

Function SupplySrvc($Comp)
    Dim $Service,$v
    $frmServices.MousePointer = 11
    $=$lstServices.Items.Clear
    $Connect = GetObject("winmgmts:{impersonationLevel=impersonate}!//$Comp")
    $Services = $Connect.instancesof("Win32_Service")
    For Each $Service in $Services
        Select
            Case $Service.StartMode="Disabled"  $v=3
            Case $Service.State="Stopped"       $v=0
            Case $Service.State="Paused"        $v=1
            Case $Service.State="Running"       $v=2
            Case 1 $v=4
        EndSelect

        ;$Item = $lstServices.Items.Add("",$v)
        ;$Item.SubItems(0).Text = $Service.DisplayName
        $Item = $lstServices.Items.Add($Service.DisplayName,$v)
        $Item.SubItems(1).Text = $Service.Name
        $Item.SubItems(2).Text = $Service.State
        $Item.SubItems(3).Text = $Service.StartMode
        $Item.SubItems(4).Text = $Service.StartName
        $Item.SubItems(5).Text = $Service.PathName
    Next
    $frmServices.MousePointer = 0
EndFunction

Function getcurrentservice()
    Dim $i
    For Each $i in $services
        If $i.name=$lstServices.FocusedItem.SubItems(1).Text
            If $i.AcceptPause=0
                $Pause.Enabled=0
                $Continue.Enabled=0
            Else
                $Pause.Enabled=1
                $Continue.Enabled=1
            EndIf
            $CurrentService=$i
        EndIf
    Next
EndFunction
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Apr 25, 2003 7:03 pm    Post subject: Reply with quote

love it - very professional looking. how about adding resizability for a stretchy listview ?

-Shawn
Back to top
View user's profile Send private message
jim
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 76
Location: Philadelphia, PA

PostPosted: Fri Apr 25, 2003 7:13 pm    Post subject: Reply with quote

Thanks!

Yeah, I've been meaning to get around to that. Haven't learned the anchor prop. yet and not familiar with the other resizable code. I'll take a deeper look at the kixpad code and stop making excusses.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Apr 25, 2003 7:17 pm    Post subject: Reply with quote

May have seen already but I just posted the docs for the Anchor and FormBorderStyle props over here
Back to top
View user's profile Send private message
jim
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 76
Location: Philadelphia, PA

PostPosted: Fri Apr 25, 2003 7:35 pm    Post subject: Reply with quote

Great! Simple enough. This is where lack of formal training on form designing hurts. What do you suggest I do with the frame and buttons?

If just the listview were to expand, the frame wouldn't match.

If I resize the frame and buts, the buttons would look ridiculous at 300p wide each.

Not like you have the time, but do you have any reference on "Form Design 101 - Designing for the resizablly challenged"? Wink Seriously though, any basics would help me and probably the community design more intuitive, functioning forms.
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Apr 25, 2003 7:57 pm    Post subject: Reply with quote

Im not aware of any reference material off the top of my head, and to be honest, i suck at designing forms - it seems to be either something you got or something you dont got - and i always thought you got it.

In terms of the service manager, i might go with something like this (using the beta):

$frmServices.BorderStyle = 2
$frmServices.MinimumSize = $frmServices.Size

...

$fraTools.Anchor = 1+4

...

$lstServices.Anchor = 15

...

Just my two cents, not much really you can do with those buttons like you said ...

-Shawn

Sorry, if using the Beta could do that or this:

$Form.FormBorderStyle = 4

either one works ... the Beta that is there now has some issues that have been fixed, to do with disabled child forms, has been fixed and the new beta will be issued this weekend.

-Shawn
Back to top
View user's profile Send private message
jim
KiXforms Supporter
KiXforms Supporter


Joined: 05 Mar 2003
Posts: 76
Location: Philadelphia, PA

PostPosted: Fri Apr 25, 2003 8:06 pm    Post subject: Reply with quote

Can you stop a form from resizing beyond a certain point, particularly inward. The frame expansion doesn't look bad going outward, but when you make the form shrink to 100x100, the frame chops the buttons and most of the buttons are cut out any way.

With the advnet of the toolbar control, the buttons issue should work itself out (read: the buts will no longer be required for this function. Can I get a halleluiah? I said, can I get a halleluiah?!!!) and resizing below the last button will present chevron >> to access the unseen. Or am I dreaming. =)
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Fri Apr 25, 2003 8:10 pm    Post subject: Reply with quote

The ToolBar control will make all this stuff go away to be sure. Think for the current beta, i mistakenly called MinimumSize as MinSize, so might try that instead (you have mail).

In terms of the Frame, if using the Beta - I would scrap the Frame altogether and use the GroupBox object - just find/replace the string Frame with GroupBox ! The GroupBox functions much better in the resizable world ! Plus its got some extra goodies and will have more down the road ...

-Shawn
Back to top
View user's profile Send private message
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