+ Reply to Thread
Results 1 to 7 of 7

Thread: Error: SWbemObjectEx (49, 4) : Not found

  1. #1
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    Error: SWbemObjectEx (49, 4) : Not found

    I'm running a script that loops through all the scheduled jobs on a server and checks to see which jobs are running by a certain user and then makes sure they're not hanging processes. Basically out there idle for over 15 minutes.

    Anyway, it starts fine and runs through the processes quite nicely for about an hour then it errors out with the following error:

    SWbemObjectEx (49, 4) : Not found
    [highlight=vb]
    Set sProcessList = oProcess.ExecQuery ("Select * from Win32_Process")
    sMsg = ""
    If sProcessList.Count > 0 Then
    For each iProcess in sProcessList
    iReturn = iProcess.GetOwner '<--- This is the line it errors on
    [/highlight]I'm not sure why it's doing that as for a while it runs fine with no errors.
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Try placing a conditional inside the For...Each that checks if iProcess.GetOwner is nothing.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    I've already done that ... it's a no go, it still happens ... here's the full error:
    Line: 53
    Column: 4
    Error: Not found
    Code: 80041002
    Source: SWbemObjectEx
    and i found this link that basically says:
    Your VBScript contains a misspelled object name. Code 80041002 is an unusual Error in that a number is returned rather than 'Syntax Error' or other message.
    can't really be misspelled if it's working to start then gets the error. i'm at a loss.
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    What about just checking if iProcess is nothing as opposed to iProcess.GetOwner?
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    tried that ... i am pulling the name of the process before get owner and that works fine. and it's never the same process that it errs on.
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  6. #6
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    here is the full code ...
    [highlight=vb]Dim oProcess, oFSO, oFile, oMail
    Dim sUser, sFile, sDir
    Dim iWait, i
    Dim sComputer, sProcessList, sError
    Dim dtmStartTime, strConvTime, intDiff, intCPU, sMsg
    Dim strUserName, strProcess, intPID

    ' Enable error handling
    On Error Resume Next

    sUser = "ThisUser"
    sFile = "thisuser_processes.txt"
    sDir = "C:\"
    iWait = 5 'loop every 5 minutes to check

    sComputer = "." 'use "." for local computer

    'Create Objects
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    'Create new text file
    Set oFile = oFSO.CreateTextFile (sDir & sFile, True)
    oFile.close
    set oFile = Nothing

    Do Until hour(Time()) = 7 and minute(Time()) > 30
    sError = ""
    Set oProcess = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
    Set sProcessList = oProcess.ExecQuery ("Select * from Win32_Process")
    sMsg = ""
    If sProcessList.Count > 0 Then 'Count = 0 , no processes running.
    For each iProcess in sProcessList
    iReturn = iProcess.GetOwner
    'Check for Error
    If Err.number <> 0 Then
    'could not be found
    sError = "Exception:<br />" & _
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error Number: " & Err.Number & "<br />" & _
    "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Error Description: " & Err.Description
    sendMessage "joanne.nuzzi@answernet.com","Ann100 SchUser Process Error",sError,"",""
    Else
    If iReturn = 0 Then 'Successful Completion
    iProcess.GetOwner(strUserName)
    if lCase(strUserName) = lCase(sUser) Then
    strProcess = iProcess.Name
    intPID = iProcess.Handle
    dtmStartTime = iProcess.CreationDate 'Check when process was started
    strConvTime = WMIDateStringToDate(dtmStartTime) 'Convert Time
    intDiff = cint(Round((DateDiff("n",strConvTime,Now())),0)) 'Check how long it's been opened.
    'If running for longer than 15 minutes, check CPU Usage
    if intDiff > 15 then
    intCPU = CPUUsage(intPID) 'Using Process ID, get CPU Usage
    if intCPU = 0 then 'Process is idle and running longer than 15 minutes.
    sMsg = sMsg & Now() & vbTab & strProcess & vbTab & intPID & vbTab & strUserName & vbTab & "Killed" & vbTab & strConvTime & vbTab & intCPU & "%" & vbCr
    iProcess.Terminate() 'Kill the process
    else 'Process is not Idle.
    sMsg = sMsg & Now() & vbTab & strProcess & vbTab & intPID & vbTab & strUserName & vbTab & "Not Idle" & vbTab & strConvTime & vbTab & intCPU & "%" & vbCr
    end if
    else 'Process has been running less than 15 minutes.
    sMsg = sMsg & Now() & vbTab & strProcess & vbTab & intPID & vbTab & strUserName & vbTab & "OK" & vbTab & strConvTime & vbTab & "" & vbCr
    end if
    end If
    End If
    End If
    'Reset error handling
    On Error Goto 0
    Next
    End If
    Set oFile = oFSO.OpenTextFile (sDir & sFile, 8, True)
    if sMsg <> "" then
    oFile.WriteLine(left(sMsg,len(sMsg)-1))
    else
    oFile.WriteLine(Now() & vbTab & vbTab & vbTab & "" & vbTab & "" & vbTab & "No Processes Running for SchUser" & vbTab & "" & vbTab & "")
    end if
    oFile.Close

    set oProcess = Nothing
    WScript.Sleep iWait * 60 * 1000 'wait XX minutes and check again (value of iWait is # of minutes)
    Loop

    If oFSO.FileExists(sDir & sFile) then
    oMail.AddAttachment sDir & sFile
    sendMessage "me@here.com","ThisUser Processes","Attached is today's report.","",""
    End if

    set oFile = Nothing
    set oFSO = Nothing
    'set oProcess = Nothing

    Function sendMessage (sTo, sSubject, sMessage, sCC, sBCC)
    Set oMail = CreateObject("CDO.Message")
    With oMail
    .To = sTo
    .Cc = sCC
    .Bcc = sBcc
    .Subject = sSubject
    .HTMLBody = sMessage
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.server.com"
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "my_usernam"
    .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "my_password"
    .Configuration.Fields.Update
    .From = "this@there.com"
    .Send
    End With
    set oMail = Nothing
    End Function

    Function WMIDateStringToDate(dtmStart)
    'DESC: Coverts WMI date Time
    WMIDateStringToDate = CDate(Mid(dtmStart, 5, 2) & "/" & Mid(dtmStart, 7, 2) & "/" & Left(dtmStart, 4) & _
    " " & Mid (dtmStart, 9, 2) & ":" & Mid(dtmStart, 11, 2) & ":" & Mid(dtmStart,13, 2))
    End Function

    Function CPUUSage( ProcID )
    'DESC: Calculate CPU Percentage
    Dim oService, oInstance1, oInstance2
    Dim N1, N2, D1, D2, Nd, Dd
    Dim PersentProcessorTime

    set oService = GetObject("winmgmts:{impersonationLevel=impersonat e}!\root\cimv2")
    For Each oInstance1 in oService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process where IDProcess = '" & ProcID & "'")
    N1 = oInstance1.PercentProcessorTime
    D1 = oInstance1.TimeStamp_Sys100NS
    Exit For
    Next
    WScript.Sleep(2000) 'Check again in 2 seconds.
    For Each oInstance2 in oService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process where IDProcess = '" & ProcID & "'")
    N2 = oInstance2.PercentProcessorTime
    D2 = oInstance2.TimeStamp_Sys100NS
    Exit For
    Next
    Nd = (N2-N1)
    Dd = (D2-D1)
    set oService = nothing
    PercentProcessorTime = CDbl((Nd/Dd) * 100)
    CPUUSage = Round(PercentProcessorTime ,0)
    End Function[/highlight]
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  7. #7
    Windows Guru Nilpo is on a distinguished road Nilpo's Avatar
    Join Date
    Jul 2010
    Location
    Wake Forest, NC
    Posts
    68
    Real Name
    Robert Dunham
    Rep Power
    2

    It sounds more like you are trying to access a non-existent process. When you poll your process list, one of them may be ending before you get around to doing anything with it.
    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!

+ Reply to Thread

Similar Threads

  1. HREF (Page not found)
    By Rebelle in forum HTML & CSS Help
    Replies: 6
    Last Post: January 18th, 2012, 05:42 AM
  2. Replies: 3
    Last Post: April 15th, 2010, 03:56 PM
  3. '?companyname' not found in the collection.
    By richyrich in forum MySQL
    Replies: 3
    Last Post: June 19th, 2009, 07:07 AM
  4. No Default Member Found for type
    By richyrich in forum .NET Development
    Replies: 5
    Last Post: May 29th, 2008, 02:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO