Unexplained application crashes when using uncom

Started by Quin, October 08, 2024, 09:50:08 AM

Previous topic - Next topic

Quin

Can anyone test and confirm whether or not this code crashes for them when hiding any update? It does for me and a friend on both Windows 10 and 11. If you want to see if it actually crashed, see instructions in my previous post.
The code is now at: https://github.com/TheQuinbox/uphide

Quin

Quote from: airr on October 23, 2024, 05:11:21 AM
Hi, Quin.

I tried this:

For I = 0 To NumSelections - 1
    Dim CurIndex
    CurIndex = Val(ToHide[I])
    If CurIndex <= 0 Or CurIndex > NumUpdates Then Continue
    Comset Update = Updates.Item(CurIndex - 1)
    If IsObject(Update) Then
        Dim Title$
        Title$ = Update.Title
        Update.IsHidden = True
        Print "Hid " & Title$
        Uncom(Update)
    End If
Next


And it successfully executed with no issue.  I ran the resulting binary as Admin (I didn't include the .res file that configures the .exe for elevation, for testing purposes).

AIR.

Edit:  Compiled with the UAC res file, no apparent issues.  Ran it through WinDBG, no crashes.
Hi Airr,
Sorry for leaving you on read for so long, life got crazy there for a few months, you know how it is.
Unfortunately I and another friend still can make this program show the standard "_ has stopped working dialog". You have to actually hide an update to get it to happen, but it still does.
I might've given the instructions earlier in this thread, but to do that, make a new DWORD at hklm\software\microsoft\windows\windows error reporting\DontShowUI, keep it at 0, then try. No reboots needed.
Here's the full code in case I missed another modification.

#include <wuapi.h>

BCX_Show_COM_Errors(True)

Dim As Object Session, Searcher, SearchResult, Update, Updates
Dim NumUpdates, I
Comset Session = Com("Microsoft.Update.Session")
Comset Searcher = Session.CreateupdateSearcher()
Searcher.ClientApplicationID = "uphide"
Print "Checking for updates..."
Comset SearchResult = Searcher.Search("IsInstalled=0 And IsHidden=0")
NumUpdates = SearchResult.Updates.Count
If NumUpdates = 0 Then
    Print "No updates were found."
    Uncom(SearchResult)
    Uncom(Searcher)
    Uncom(Session)
    End
End If
Print "Enter the numbers of the updates you want to hide, seperated by spaces, and press enter. Leave blank to exit."
Dim Index = 1
Comset Updates = SearchResult.Updates
For Each Item In Updates
    Dim Title$
    Title$ = Item.Title
    Print Str$(Index, 1) & ": " & Title$
    Index++
Next
Dim Input$
Input Input$
If Input$ = "" Then
    Uncom(Updates)
    Uncom(SearchResult)
    Uncom(Searcher)
    Uncom(Session)
    End
End If
Dim NumSelections
Dim ToHide[100] As String
NumSelections = Split(ToHide, Input$, " ", 0)
For I = 0 To NumSelections - 1
    Dim CurIndex
    CurIndex = Val(ToHide[I])
    If CurIndex <= 0 Or CurIndex > NumUpdates Then Continue
    Comset Update = Updates.Item(CurIndex - 1)
    If IsObject(Update) Then
        Dim Title$
        Title$ = Update.Title
        Update.IsHidden = True
        Print "Hid " & Title$
        Uncom(Update)
    End If
Next
Pause
Uncom(Updates)
Uncom(SearchResult)
Uncom(Searcher)
Uncom(Session)

Thanks as always for all your help!

MrBcx

I found the earlier error of my ways ( see screenshot )

If compiling with BED, need to uncheck the default manifest inclusion.

Now it compiles, executes, and closes as it should. -- No issues.






airr

Quote from: MrBcx on October 23, 2024, 10:32:35 AM
Quote from: airr on October 23, 2024, 05:11:21 AM

AIR.

Edit:  Compiled with the UAC res file, no apparent issues.


Can someone share the "UAC res file" ?

Inquiring minds and all that ...

See attachment...

AIR.

MrBcx

Quote from: airr on October 23, 2024, 05:11:21 AM

AIR.

Edit:  Compiled with the UAC res file, no apparent issues.


Can someone share the "UAC res file" ?

Inquiring minds and all that ...

airr

#27
Hi, Quin.

I tried this:

For I = 0 To NumSelections - 1
    Dim CurIndex
    CurIndex = Val(ToHide[I])
    If CurIndex <= 0 Or CurIndex > NumUpdates Then Continue
    Comset Update = Updates.Item(CurIndex - 1)
    If IsObject(Update) Then
        Dim Title$
        Title$ = Update.Title
        Update.IsHidden = True
        Print "Hid " & Title$
        Uncom(Update)
    End If
Next


And it successfully executed with no issue.  I ran the resulting binary as Admin (I didn't include the .res file that configures the .exe for elevation, for testing purposes).

AIR.

Edit:  Compiled with the UAC res file, no apparent issues.  Ran it through WinDBG, no crashes.

Quin

Kevin,
Yes, I've tried it in powershell, and it works perfectly fine. Just to be clear, it works perfectly fine here, too, the updates get hidden and don't show up again, but it's crashing somewhere after hiding all of them on exit.

MrBcx

Quote from: Quin on October 21, 2024, 08:34:58 AM
I completely expected this to fix it, but it actually didn't, bafflingly enough. All I did was move the Uncom(Update) line to right after the Update.IsHidden = True line, and I fixed the case on that line too. The same crash occurs, only after successfully hiding at least one update.

I'm curious whether you've tried doing this in vbscript or powershell. 

That might help isolate the root cause of this stubbornness.

Quin

I completely expected this to fix it, but it actually didn't, bafflingly enough. All I did was move the Uncom(Update) line to right after the Update.IsHidden = True line, and I fixed the case on that line too. The same crash occurs, only after successfully hiding at least one update.

airr

Hi, nagrom, I just wanted to welcome you to the forum!

AIR.

Edit:  I see what you did there!


airr

Try "UCOM(Update)" in the loop after you've set the ".IsHidden" property? Also, is the property name case-sensitive?

AIR.

Quin

Robert,
Thanks for all your help! Unfortunately though, that doesn't seem to have fixed it. If I don't type anything and let those uncom statements run there's no crash, it's only after I've successfully hidden at least one update that it crashes.
Latest code for reference:

#include <wuapi.h>

BCX_Show_COM_Errors(True)

Dim As Object Session, Searcher, SearchResult, Update, Updates
Dim NumUpdates, I
Comset Session = Com("Microsoft.Update.Session")
Comset Searcher = Session.CreateupdateSearcher()
Searcher.ClientApplicationID = "uphide"
Print "Checking for updates..."
Comset SearchResult = Searcher.Search("IsInstalled=0 And IsHidden=0")
NumUpdates = SearchResult.Updates.Count
If NumUpdates = 0 Then
    Print "No updates were found."
    Uncom(SearchResult)
    Uncom(Searcher)
    Uncom(Session)
    End
End If
Print "Enter the numbers of the updates you want to hide, seperated by spaces, and press enter. Leave blank to exit."
Dim Index = 1
Comset Updates = SearchResult.Updates
For Each Item In Updates
    Dim Title$
    Title$ = Item.Title
    Print Str$(Index, 1) & ": " & Title$
    Index++
Next
Dim Input$
Input Input$
If Input$ = "" Then
    Uncom(Updates)
    Uncom(SearchResult)
    Uncom(Searcher)
    Uncom(Session)
    End
End If
Dim NumSelections
Dim ToHide[100] As String
NumSelections = Split(ToHide, Input$, " ", 0)
For I = 0 To NumSelections - 1
    Dim CurIndex
    CurIndex = Val(ToHide[I])
    If CurIndex <= 0 Or CurIndex > NumUpdates Then Continue
    Comset Update = Updates.Item(CurIndex - 1)
    Dim Title$
    Title$ = Update.Title
    Update.Ishidden = True
    Print "Hid " & Title$
Next
Pause
Uncom(Update)
Uncom(Updates)
Uncom(SearchResult)
Uncom(Searcher)
Uncom(Session)

Did I miss something?'Thanks,
Quin.

Robert

Quote from: Quin on October 16, 2024, 06:09:23 PM
Airr,
I can confirm that this did in fact fix the crash in the battery utility. Thanks for all your help!
I'll do more testing with that update utility and see what I can find.

Hi Quin:

Each COMSET object must be terminated with an UNCOM before an END statement.

In your original post updates code change from


If NumUpdates = 0 Then
    Print "No updates were found."
    End
End If


to


IF NumUpdates = 0 THEN
  PRINT "No updates were found."
  UNCOM(SearchResult)
  UNCOM(Searcher)
  UNCOM(Session)
  END
END IF


and change


If Input$ = "" Then End


to

IF UpdatesToHide$ = "" THEN
  UNCOM(Updates)
  UNCOM(SearchResult)
  UNCOM(Searcher)
  UNCOM(Session)
  END
END IF


And at the end of your updates program reorder the UNCOM statements to: first COMSET object in, last matching UNCOM out


UNCOM(Update)
UNCOM(Updates)
UNCOM(SearchResult)
UNCOM(Searcher)
UNCOM(Session)

Quin

Airr,
I can confirm that this did in fact fix the crash in the battery utility. Thanks for all your help!
I'll do more testing with that update utility and see what I can find.