diff --git a/trunk/ProcessHacker.Native/Api/Functions.cs b/trunk/ProcessHacker.Native/Api/Functions.cs index d7d35f63a..79b5ae9f0 100644 --- a/trunk/ProcessHacker.Native/Api/Functions.cs +++ b/trunk/ProcessHacker.Native/Api/Functions.cs @@ -713,6 +713,146 @@ namespace ProcessHacker.Native.Api #endregion + #region Network Diagnostics + + /// + /// The NdfCancelIncident function is used to cancel unneeded functions which have been previously called on an existing incident. + /// + /// + /// Before using this API, an application must call an incident creation function such as NdfCreateWebIncident. + /// NdfCloseIncident should be used to close an incident once it has been resolved, as NdfCancelIncident does not actually close the incident itself. + /// + /// A handle to the Network Diagnostics Framework incident. + /// This handle should match the handle of an existing incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll")] + public static extern HResult NdfCancelIncident( + [In] IntPtr NdfHandle + ); + + /// + /// The NdfCloseIncident function is used to close an Network Diagnostics Framework (NDF) incident following its resolution. + /// + /// The handle to the NDF incident that is being closed. + /// A HResult value indicating the result + [DllImport("ndfapi.dll")] + public static extern HResult NdfCloseIncident( + [In] IntPtr NdfHandle + ); + + /// + /// The NdfCreateConnectivityIncident function diagnoses generic internet connectivity problems. + /// + /// The handle to the Network Diagnostics Framework incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll")] + public static extern HResult NdfCreateConnectivityIncident( + [In, Out] ref IntPtr NdfHandle + ); + + /// + /// The NdfCreateInboundIncident function creates a session to diagnose inbound connectivity for a specific application or service. + /// + /// The fully qualified path to the application receiving the inbound traffic. + /// The Windows service receiving the inbound traffic. + /// The SID for the application receiving the traffic. If NULL, the caller's SID is automatically used. + /// A SOCKADDR_STORAGE structure which limits the diagnosis to traffic to a specific IP address. If NULL, all traffic will be included in the diagnosis + /// The protocol which should be diagnosed. For example, IPPROTO_TCP would be used to indicate the TCP/IP protocol. + /// The Inbound flags for specifying the type of options to preform during diagnostics. + /// Pointer to a handle to the Network Diagnostics Framework incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll", CharSet = CharSet.Unicode)] + public static extern HResult NdfCreateInboundIncident( + [In, Optional] string applicationID, + [In, Optional] string serviceID, + [In, Optional] int userID, //Incorrect + [In, Optional] int localTarget, //Incorrect + int protocol, //Incorrect + int dwFlags, ///IsUnum: NDF_INBOUND_FLAG + [In, Out] ref IntPtr NdfHandle + ); + + /// + /// The NdfCreateDNSIncident function diagnoses name resolution issues in resolving a specific host name. + /// + /// The host name with which there is a name resolution issue. + /// The numeric representation of the type of record that was queried when the issue occurred. + /// A handle to the Network Diagnostics Framework incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll", CharSet = CharSet.Unicode)] + public static extern HResult NdfCreateDNSIncident( + [In] string hostname, + ushort querytype, //enum value: see the windns.h header file + [In, Out] ref IntPtr NdfHandle + ); + + /// + /// The NdfCreateSharingIncident function diagnoses network problems in accessing a specific network share. + /// + /// The full UNC string (for example, "\\server\folder\file.ext")for the shared asset with which there is a connectivity issue. + /// A handle to the Network Diagnostics Framework incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll", CharSet = CharSet.Unicode)] + public static extern HResult NdfCreateSharingIncident( + [In] string shareName, + [In, Out] ref IntPtr NdfHandle + ); + + /// + /// The NdfCreateWebIncident function diagnoses web connectivity problems concerning a specific URL. + /// + /// The URL with which there is a connectivity issue. + /// A handle to the Network Diagnostics Framework incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll", CharSet = CharSet.Unicode)] + public static extern HResult NdfCreateWebIncident( + [In] string url, + [In, Out] ref IntPtr NdfHandle + ); + + /// + /// The NdfCreateWebIncidentEx function diagnoses web connectivity problems concerning a specific URL. This function allows for more control over the underlying diagnosis than the NdfCreateWebIncident function. + /// + /// The URL with which there is a connectivity issue. + /// If TRUE, diagnosis is performed using the WinHTTP APIs. Otherwise, the WinInet APIs are used. + /// The module name to use when checking against application-specific filtering rules (for example, "C:\Program Files\Internet Explorer\iexplorer.exe"). If NULL, the value is autodetected during the diagnosis. + /// A handle to the Network Diagnostics Framework incident. + /// A HResult value indicating the result + [DllImport("ndfapi.dll", CharSet = CharSet.Unicode)] + public static extern HResult NdfCreateWebIncidentEx( + [In] string url, + [MarshalAs(UnmanagedType.Bool)] + [In] bool useWinHTTP, + [In] string moduleName, + [In, Out] ref IntPtr NdfHandle + ); + + /// + /// The NdfExecuteDiagnosis function is used to diagnose the root cause of the incident that has occurred. + /// + /// A handle to the Network Diagnostics Framework incident. + /// The handle to the window that is intended to display the diagnostic information. If specified, the NDF UI is modal to the window. If NULL, the UI is non-modal. + /// A HResult value indicating the result + [DllImport("ndfapi.dll")] + public static extern HResult NdfExecuteDiagnosis( + [In] IntPtr NdfHandle, + [In] IntPtr hwnd + ); + + /// + /// The NdfGetTraceFile function is used to retrieve the path containing an Event Trace Log (ETL) file that contains Event Tracing for Windows (ETW) events from a diagnostic session. + /// + /// A handle to a Network Diagnostics Framework incident. This handle should match the handle of an existing incident. + /// Pointer to a string that contains the location of the trace file. + /// A HResult value indicating the result + [DllImport("ndfapi.dll", CharSet = CharSet.Unicode)] + public static extern HResult NdfGetTraceFile( + [In] IntPtr NdfHandle, + [Out] string TraceFileLocation + ); + + #endregion + #region Private Namespaces [DllImport("kernel32.dll", SetLastError = true)] diff --git a/trunk/ProcessHacker/Common/PhUtils.cs b/trunk/ProcessHacker/Common/PhUtils.cs index eb1a52bc8..562c4ce5e 100644 --- a/trunk/ProcessHacker/Common/PhUtils.cs +++ b/trunk/ProcessHacker/Common/PhUtils.cs @@ -206,6 +206,34 @@ namespace ProcessHacker.Common return endPoint.Address.GetAddressBytes().IsEmpty() && endPoint.Port == 0; } + public static void IsNetworkError(string url) + { + if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista)) + { + IntPtr ndfhandle = IntPtr.Zero; + + HResult ndfCreate = Win32.NdfCreateWebIncident(url, ref ndfhandle); + ndfCreate.ThrowIf(); + + Win32.NdfExecuteDiagnosis(ndfhandle, IntPtr.Zero); //Will throw error if user cancels + Win32.NdfCloseIncident(ndfhandle); + } + } + + public static void IsNetworkError(string url, IntPtr hwnd) + { + if (OSVersion.IsAboveOrEqual(WindowsVersion.Vista)) + { + IntPtr ndfhandle = IntPtr.Zero; + + HResult ndfCreate = Win32.NdfCreateWebIncident(url, ref ndfhandle); + ndfCreate.ThrowIf(); + + Win32.NdfExecuteDiagnosis(ndfhandle, hwnd); //Will throw error if user cancels + Win32.NdfCloseIncident(ndfhandle); + } + } + /// /// Opens a registry key in the Registry Editor. ///