Win10 they broke many things - VPN reconnect, ICS sharing etc, I was trying to schedule a script to fix those (VPN reconnect was a success) - but the one I found for ICS - powershell script to turn off and turn back on ICS (that fixes the sharing stopping working in Win10 after internet reconnect) crashes on line where it enables sharing for public adapter with error `System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at IDispatchInvoke`, even thought checkboxes in adapter seem to go off and back on - internet sharing doesn’t start working back - no wonder, cuz powrshell crashes in that moment.
screenshot - https://i.stack.imgur.com/zcv4i.jpg
script:
# Constants $public = 0 $private = 1 Write-Host "Creating netshare object..." $netshare = New-Object -ComObject HNetCfg.HNetShare Write-Host "Getting public adapter..." $publicadapter = $netshare.EnumEveryConnection | Where-Object { $netshare.NetConnectionProps($_).Name -eq "MYISP_VPN" }#foreach Write-Host "Getting private adapter..." $privateadapter = $netshare.EnumEveryConnection | Where-Object { $netshare.NetConnectionProps($_).Name -eq "Home_local" }#foreach Write-Host "Disabling sharing for adapters...." $netshare.INetSharingConfigurationForINetConnection($privateadapter).DisableSharing() $netshare.INetSharingConfigurationForINetConnection($publicadapter).DisableSharing() Start-Sleep -s 3 Write-Host "Enabling sharing for private adapter...." $netshare.INetSharingConfigurationForINetConnection($privateadapter).EnableSharing($private) Write-Host "Enabling sharing for public adapter...." $netshare.INetSharingConfigurationForINetConnection($publicadapter).EnableSharing($public) # Clean up Remove-Variable netshare
help?