Avatar billede j_jorgensen Nybegynder
02. juli 2002 - 15:06 Der er 8 kommentarer og
1 løsning

Øh...hvad går der galt her?

Hej!

Jeg har et par VBScripts som jeg skal køre (jeg har INGEN forstand på VBScript, AT ALL)...men det fejler :(

Nogen der umiddelbart kan se hvad fejlen er?

Scriptet er her:

'*********************************************
'*** assign values to variables
strClass = "Win32_PerfRawData_PerfOS_Memory"
strNamespace = "root/cimv2"
strProperty = "PagesPersec"
intInterval = WScript.Arguments(0) 'interval (in seconds)
strComputer = WScript.Arguments(1) 'target computer name

'*********************************************
'*** connect to WMI using moniker and retrieve collection of
'*** all instances of class specified as the script argument
Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
                                      strComputer & "/" & strNameSpace).InstancesOf(strClass)

'*********************************************
'*** capture the initial value of the Counter you want to monitor
For Each objInstance In colInstances
                intN0 = objInstance.Properties_.Item(strProperty)
                WScript.Echo intN0 Next

'*********************************************
'*** destroy the objects and collections you created
Set objInstance = Nothing
Set colInstances = Nothing

'*********************************************
'*** in the infinite loop, capture the Counter value at
'*** the end of the interval
While True

        '*********************************************
        '*** go to sleep for intInverval seconds
        WScript.Sleep(intInterval * 1000)

        '*********************************************
        '*** connect to WMI using moniker and retrieve collection of
        '*** all instances of class specified as the script argument
        Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
                                            strComputer & "/" & strNameSpace).InstancesOf(strClass)

        '*********************************************
        '*** capture the final value of the Counter you want to monitor
        For Each objInstance In colInstances
                    intN1 = objInstance.Properties_.Item(strProperty)
                    WScript.Echo intN1
        Next

        '*********************************************
        '*** display the result
        WScript.Echo strProperty & Chr(9) & (intN1 - intN0)/(intInterval)

        '*********************************************
        '*** get ready for the next loop
        Set objInstance = Nothing
        Set colInstances = Nothing
        intN0 = intN1
Wend


----

Og fejlen den siger er:

C:\wmi>cscript //nologo GetCounter.vbs 5 SERVER
C:\wmi\GetCounter.vbs(19, 36) Der opstod en Microsoft VBScript-kompileringsfejl:
Slut på sætning var ventet

Linje 19 er:                WScript.Echo intN0 Next...


Hjæææælp :)
Avatar billede dk_akj Nybegynder
02. juli 2002 - 15:07 #1
Det ser ud til at du mangler en next under WEND

//akj
Avatar billede dk_akj Nybegynder
02. juli 2002 - 15:09 #2
Altså:

'*********************************************
'*** assign values to variables
strClass = "Win32_PerfRawData_PerfOS_Memory"
strNamespace = "root/cimv2"
strProperty = "PagesPersec"
intInterval = WScript.Arguments(0) 'interval (in seconds)
strComputer = WScript.Arguments(1) 'target computer name

'*********************************************
'*** connect to WMI using moniker and retrieve collection of
'*** all instances of class specified as the script argument
Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
                                      strComputer & "/" & strNameSpace).InstancesOf(strClass)

'*********************************************
'*** capture the initial value of the Counter you want to monitor
For Each objInstance In colInstances
                intN0 = objInstance.Properties_.Item(strProperty)
                WScript.Echo intN0 Next

'*********************************************
'*** destroy the objects and collections you created
Set objInstance = Nothing
Set colInstances = Nothing

'*********************************************
'*** in the infinite loop, capture the Counter value at
'*** the end of the interval
While True

        '*********************************************
        '*** go to sleep for intInverval seconds
        WScript.Sleep(intInterval * 1000)

        '*********************************************
        '*** connect to WMI using moniker and retrieve collection of
        '*** all instances of class specified as the script argument
        Set colInstances = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
                                            strComputer & "/" & strNameSpace).InstancesOf(strClass)

        '*********************************************
        '*** capture the final value of the Counter you want to monitor
        For Each objInstance In colInstances
                    intN1 = objInstance.Properties_.Item(strProperty)
                    WScript.Echo intN1
        Next

        '*********************************************
        '*** display the result
        WScript.Echo strProperty & Chr(9) & (intN1 - intN0)/(intInterval)

        '*********************************************
        '*** get ready for the next loop
        Set objInstance = Nothing
        Set colInstances = Nothing
        intN0 = intN1
Wend
Next
Avatar billede j_jorgensen Nybegynder
02. juli 2002 - 15:11 #3
Hmm - det retter jo ikke fejlen i linje 19?  den giver samme fejl nemlig...
Avatar billede j_jorgensen Nybegynder
02. juli 2002 - 16:54 #4
dk_akj - har du opgivet, eller har du ikke tid? :) det lader til at du er den eneste der har villet kigge på det....så jeg ville sætte pris på at finde ud af om jeg ska prøve andre steder, eller om du på et tidspunkt får tid....
Avatar billede dk_akj Nybegynder
02. juli 2002 - 20:37 #5
Prøv lige at rette dette:

For Each objInstance In colInstances
                intN0 = objInstance.Properties_.Item(strProperty)
                WScript.Echo intN0 Next

til dette:

For Each objInstance In colInstances
    intN0 = objInstance.Properties.Item(strProperty)
    WScript.Echo intN0
Next


og fjern det next jeg foreslog i første omgang.

//akj
Avatar billede j_jorgensen Nybegynder
02. juli 2002 - 20:50 #6
C:\>cscript //nologo GetCounter.vbs 5 SERVER
C:\\GetCounter.vbs(18, 5) Der opstod en Microsoft VBScript-kørselsfejl: Objektet understøtter ikke denne egenskab eller metode: 'objInstance.Properties'
Avatar billede dk_akj Nybegynder
02. juli 2002 - 20:53 #7
Sidste ide fra mig.

For Each objInstance In colInstances
                intN0 = objInstance.Properties_.Item(strProperty)
                WScript.Echo intN0
Next

//akj
Avatar billede j_jorgensen Nybegynder
02. juli 2002 - 20:54 #8
Perfekt...det virker! alt for lækkert, tak!!

Post lige et svar :)
Avatar billede dk_akj Nybegynder
02. juli 2002 - 20:58 #9
Når jeg tænker over det er det egentligt temmeligt logisk at next ikke må stå på samme linie som echo, overså det bare fuldstændigt.

//akj
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester