mirror of
https://github.com/ShareX/ShareX.git
synced 2024-07-03 13:40:34 +12:00
Added dns change error messages
This commit is contained in:
parent
4eefd960ad
commit
6a15f8d5d3
|
@ -81,13 +81,9 @@ public string[] GetDNS()
|
|||
return (string[])adapter["DnsServerSearchOrder"];
|
||||
}
|
||||
|
||||
public bool SetDNS(string primary, string secondary)
|
||||
{
|
||||
try
|
||||
public uint SetDNS(string primary, string secondary)
|
||||
{
|
||||
using (ManagementBaseObject parameters = adapter.GetMethodParameters("SetDNSServerSearchOrder"))
|
||||
{
|
||||
if (parameters != null)
|
||||
{
|
||||
if (primary == null || secondary == null)
|
||||
{
|
||||
|
@ -99,22 +95,15 @@ public bool SetDNS(string primary, string secondary)
|
|||
parameters["DNSServerSearchOrder"] = new string[] { primary, secondary };
|
||||
}
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/aa393295(v=vs.85).aspx
|
||||
using (ManagementBaseObject result = adapter.InvokeMethod("SetDNSServerSearchOrder", parameters, null))
|
||||
{
|
||||
return (uint)result["ReturnValue"] == 0;
|
||||
return (uint)result["ReturnValue"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool SetDNSAutomatic()
|
||||
public uint SetDNSAutomatic()
|
||||
{
|
||||
return SetDNS(null, null);
|
||||
}
|
||||
|
|
|
@ -129,8 +129,10 @@ private void btnSave_Click(object sender, EventArgs e)
|
|||
|
||||
if (adapter != null)
|
||||
{
|
||||
bool result = false;
|
||||
uint result;
|
||||
|
||||
try
|
||||
{
|
||||
if (cbAutomatic.Checked)
|
||||
{
|
||||
result = adapter.SetDNSAutomatic();
|
||||
|
@ -144,13 +146,30 @@ private void btnSave_Click(object sender, EventArgs e)
|
|||
{
|
||||
result = adapter.SetDNS(primaryDNS, secondaryDNS);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Not valid ip address.");
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
if (result == 0)
|
||||
{
|
||||
NativeMethods.DnsFlushResolverCache();
|
||||
MessageBox.Show("DNS successfully set.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else if (result == 1)
|
||||
{
|
||||
MessageBox.Show("DNS successfully set. Reboot is required.", "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else if (result > 1)
|
||||
{
|
||||
MessageBox.Show("DNS set failed with error code: " + result, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("DNS set failed.\r\n" + ex.ToString(), "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue