1

Tried to search for something similar but could not find.

I have file on a remote machine which I want to query for it`s details like version, date, etc. How do I do that when I need to enter credentials for that machine? FileVersionInfo does not give option to do so.

Thanks

Update:

As I said above I checked what FIleVersionInfo gives me (and also tried it) and that will not work for me. I also tried using WMI and failed with (although it looked like the direction I need) Here is the WMI code I tried - haven`t got much far:

var computerName = "IP_ADDRESS";
            ConnectionOptions conn = new ConnectionOptions();
            conn.Username = "username";
            conn.Password = "password";
            conn.Authority = "ntlmdomain:DOMAIN";
            conn.Impersonation = ImpersonationLevel.Impersonate;
            conn.EnablePriviledges = true;
            var scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", computerName), conn);


            scope.Connect();
            string Drive = "c:";
            string Path = "\\\\inetpub\\\\wwwroot\\\\FOLDER\\\BIN\\\File.dll";

            ObjectQuery Query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile Where Drive='{0}' AND Path='{1}' ", Drive, Path));

            ManagementObjectSearcher Searcher = new ManagementObjectSearcher(scope, Query);

            foreach (ManagementObject WmiObject in Searcher.Get())
            {
                Console.WriteLine("{0}", (string)WmiObject["Name"]);// String
            }

I mainly need the file properties version and date.

Thanks

shahar eldad
  • 861
  • 1
  • 12
  • 31
  • 1
    Please show us your research. Provide links and explain *explicitly* why they didn't answer your question. – rory.ap May 26 '16 at 13:28
  • Possible duplicate : http://stackoverflow.com/questions/2417878/read-file-on-a-remote-server – SunilA May 26 '16 at 13:33
  • What does your WMI code fail on? I've played around with it before and know it can be done. Have you tried setting the following flags in your WMI code? [Impersonation](https://msdn.microsoft.com/en-us/library/system.management.connectionoptions.impersonation.aspx) and [EnablePrivileges](https://msdn.microsoft.com/en-us/library/system.management.connectionoptions.enableprivileges.aspx) – Draken May 26 '16 at 14:25
  • I have added the Impersonation as Impersonate and EnablePriviledges as true. I fail when I get to the Connect method. – shahar eldad May 29 '16 at 05:53
  • @Draken Thanks. It was a mixture of your suggestions and mistaking in the domain name. Now I can carry on to get the details. – shahar eldad May 29 '16 at 06:06

1 Answers1

2

Thanks to @Draken comment above I`ve added missing properties on the ConnectionOptions and also fixed my mistake on the domain name.

Here is the code I use to get to the file in the network PC

var computerName = "IP_ADDRESS";
        ConnectionOptions conn = new ConnectionOptions();
        conn.Username = "username";
        conn.Password = "password";
        conn.Authority = "ntlmdomain:DOMAIN";
        conn.Impersonation = ImpersonationLevel.Impersonate;
        conn.EnablePriviledges = true;
        var scope = new ManagementScope(String.Format("\\\\{0}\\root\\CIMV2", computerName), conn);


        scope.Connect();
        string Drive = "c:";
        string Path = "\\\\inetpub\\\\wwwroot\\\\FOLDER\\\BIN\\\File.dll";

        ObjectQuery Query = new ObjectQuery(string.Format("SELECT * FROM CIM_DataFile Where Drive='{0}' AND Path='{1}' ", Drive, Path));

        ManagementObjectSearcher Searcher = new ManagementObjectSearcher(scope, Query);

        foreach (ManagementObject WmiObject in Searcher.Get())
        {
            Console.WriteLine("{0}", (string)WmiObject["Name"]);// String
        }
shahar eldad
  • 861
  • 1
  • 12
  • 31