Page 1 of 1 1
Topic Options
#51413 - 2000-09-13 03:28 PM OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gang:

I'm having so much fun programming these Internet Explorer scripts, it should be illegal.

If you've got Windows 2000 and Internet Explorer, I encourage you to give this script a try ...


The following will browse all services on your workstation, then give you the ability to start and stop them.

I'm experimenting with different naming schemes and script layouts. I modeled this along the lines of how a Visual Basic program would work.

Because KiX doesn't support ActiveX event handling (yet), one has to build one's own event dispatcher to simulate them (a fancy name for a case statement).

I also got lazy and started plugging the embedded HTML right into the olecallfunc().

This script also demonstrates how to use "Dynamic HTML" to generate HTML "on the fly" (see: building the services dropdown).


WARNING - THIS SCRIPT REALLY WORKS SO WATCH CAREFULLY WHAT YOU START AND STOP

As always, looking forward to your feedback...


code:

;
; SERVICE.KIX
;
; REQUIRES: WINDOWS 2000 & INTERNET EXPLORER
;
; AUTHOR: Shawn and the "Gang" at http://www.kixtart.org
;


break on


$computer = "@wksta"
$program = "SERVICE"
$title = "SERVICE BROWSER"
$top = "100"
$left = "200"
$height = "450"
$width = "500"
$sleep = 1
$crlf = chr(13)+chr(10)


$false = 0
$true = -1


;====
:init
;====


gosub HTML
gosub formLoad
gosub computerChange
gosub serviceChange
gosub eventDispatch
gosub formUnload


exit


;=============
:eventDispatch
;=============


$= oleputproperty( $ie, "visible", "s", "$true")
while olegetproperty ( $ie, "visible" ) = 0 and @error = 0 loop
$= setfocus ( "$program" )


while @error = 0


sleep $sleep


; Get form event ...


$event = olegetproperty ( $frmEvent, "value" )


if $event <> "0"


select


case $event = "1" ; SERVICE CHANGE


gosub serviceChange


case $event = "2" ; REFRESH


gosub serviceChange


case $event = "3" ; START


gosub startClick
gosub serviceChange


case $event = "4" ; STOP


gosub stopClick
gosub serviceChange


case $event = "5" ; PAUSE


gosub pauseClick
gosub serviceChange


case $event = "6" ; RESUME


gosub resumeClick
gosub serviceChange


case $event = "7" ; COMPUTER


gosub computerChange
gosub serviceChange


case $event = "-1" ; CLOSE


return


endselect


$= oleputproperty ( $frmEvent, "value", "s", "0" )


endif


loop


return


;=============
:serviceChange
;=============


; Set service properties to blank for warm and fuzzy


$= oleputproperty ( $frmDescription, "value", "s", "" )
$= oleputproperty ( $frmState, "value", "s", "" )
$= oleputproperty ( $frmStatus, "value", "s", "" )
$= oleputproperty ( $frmProcId, "value", "s", "" )
$= oleputproperty ( $frmServType, "value", "s", "" )


gosub serviceQuery


if $service


$description = olegetproperty($service,"displayName")
$state = olegetproperty($service,"state")
$status = olegetproperty($service,"status")
$processId = olegetproperty($service,"processId")
$serviceType = olegetproperty($service,"serviceType")


$= oleputproperty ( $frmDescription, "value", "s", "$description" )
$= oleputproperty ( $frmState, "value", "s", "$state" )
$= oleputproperty ( $frmStatus, "value", "s", "$status" )
$= oleputproperty ( $frmProcId, "value", "s", "$processId" )
$= oleputproperty ( $frmServType, "value", "s", "$serviceType" )


$= olereleaseobject ( $service )


endif


return


;=========
:stopClick
;=========


gosub serviceQuery


if $service


$= olecallfunc ( $service, "stopService" )


$= olereleaseobject ( $service )


endif


return


;==========
:startClick
;==========


gosub serviceQuery


if $service


$= olecallfunc ( $service, "startService" )


$= olereleaseobject ( $service )


endif


return


;==========
:pauseClick
;==========


gosub serviceQuery


if $service


$= olecallfunc ( $service, "pauseService" )
$= olereleaseobject ( $service )


endif


return


;===========
:resumeClick
;===========


gosub serviceQuery


if $service


$= olecallfunc ( $service, "resumeService" )
$= olereleaseobject ( $service )


endif


return


;==============
:computerChange
;==============


$oldComputer = $computer
$oldWmi = $wmi


$computer = ucase(olegetproperty ( $frmComputer, "value" ))


if $computer
$= oleputproperty ( $frmComputer, "value", "s", "$computer" )
else
$computer = "@wksta"
$= oleputproperty ( $frmComputer, "value", "s", "$computer" )
endif


$wmi = olegetobject ( 0, "winmgmts:{impersonationLevel=impersonate}!//$computer" )


if @error
$computer = $oldComputer
$= oleputproperty ( $frmComputer, "value", "s", "$computer" )
$wmi = $oldWmi
return
endif


$= oleputproperty ( $frmServices, "innerHTML", "s", "<select></select>" )


$select = 'select * from Win32_Service'


$query = val ( "&" + olecallfunc ( $wmi, "execquery", "s", "$select" ))


$enumeration = oleenumobject ( $query )


$service = oleenumobject ( $query, $enumeration )


$dhtml = '<select id=mService onchange="mEvent.value=1" size=1>$crlf'


while @error = 0


$name = olegetproperty ( $service, "name" )
$displayName = olegetproperty ( $service, "displayName" )


$dhtml = $dhtml + '<option id=1 value="$name">$displayName</option>$crlf'


$rs = olereleaseobject ( $service )


$service = oleenumobject ( $query, $enumeration )


loop


$dhtml = $dhtml + '</select>$crlf'


$= oleputproperty ( $frmServices, "innerHTML", "s", "$dhtml" )


if $frmService
$= olereleaseobject ( $frmService )
endif


$frmService = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mService" ))


$= olereleaseobject ( $query )
$= olereleaseobject ( $collection )


return


;========
:formLoad
;========


; Create instance of Internet Explorer ...


$ie = olecreateobject("internetexplorer.application")


; Set properties and display form ...


$nul = oleputproperty ($ie, "addressbar","s","$false")
$nul = oleputproperty ($ie, "menubar", "s", "$false")
$nul = oleputproperty ($ie, "toolbar", "s", "$false")
$nul = oleputproperty ($ie, "statusbar", "s", "$false")
$nul = oleputproperty ($ie, "top", "s", "$top")
$nul = oleputproperty ($ie, "left", "s", "$left")
$nul = oleputproperty ($ie, "height", "s", "$height")
$nul = oleputproperty ($ie, "width", "s", "$width")
$nul = olecallfunc ($ie, "navigate", "s", "about:blank")


; Wait for Internet Explorer to naviate ...


while olegetproperty($ie, "busy") <> "0" and @error = 0 loop


; Get a handle to the active document ...


$doc = val("&" + olegetproperty($ie, "document"))


$nul = olecallfunc($doc, "write", "s", "$htmlForm" )


; Get a handle to the form controls ...


$frmEvent = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mEvent" ))
$frmComputer = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mComputer" ))
$frmServices = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mServices" ))
$frmState = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mState" ))
$frmStatus = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mStatus" ))
$frmProcId = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mProcId" ))
$frmServType = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mServType" ))
$frmDescription = val ( "&" + olecallfunc ( $doc, "getElementById", "s", "mDescription" ))


$= oleputproperty ( $frmComputer, "value", "s", "$computer" )


return


;==========
:formUnload
;==========


if ( $ie )
$= olecallfunc ( $ie, "quit" )
$= olereleaseobject ( $ie )
endif


if ( $wmi )
$= olereleaseobject ( $wmi )
endif


return


;============
:serviceQuery
;============


$name = olegetproperty ( $frmService, "value" )


$select = 'select * from Win32_Service where name="$name"'


$query = val ( "&" + olecallfunc ( $wmi, "execquery", "s", "$select" ))


$enumeration = oleenumobject ( $query )


$service = oleenumobject ( $query, $enumeration )


$= olereleaseobject ( $enumeration )
$= olereleaseobject ( $query )


return


;====
:HTML
;====


$htmlForm = '
<html>
<head>
<title>$program</title>
<h4 align=center><strong>$title</strong></h4>
<h6 align=center>
<strong>
KiXtart Version @KIX<br>
Powered by Microsoft Windows 2000 and Internet Explorer
</strong>
</h6>
<style>
<!---body {
background-color: powderblue; color: black;
font-family: arial; font-size: 10pt; margin: 3px
input.tbox { border: lpx black solid; font: 10pt arial}
td { font: 10pt arial; }
}
--->
</style>
</head>
<body scroll=no>
<input type=hidden id=mEvent name=mEvent value=0>
<table align=center>
<tr>
<td>Computer:<td><input id=mComputer type=tbox>
<input type=button value="Connect" onclick="mEvent.value=7"></td>
<tr>
<td>Service:</td>
<td id=mServices>
<select onchange="mEvent.value=1" size=1>
<select></select>
</td>
<br>
<tr><td>State: <td><input id=mState type=tbox disabled></td>
<tr><td>Status: <td><input id=mStatus type=tbox disabled></td>
<tr><td>ProcessId: <td><input id=mProcId type=tbox disabled></td>
<tr><td>ServiceType:<td><input id=mServType type=tbox disabled></td>
</table>
<br>
<table align=center>
<td><input type=button value="Refresh" onclick="mEvent.value=2"></td>
<td><input type=button value=" Start " onclick="mEvent.value=3"></td>
<td><input type=button value=" Stop " onclick="mEvent.value=4"></td>
<td><input type=button value=" Pause " onclick="mEvent.value=5"></td>
<td><input type=button value=" Resume" onclick="mEvent.value=6"></td>
<td><input type=button value=" Close " onclick="mEvent.value=-1"></td>
</table>
<br><hr>
<h6 align=center>
For questions or feedback concerning this utility, please contact
<br>
<a href="http://www.kixtart.org">The KiXtart Bulletin Board</a>
</h6>
</body>
</html>
'


return


Shawn.

[This message has been edited by Shawn (edited 15 September 2000).]

Top
#51414 - 2000-09-13 04:35 PM Re: OLE/WMI - Service Browser for Windows 2000
Anonymous
Unregistered


[Ramon is in awe of the raw power demonstrated - and now lives in fear of being crushed by the sun, if Shawn ever decides to script the earth into it... ]

This is the one script that has convinced me to skip rigth to the OLE part of my visual basic book, Shawn! I just love the simplicity of it all and I think I'm just inches away of grasping the concept only, I haven't been able to put any decent time into it the last two weeks. But I most definately will soon... Feedback you ask? This one is gorgeous!

Top
#51415 - 2000-09-13 06:31 PM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Already thinkin 'bout some "small" enhancements...

1) Implement "Pause" button

2) Add a network dropdown list to support remote Windows 2000 workstations and servers.

3) Include ADSI support for legacy Windows NT machines (browsing-only)

4) Maybe add some new display properties like "startup type" and "logon as".

5) Real-time status refresh - some services won't start even with computer manager.

The list goes on and on...

Shawn.

[This message has been edited by Shawn (edited 13 September 2000).]

Top
#51416 - 2000-09-14 08:23 PM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Gang:

Implemented the "Pause" and "Resume" feature.

Not all services can be paused. The Workstation service can be paused.

Made some procedural and cosmetic changes !

I'm going to try and implement remote service management using Active Directory.

Good opportunity to try out multi-document forms with Internet Explorer !

Stay tuned !

Shawn.

[This message has been edited by Shawn (edited 14 September 2000).]

Top
#51417 - 2000-09-15 12:28 AM Re: OLE/WMI - Service Browser for Windows 2000
Anonymous
Unregistered


Hey Shawn,

Great utility. I have one suggestion. If you set the text box thingy's to DISABLED, then the user won't be able to change any of the values that come up for the service. For instance:

<tr><td>ServiceType:<td><input id=mServType type=tbox DISABLED></td>

Roneil

Top
#51418 - 2000-09-15 07:31 PM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Icatar:

Great tip ... done !

Gang:

This script is getting hairy !


Posted new version of above. Allows one to connect to a remote Windows 2000 machine !

Having lot's of fun with this one. Me and my buddy are disabling each other's "Network Associates McShield" service which causes the red stop sign to appear in the icon tray.

Lot's of larfs !

Shawn.

Top
#51419 - 2001-03-14 08:30 AM Re: OLE/WMI - Service Browser for Windows 2000
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Shawn,

this kix ass!

cj

------------------
For more scripts goto my website and click the hammer and spanner icon.

chrismat@ozemail.com.au

Top
#51420 - 2001-08-01 07:41 PM Re: OLE/WMI - Service Browser for Windows 2000
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Shawn.. This is great. How many more old posts do you have with good stuff like this?

The only change I recommend is to have it open this thread in a new window.

code:
<A HREF="http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=2&t=000740" TARGET="_blank">The KiXtart Bulletin Board</a>  

Otherwise when it opens you have no menu or method to go back.

Top
#51421 - 2001-08-02 06:05 AM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Doc,

Here's some xmas fun Bryce and I had a while back. I'm a huge ascii-art fan and this script uses a high tech, super advanced technique called KiXtart ASCIImation (tm)

Merry Christmas Kixters !

Here's another fun script - I thought maybe Lonkero might get around to using innerhtml in his webbot ... the link that this script points to is probably out-of-date though, if anyone wants - I can refresh ...

OLE/IE Stock Quotes - The inner beauty of innerHTML

The MSAgent agent scripts had the board in stitches for days - that was a great diversion. Sure - just lots of toys - but it's amazing what neat ideas have evolved through board discussion around these things ... Paul used the innerhtml idea to send telemetry data to an ASP page he setup in his Intranet - I always though he was on to something there (eg, login script "posts" HTML data to central inventory server) but I haven't heard much from him of late ...

-Shawn

p.s. Looks as if the Stock link is still ok - but they've probably changed the "innerhtml" so the parsing might be off - and I'm running Windows 98 right now and of course - KiXtart 3.63 COM is totally busted on here

[ 02 August 2001: Message edited by: Shawn ]

Top
#51422 - 2001-08-02 09:57 AM Re: OLE/WMI - Service Browser for Windows 2000
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
heh, I printed it out and go to see it in more depth at smoking area...
I just wonder, I've understood that OLE is a old thingie which is needed anymore directly in kix because we have COM. and still, the way you do your script, I wouldn't bury OLE functions.
well. Do I understand or not does not matter as long as you keep throwing us with these wonderfull (and yes, even usefull) scripts.
_________________________
!

download KiXnet

Top
#51423 - 2001-08-02 03:55 PM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Lonkero

Your right - the olde OLE functions were neat because they were really stupid (I mean that in a good way). Because they were so basic - nothing ever really broke and they ran flawlessly. Although to be honest - they were "lacking" in some important ways - like support for VB enumerations (FOR EACH) and such... I like the new COM much, much better ...

I've noticed that the "download" from this bulliten board has become unbearable - I dl'd the xmas script back to me and the formatting got totally screwed-up (even when using wordpad) ... if anyone wants - drop me an email and I'll send it to yeh ! We need to get that edit post feature back !!!

-Shawn

p.s. I noticed the stock quote script still works - don't you just love web pages that keep some sort of consistency ?

[ 02 August 2001: Message edited by: Shawn ]

Top
#51424 - 2001-08-02 05:04 PM Re: OLE/WMI - Service Browser for Windows 2000
masken Offline
MM club member
*****

Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
CooooOoool Shawn!

Very impressive!

_________________________
The tart is out there

Top
#51425 - 2001-08-02 07:04 PM Re: OLE/WMI - Service Browser for Windows 2000
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Shawn,

This rocks!

Any plans to port to 2001?

Thanks!

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#51426 - 2001-08-02 10:04 PM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Kent,

I'll be cooking this fish in one of the frying pans I have on the back burner

-Shawn

Top
#51427 - 2001-08-03 06:54 PM Re: OLE/WMI - Service Browser for Windows 2000
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Shawn,

I need some "KIX Schooling!"

What are the KIX2001 equivalents to -

code:

olegetproperty
oleputproperty
olegetobject
oleenumobject
olecallfunc

??

Thanks!

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#51428 - 2001-08-03 08:40 PM Re: OLE/WMI - Service Browser for Windows 2000
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Sure thing Kent. Using the above script as an example:

olegetproperty

$event = olegetproperty ( $frmEvent, "value" )

$event = $frmEvent.value

oleputproperty

$= oleputproperty( $ie, "visible", "s", "$true")

$ie.visible = "$true" ; or...
$ie.visible = 1

olegetobject

$wmi = olegetobject ( 0, "winmgmts:{impersonationLevel=impersonate}!//$computer" )

$wmi = getobject("winmgmts:{impersonationLevel=impersonate}!//$computer" )

oleenumobject

$enumeration = oleenumobject ( $query )

for each $object in $query ...

olecallfunc

$= olecallfunc ( $service, "stopService" )

$service.stopService()

-Shawn

[ 03 August 2001: Message edited by: Shawn ]

Top
#51429 - 2001-08-04 01:44 AM Re: OLE/WMI - Service Browser for Windows 2000
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Shawn,

Uh.. yields..

>>> Kixtart 2001 <<<
Script error : expected expression !
$nul = oleputproperty($ie, "addressbar","s","$false")

;;$ie = OleCreateObject("internetexplorer.application")
$ie = CreateObject("internetexplorer.application") ;<--- Line 271

; Set properties and display form ...

$nul = OlePutProperty($ie, "addressbar","s","$false") ;<--- Line 276

Hmm...

- Kent

_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 823 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.078 seconds in which 0.03 seconds were spent on a total of 12 queries. Zlib compression enabled.

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