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

The WebProxy property may not exist #5

Open re3turn opened 2 years ago

re3turn commented 2 years ago

4 has not fixed #3

That's the webProxy of the failed EC2 instance

PS C:\Users\Administrator\Documents> $objSession = New-Object -ComObject "Microsoft.Update.Session"
PS C:\Users\Administrator\Documents> $objSession | Format-List

ClientApplicationID :
ReadOnly            : False
WebProxy            :
UserLocale          : 1033

PS C:\Users\Administrator\Documents> $objSession.WebProxy
PS C:\Users\Administrator\Documents> 

That's the webProxy of the my local Windows OS

PS C:\Users\Administrator\Documents> $objSession = New-Object -ComObject "Microsoft.Update.Session"
PS C:\Users\Administrator\Documents> $objSession | Format-List

ClientApplicationID :
ReadOnly            : False
WebProxy            : System.__ComObject
UserLocale          : 1041

PS C:\Users\Administrator\Documents> $objSession.WebProxy

Address            :
BypassList         : System.__ComObject
BypassProxyOnLocal : False
ReadOnly           : False
UserName           :
AutoDetect         : True
ceshihao commented 2 years ago

It looks like that error comes from oleutil.GetProperty(updateSessionDisp, "WebProxy") https://github.com/ceshihao/windowsupdate/blob/94efa1c2d8dba7e7d81522507728ec8053d33c12/iupdatesession.go#L45-L48 The function returns Exception occurred. (<nil>) but not nil IDispatch. Could you please help to dig more, why it happens on EC2 instance? I do not have much experience on EC2 Windows.

re3turn commented 2 years ago

It was found that some ComObject could not be accessed when connecting remotely.

https://stackoverflow.com/questions/7078958/powershell-remote-microsoft-update-session-access-denied-0x80070005

PS C:\Users\Administrator> $objSession = New-Object -ComObject "Microsoft.Update.Session"
PS C:\Users\Administrator> $objSession | Format-List

ClientApplicationID :
ReadOnly            : False
WebProxy            : System.__ComObject
UserLocale          : 1033

PS C:\Users\Administrator> Set-ExecutionPolicy RemoteSigned -Force
PS C:\Users\Administrator> Set-WSManQuickConfig -Force
WinRM is already set up to receive requests on this computer.
WinRM has been updated for remote management.
Configured LocalAccountTokenFilterPolicy to grant administrative rights remotely to local users.

PS C:\Users\Administrator> Enter-PSSession -ComputerName localhost
[localhost]: PS C:\Users\Administrator\Documents> $objSession = New-Object -ComObject "Microsoft.Update.Session"
[localhost]: PS C:\Users\Administrator\Documents> $objSession | Format-List

ClientApplicationID :
ReadOnly            : False
WebProxy            :
UserLocale          : 1033

[localhost]: PS C:\Users\Administrator\Documents> $objSession.WebProxy
[localhost]: PS C:\Users\Administrator\Documents>