@@ -66,14 +66,24 @@ public static void RemoveHttpProxy()
66
66
"Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Internet Settings" , true ) ;
67
67
if ( reg != null )
68
68
{
69
- var exisitingContent = reg . GetValue ( "ProxyServer" ) as string ;
70
-
71
- var existingSystemProxyValues = GetSystemProxyValues ( exisitingContent ) ;
72
- existingSystemProxyValues . RemoveAll ( x => ! x . IsSecure ) ;
73
-
74
-
75
- reg . SetValue ( "ProxyEnable" , 1 ) ;
76
- reg . SetValue ( "ProxyServer" , String . Join ( ";" , existingSystemProxyValues . Select ( x => x . ToString ( ) ) . ToArray ( ) ) ) ;
69
+ if ( reg . GetValue ( "ProxyServer" ) != null )
70
+ {
71
+ var exisitingContent = reg . GetValue ( "ProxyServer" ) as string ;
72
+
73
+ var existingSystemProxyValues = GetSystemProxyValues ( exisitingContent ) ;
74
+ existingSystemProxyValues . RemoveAll ( x => ! x . IsSecure ) ;
75
+
76
+ if ( ! ( existingSystemProxyValues . Count ( ) == 0 ) )
77
+ {
78
+ reg . SetValue ( "ProxyEnable" , 1 ) ;
79
+ reg . SetValue ( "ProxyServer" , String . Join ( ";" , existingSystemProxyValues . Select ( x => x . ToString ( ) ) . ToArray ( ) ) ) ;
80
+ }
81
+ else
82
+ {
83
+ reg . SetValue ( "ProxyEnable" , 0 ) ;
84
+ reg . SetValue ( "ProxyServer" , string . Empty ) ;
85
+ }
86
+ }
77
87
}
78
88
79
89
Refresh ( ) ;
@@ -112,14 +122,25 @@ public static void RemoveHttpsProxy()
112
122
"Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Internet Settings" , true ) ;
113
123
if ( reg != null )
114
124
{
115
- var exisitingContent = reg . GetValue ( "ProxyServer" ) as string ;
116
-
117
- var existingSystemProxyValues = GetSystemProxyValues ( exisitingContent ) ;
118
- existingSystemProxyValues . RemoveAll ( x => x . IsSecure ) ;
119
-
120
-
121
- reg . SetValue ( "ProxyEnable" , 1 ) ;
122
- reg . SetValue ( "ProxyServer" , String . Join ( ";" , existingSystemProxyValues . Select ( x => x . ToString ( ) ) . ToArray ( ) ) ) ;
125
+ if ( reg . GetValue ( "ProxyServer" ) != null )
126
+ {
127
+ var exisitingContent = reg . GetValue ( "ProxyServer" ) as string ;
128
+
129
+ var existingSystemProxyValues = GetSystemProxyValues ( exisitingContent ) ;
130
+ existingSystemProxyValues . RemoveAll ( x => x . IsSecure ) ;
131
+
132
+ if ( ! ( existingSystemProxyValues . Count ( ) == 0 ) )
133
+ {
134
+ reg . SetValue ( "ProxyEnable" , 1 ) ;
135
+ reg . SetValue ( "ProxyServer" , String . Join ( ";" , existingSystemProxyValues . Select ( x => x . ToString ( ) ) . ToArray ( ) ) ) ;
136
+ }
137
+ else
138
+ {
139
+ reg . SetValue ( "ProxyEnable" , 0 ) ;
140
+ reg . SetValue ( "ProxyServer" , string . Empty ) ;
141
+ }
142
+
143
+ }
123
144
}
124
145
125
146
Refresh ( ) ;
0 commit comments