1

I am developing a c# .Net3.5 application.

The applications checks the signature of files using WinVerifyTrust. The problem is that on isolated networks (i.e. no Internet access but machine still has an IP address) it takes a very long time (~20 seconds) until WinVerifyTrust returns.

Is there a way to identify this situation?

user844541
  • 2,868
  • 5
  • 32
  • 60

2 Answers2

2

Have you tried using the Windows API-

using System;
using System.Runtime;
using System.Runtime.InteropServices;

    public class InternetCS
    {
        //Creating the extern function...
        [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState( out int Description, int ReservedValue );

        //Creating a function that uses the API function...
        public static bool IsConnectedToInternet( )
        {
            int Desc ;
            return InternetGetConnectedState( out Desc, 0 ) ;
        }
    }
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
1

And how you will differentiate if the computer is connected with a slow internet connection?

Anyway you can Ping google (for example) to see if it's available. If the computer is not isolated it will be available.

To ping from C# just use System.Net.NetworkInformation.Ping

EDIT: if you need to support being behind a proxy then you should open a TcpConnection over the google port 80 and check if you can or you cannot. If you cannot open a port to google's 80 you cannot connect to WinVerifyTrust either.

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
  • you are correct, but on a slow network connections it is ok that my application will work slowly, but when using isolated networks it's not. – user844541 Oct 24 '12 at 09:17
  • I get request timeout when trying to ping google no matter if I am connected to the internet or not. – user844541 Oct 24 '12 at 15:51
  • Can you post your code? I've done this several times in the past and it works. Can you check if you can ping google from the commandline too? – Ignacio Soler Garcia Oct 24 '12 at 19:18
  • @user844541: so ... ? Comm'on :) – Ignacio Soler Garcia Oct 25 '12 at 07:52
  • what?? I thought that maybe the firewall blocks the ping response . anyhow,my point is that ping can fail even if you have internet connection. so if ping failed it's not enough inorder to determine whether you're connected to the internet or not. – user844541 Oct 25 '12 at 08:13
  • @user844541: you're wrong. If you cannot access google pinging it then you can be almost sure that you won't be able to access WinVerifyTrust. Nobody blocks outgoing traffic (even less if it's ICMP). The only possible scenario that I can think of is if you're on a proxy. – Ignacio Soler Garcia Oct 25 '12 at 08:56