Page 1 of 1 1
Topic Options
#85696 - 2002-05-16 06:13 PM WMI OS classes (Networking)
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I've been struggling with this for awhile...

Can someone post an example of how to use Networking classes like:

Win32_ActiveRoute, Win32_NetworkConnection, Win32_NTDomain, and Win32_PingStatus?

If a class does not support enumeration (Win32_PingStatus), can it still be of any use in KiXtart?

I'm not working on a specific project.. but just tooling around with COM objects and KiXtart -- especially ADSI and WMI...

Brian

Top
#85697 - 2002-05-16 08:56 PM Re: WMI OS classes (Networking)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
Here's a quicky port of script:

break on

for each $process in getobject("winmgmts:").instancesof("win32_networkconnection")
 ?
 ?"Name: " $process.name
 ?"Status: "$process.status
next

exit 1


-Shawn

Top
#85698 - 2002-05-16 09:01 PM Re: WMI OS classes (Networking)
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
That's excellent.. How can you do something like that for the Win32_PingStatus. I guess what I don't understand about the Win32_PingStatus is that what it actually does. It appears (from documentation) that it returns the same information as a PING would, but do you have to create an instance to get it to work? That brings me to another question.. is it possible with Win32_NetworkConnection to create a new instance that opens a network connection?

Brian

P.S. Maybe my problem is dealing with the GetQueryAsync method.. I need to have some sort of sink defined? This is where I get confused...

[ 16 May 2002, 21:26: Message edited by: BrianTX ]

Top
#85699 - 2002-05-16 10:36 PM Re: WMI OS classes (Networking)
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
How can you do this in kixtart? This lists all instances of processes in VBScript.

code:
set oSink = WScript.CreateObject("wbemscripting.swbemsink","sink_")
set oSvc = GetObject("winmgmts:root\cimv2")
bdone = false
osvc.ExecQueryAsync oSink, "SELECT Name FROM Win32_Process"
while not bdone
wscript.sleep 1000
wend
sub sink_OnObjectReady(oInst, octx)
WScript.Echo "Got Instance: " & oInst.Name
end sub
sub sink_OnCompleted(HResult, oErr, oCtx)
WScript.Echo "ExecQueryAsync completed"
bdone = true
end sub

Brian

[ 16 May 2002, 22:37: Message edited by: BrianTX ]

Top
#85700 - 2002-05-16 11:31 PM Re: WMI OS classes (Networking)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
Brian - does it have to be the asynchronous version like you've posted. If not, just replace the class string in the createobject. If yes, I'm afraid your out-of-luck because Kixtart doesn't support ActiveX event handling (sadly) [Frown]

break on

for each $process in getobject("winmgmts:").instancesof("win32_process")
 ?"Name: " $process.name
next

exit 1


-Shawn

Top
#85701 - 2002-05-16 11:53 PM Re: WMI OS classes (Networking)
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Hmm. no ActiveX event handling, eh? Some classes ONLY support asynchronous operation (i.e. event handling) -- (Win32_PingStatus is one)... so it's a little difficult to use them in that situation.

This brings me to another question... Can a .dll objects be referenced in KiXtart through WINMGMTS? I was wondering if there was a way to do this...

Brian

(Would it be worthwhile to put ActiveX event handling into the suggestion box?)...

P.S. Generically, the reason I got into this is I was trying to find an alternative to the "PING" command from the command prompt without having to use an alternate PING utility. The reason for this is that the "PING" utility fails if the computer name starts with a zero..

0038625 will resolve to 0.0.65.149 If sent directly to ping.exe. Alternately, I suppose there may be a utility to resolve the hostname prior to pinging it.. ? But, I was going to see if there was a solution to this using COM objects and KIX.. thus far I haven't found one.

[ 16 May 2002, 23:59: Message edited by: BrianTX ]

Top
#85702 - 2002-05-17 12:04 AM Re: WMI OS classes (Networking)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
I'm working on the pingstatus thingy now. There are hardly any docs anywhere on this thing (arggg) no mention at all in the WMI SDK !!! Here's what I've managed to bodge together so far ... I'm on a stand-alone machine here so I really can't test ...

Is this a roll-your-own ping command ?

break on

$query = "select * from win32_pingstatus where address = '@WKSTA' and buffersize=2345678"

for $i = 0 to 10
 $ping = getobject("winmgmts:").execquery("$query")
 for each $stat in $ping
  ?"Reply from " $stat.protocoladdress " bytes=" $stat.buffersize " time=" $stat.responsetime
 next
next

exit 1


win32_pingstatus only works on xp to the best of my knowledge (according to MSDN) ... can you give it a go ? Heres the only hit on MSDN:

Win32_PingStatus

-Shawn

[ 17 May 2002, 01:13: Message edited by: Shawn ]

Top
#85703 - 2002-05-17 01:47 AM Re: WMI OS classes (Networking)
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11548
Loc: CA
Brian,

Not sure if any of this helps... but here is about the only other information I could find that you and Shawn have not already found.

Whistler'а (aka Windows XP):
* Win32_ActiveRoute
* Win32_CollectionStatistics
* Win32_ComputerShutdownEvent
* Win32_ConnectionShare
* Win32_DfsLink
* Win32_DfsLinkReplica
* Win32_DfsReplica
* Win32_DiskQuota
* Win32_IP4PersistedRouteTable
* Win32_IP4RouteTable
* Win32_IP4RouteTableEvent
* Win32_JobObjectEvent
* Win32_LUID
* Win32_LUIDandAttribute
* Win32_ModuleLoadTrace
* Win32_ModuleTrace
* Win32_NamedJobObject
* Win32_NamedJobObjectActgInfo
* Win32_NamedJobObjectLimit
* Win32_NamedJobObjectLimitSetting
* Win32_NamedJobObjectProcess
* Win32_NamedJobObjectSecLimit
* Win32_NamedJobObjectSecLimitSetting
* Win32_NamedJobObjectStatistics
* Win32_PingStatus
* Win32_ProcessStartTrace
* Win32_ProcessStopTrace
* Win32_ProcessTrace
* Win32_QuotaSettings
* Win32_ServerConnection
* Win32_ServerSession
* Win32_SessionConnection
* Win32_SIDandAttribute
* Win32_SystemTrace
* Win32_ThreadStartTrace
* Win32_ThreadStopTrace
* Win32_ThreadTrace
* Win32_TokenGroups
* Win32_TokenPrivileges
* Win32_VolumeQuotaSetting

System Scripting Runtime in its current form is a module which contains six ActiveX components:
IPNetwork, LMNetwork, NBTNetwork, SNMPManager, SSHSupport and System.
It was designed and implemented to provide system and network-related functionality for various
development environments (Scripting Languages, VB, C++, etc.).

http://www.netal.com
http://www.netal.com/Software/SSR14.ZIP

Here is an example to check if host alive:

----------------------------------
Set IPNet = CreateObject("SScripting.IPNetwork")
IpAddr = "216.115.108.245" 'That is Yahoo.com
PingHost = IPNet.Ping(IpAddr)
If PingHost = 0 Then
Wscript.Echo "IP Address " & IPAddr & " is alive!"
else
Wscript.Echo "IP Address " & IPAddr & " Request timed out."
End if
----------------------------------

Lightweight Object Browser
http://home.sprintmail.com/~mpryor/promo.htm

code:
Dim oWmiLocator 
Dim oWmiService
Dim oWmiEnum
Dim obj
Set oWmiLocator = CreateObject("WbemScripting.SWbemLocator")
Set oWmiService = oWmiLocator.ConnectServer(".")

oWmiService.Security_.Impersonationlevel = 3
Set oWmiEnum = oWmiService.execQuery("SELECT * FROM win32_pingStatus" & "WHERE statuscode = 0 and (address = 'scotmc3' or address =" & "'scotmc4')","WQL",0)
for each obj in oWMIEnum
wscript.echo obj.Address
next



[ 17 May 2002, 02:48: Message edited by: NTDOC ]

Top
#85704 - 2002-05-17 04:30 AM Re: WMI OS classes (Networking)
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8609
Hey Brian, this one seems to work better over the network (added timeout):

break on

$address = "209.226.175.83"
$timeout = 10000 ; ms

$query = "select * from win32_pingstatus where address = '$address' and timeout=$timeout"

for $i = 0 to 10
 $ping = getobject("winmgmts:").execquery("$query")
 for each $stat in $ping
  ?"Reply from " $stat.protocoladdress
   " bytes=" $stat.buffersize
   " time=" $stat.responsetime
   " status=" $stat.statuscode
 next
next

exit 1


-Shawn

[ 17 May 2002, 04:31: Message edited by: Shawn ]

Top
#85705 - 2002-05-17 03:19 PM Re: WMI OS classes (Networking)
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
Ahh... sorry for sending you guys on a wild goose chase! No wonder it didn't work.. I missed the part about being XP only. At some point, we will be moving to "Whistler"/.NET, so I can make use of this code.

NTDOC,
Those are some GREAT links there. I keep proving how novice I am at this sort of stuff. The learning curve seems pretty steep on the object-oriented syntax.

In the meantime, is there a way in KiXtart that will allow you to load routines from .dll and .exe files? I know that you can call specific functions/routines with rundll.exe and rundll32.exe, but this has limited usefulness as functions return information that cannot be passed back to the script. Perhaps if KiXtart cannot do this internally, there is a .dll wrapper of some sort that will allow it?

Brian

Top
#85706 - 2002-05-17 03:37 PM Re: WMI OS classes (Networking)
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11161
Loc: Boston, MA, USA
BrianTX:

Please add this request to the suggestions forum. I am also looking forward to this type of functionality. It could be modeled after the Visual Basic implementation of including DLL calls. I believe this solution might be the easiest to use.
_________________________
There are two types of vessels, submarines and targets.

Top
#85707 - 2002-05-17 04:43 PM Re: WMI OS classes (Networking)
BrianTX Offline
Korg Regular

Registered: 2002-04-01
Posts: 895
I found this website:

http://home.att.net/~wshvbs/

Which has a lot of neat utilities. It's written for Windows Scripting Host, but it includes a DLL wrapper.

Top
Page 1 of 1 1


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

Who's Online
4 registered (Jochen, AndreLuiz, Flavien, Arend_) and 206 anonymous users online.
Newest Members
Sjaak, Biybucket, Markus1961, Ian231, kixnewbie12
17480 Registered Users

Generated in 0.065 seconds in which 0.024 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