See Free Drive Space via IP Address

I know that affordable FreeFreeSpace can be used for local drives like "C: /", "D: /", etc. It also works on network drives.

But now my question is:

Can I view AvailableFreeSpace "Folders" at a different IP address? I connect to local drives with this code:

System.IO.DriveInfo _DriveInfo = new DriveInfo(SaveLocation);

When "SaveLocation" is a local drive, for example, "C: \ Temp \ Folder", it works fine.

But when there is an IP address inside "SaveLocation", it does not work. SaveLocation looks in this case: "192.168.200.10 \ c \ Data"

This does not work, and that is the reason for my question. Exceptionmessage: {"The object must be the root directory (\" C: \\ ") or the drive letter (\" C \ ")." }

I hope you help me.

+4
source share
1 answer

As you can see from Get available free disk space for this path in Windows :

Use the winapi function GetDiskFreeSpaceExto determine the free space on the UNC (network) path. For example, create a new VS project called FreeSpace and paste it as Program.cs:

    using System;
    using System.Runtime.InteropServices;

    namespace FreeSpace
    {
        class Program
        {
            [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
            [return: MarshalAs(UnmanagedType.Bool)]
            static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
                                        out ulong lpFreeBytesAvailable,
                                        out ulong lpTotalNumberOfBytes,
                                        out ulong lpTotalNumberOfFreeBytes);

            static void Main(string[] args)
            {
                ulong FreeBytesAvailable;
                ulong TotalNumberOfBytes;
                ulong TotalNumberOfFreeBytes;

                bool success = GetDiskFreeSpaceEx(@"\\NETSHARE\folder",
                                              out FreeBytesAvailable,
                                              out TotalNumberOfBytes,
                                              out TotalNumberOfFreeBytes);
                if (!success)
                    throw new System.ComponentModel.Win32Exception();

                Console.WriteLine("Free Bytes Available:      {0,15:D}", FreeBytesAvailable);
                Console.WriteLine("Total Number Of Bytes:     {0,15:D}", TotalNumberOfBytes);
                Console.WriteLine("Total Number Of FreeBytes: {0,15:D}", TotalNumberOfFreeBytes);
                Console.ReadKey();
            }
        }
    }

As you can see, this is the same code as in the question above, just taken into account in the class, plus the correct directives usingfor compilation without errors. All loans go to https://stackoverflow.com/users/995926/rekire

WMI, , . Windows - : https://msdn.microsoft.com/en-us/library/aa394592(v=vs.85).aspx

+3

Source: https://habr.com/ru/post/1658403/


All Articles