Strange behavior of VBscript/WMI into ASP (compared to VBscript/WMI into client-side application) 
Author Message
 Strange behavior of VBscript/WMI into ASP (compared to VBscript/WMI into client-side application)

Hi,

I'm facing a very strange problem.

This is the context:
I'm using a VB script to access the WMI interface and get information about
the CPU (class Win32_Processor).

I use the same basic VB script in two different applications, one is a
server-side asp, the other is a client active X application.

Everything is fine with the active X: I get the Win32_Processor object and I
can display the data it contains.

There's a problem with the asp: I get the Win32_Processor object (the same
way I do within the active X) and I can display only SOME data and in
particular it seems to have no value for LoadPercentage.
The thing that really confuses me is to get only a part of the information.
I don't understand why some information are present and why one
(LoadPercentage) is missing (and also why it works fine when its a local
side application and not when it's an server ASP).

I attach source and output of my sripts.

Thanks,

Sacha

----------------------------------------------------------------------------
-------------------------------
ASP:

Source:

<HTML>
<HEAD>
<TITLE>WBEM VBScript Example</TITLE>

<%
 const impersonation = 3
 Set Locator = CreateObject("WbemScripting.SWbemLocator")
 Set Service = Locator.ConnectServer()
 Service.Security_.ImpersonationLevel=impersonation
 Set Proc = Service.Get("Win32_Processor.DeviceID=""CPU0""")
 Response.Write Proc.LoadPercentage
 Response.Flush
%>

</HEAD>
<BODY>
<P>load = "<%= Proc.LoadPercentage %>"</P>
<P>name = "<%= Proc.Name %>"</P>
</BODY>
</HTML>

Output

load = ""
name = "Intel Pentium III processor"

----------------------------------------------------------------------------
-------------------------------
Active-X

Source

<HTML>
<HEAD>
<TITLE>WBEM VBScript Example</TITLE>

<SCRIPT LANGUAGE="VBScript">

 Sub window_onload
 const impersonation = 3
 Set Locator = CreateObject("WbemScripting.SWbemLocator")
 Set Service = Locator.ConnectServer()
 Service.Security_.ImpersonationLevel=impersonation
 Set Proc = Service.Get("Win32_Processor.DeviceID=""CPU0""")
 document.all.info.innerText = Proc.LoadPercentage
 document.all.name.innerText = Proc.Name
 end sub

</SCRIPT>

</HEAD>
<BODY>
The load is
<SPAN ID="info">
unknown
</SPAN>.
The name is
<SPAN ID="name">
unknown
</SPAN>.
</BODY>
</HTML>

Output

The load is 0.
The name is Intel Pentium III processor.



Sat, 27 Sep 2003 16:56:58 GMT  
 Strange behavior of VBscript/WMI into ASP (compared to VBscript/WMI into client-side application)
Hi,

Try this it works for me.

'------------------------------------------------------------------------

Function cpuUsage()

Dim Events, Instance, NTEvent

if Not blnDebug Then ON ERROR RESUME NEXT

Set Events = OService.ExecNotificationQuery _

("select * from __instancemodificationevent within 2 where targetinstance
isa 'Win32_Processor' and targetinstance.LoadPercentage > 10")

if err then

WScript.Echo Err.Description, Err.Number, Err.Source

end if

' Note this next call will wait indefinitely - a timeout can be specified

WScript.Echo "Waiting for CPU load events ..."

WScript.Echo ""

do

set NTEvent = Events.nextevent

if err <> 0 then

WScript.Echo Err.Number, Err.Description, Err.Source

Err.Clear

Exit Do

else

WScript.Echo NTEvent.TargetInstance.DeviceID & " : " & _

NTEvent.TargetInstance.CurrentClockSpeed & "Mhz : " & _

NTEvent.TargetInstance.LoadPercentage & "%"

end if

loop

End Function



Quote:
> Hi,

> I'm facing a very strange problem.

> This is the context:
> I'm using a VB script to access the WMI interface and get information
about
> the CPU (class Win32_Processor).

> I use the same basic VB script in two different applications, one is a
> server-side asp, the other is a client active X application.

> Everything is fine with the active X: I get the Win32_Processor object and
I
> can display the data it contains.

> There's a problem with the asp: I get the Win32_Processor object (the same
> way I do within the active X) and I can display only SOME data and in
> particular it seems to have no value for LoadPercentage.
> The thing that really confuses me is to get only a part of the
information.
> I don't understand why some information are present and why one
> (LoadPercentage) is missing (and also why it works fine when its a local
> side application and not when it's an server ASP).

> I attach source and output of my sripts.

> Thanks,

> Sacha

> --------------------------------------------------------------------------
--
> -------------------------------
> ASP:

> Source:

> <HTML>
> <HEAD>
> <TITLE>WBEM VBScript Example</TITLE>

> <%
>  const impersonation = 3
>  Set Locator = CreateObject("WbemScripting.SWbemLocator")
>  Set Service = Locator.ConnectServer()
>  Service.Security_.ImpersonationLevel=impersonation
>  Set Proc = Service.Get("Win32_Processor.DeviceID=""CPU0""")
>  Response.Write Proc.LoadPercentage
>  Response.Flush
> %>

> </HEAD>
> <BODY>
> <P>load = "<%= Proc.LoadPercentage %>"</P>
> <P>name = "<%= Proc.Name %>"</P>
> </BODY>
> </HTML>

> Output

> load = ""
> name = "Intel Pentium III processor"

> --------------------------------------------------------------------------
--
> -------------------------------
> Active-X

> Source

> <HTML>
> <HEAD>
> <TITLE>WBEM VBScript Example</TITLE>

> <SCRIPT LANGUAGE="VBScript">

>  Sub window_onload
>  const impersonation = 3
>  Set Locator = CreateObject("WbemScripting.SWbemLocator")
>  Set Service = Locator.ConnectServer()
>  Service.Security_.ImpersonationLevel=impersonation
>  Set Proc = Service.Get("Win32_Processor.DeviceID=""CPU0""")
>  document.all.info.innerText = Proc.LoadPercentage
>  document.all.name.innerText = Proc.Name
>  end sub

> </SCRIPT>

> </HEAD>
> <BODY>
> The load is
> <SPAN ID="info">
> unknown
> </SPAN>.
> The name is
> <SPAN ID="name">
> unknown
> </SPAN>.
> </BODY>
> </HTML>

> Output

> The load is 0.
> The name is Intel Pentium III processor.



Mon, 29 Sep 2003 17:51:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Pulling device driver information using vbscript and WMI.

2. Novice Question: Using VBScript + WMI within ASP

3. Stopping a Service or Killing a Process with VBScript and WMI in ASP

4. Strange Behavior in Wn98 PWS w client-side script

5. ASP ot VBScript / VBScript to ASP

6. Client-side VBScript and Server-side VBScript?

7. ? Get rid of VBScript title in msgbox (client Side VBScript)

8. ASP, Word, Client Side vbScript

9. wmi core and wmi sdk...

10. VBScript, WMI and Cisco switches

11. Using WMI with VBScript to Query Network Config

12. WMI Script or VBSCRIPT

 

 
Powered by phpBB® Forum Software