ceshihao / windowsupdate

A Golang binding for Windows Update Agent API
https://pkg.go.dev/github.com/ceshihao/windowsupdate
Apache License 2.0
11 stars 7 forks source link

Fix not exist WebProxy property #3

Closed re3turn closed 2 years ago

re3turn commented 2 years ago

Signed-off-by: re3turn re3turn@gmail.com

The WebProxy property may not exist on the EC2 instance and GetProperty() fails.

PS C:/Users/re3turn/GolandProjects/wsus/windowsupdate/examples> .\install_updates.exe
panic: Exception occurred. (<nil>)

goroutine 1 [running]:
main.main()
        C:/Users/re3turn/GolandProjects/wsus/windowsupdate/examples/install_updates/main.go:24 +0x194
ceshihao commented 2 years ago

Signed-off-by: re3turn re3turn@gmail.com

The WebProxy property may not exist on the EC2 instance and GetProperty() fails.

PS C:/Users/re3turn/GolandProjects/wsus/windowsupdate/examples> .\install_updates.exe
panic: Exception occurred. (<nil>)

goroutine 1 [running]:
main.main()
        C:/Users/re3turn/GolandProjects/wsus/windowsupdate/examples/install_updates/main.go:24 +0x194

Cloud you please provide more info? I can not reproduce it on my OS.

If WebProxy not exists, it should be nil rather than an error. Does Windows EC2 instance have any difference?

re3turn commented 2 years ago

It always fails with my OS. However, a local Windows OS will succeed.

ceshihao commented 2 years ago
  • OS: Windows Server 2019 Datacenter
  • Version: 10.0.17763

It always fails with my OS. However, a local Windows OS will succeed.

I try to reproduce the issue on such an OS. But it works. Can you provide more information about the panic?

Edition: Windows Server 2019 Datacenter
Version: 1809
OS Build: 17763.2928
re3turn commented 2 years ago

Why is that? My Windows instance is on an Amazon VPC. It fails for all Windows instances on the VPC.

ceshihao commented 2 years ago

@re3turn Try to debug on WebProxy

$objSession = New-Object -ComObject "Microsoft.Update.Session"
$objSession.WebProxy

I reproduce the issue on aws EC2. WebProxy is nil.

However, on my Windows OS, WebProxy is

Address            : 
BypassList         : System.__ComObject
BypassProxyOnLocal : False
ReadOnly           : False
UserName           : 
AutoDetect         : True

I think it should be a bug on function toIDispatchErr() which does not handle nil correctly. Could you please help to fix it?