Exemplo n.º 1
0
    public int GetDriveSpace(string shareName, string userName, string password)
    {
        NETRESOURCEA[] n = new NETRESOURCEA[1];
        n[0] = new NETRESOURCEA();

        n[0].dwScope       = 0;
        n[0].dwType        = 0;
        n[0].dwDisplayType = 0;
        n[0].dwUsage       = 0;

        n[0].dwType = 1;

        n[0].lpLocalName  = "x:";
        n[0].lpRemoteName = shareName;
        n[0].lpProvider   = null;

        int res = WNetAddConnection2A(n, userName, password, 1);

        DriveInfo info  = new DriveInfo("x:");
        int       space = info.AvailableFreeSpace;

        int err = 0;

        err = WNetCancelConnection2A("x:", 0, 1);

        return(space);
    }
Exemplo n.º 2
0
        //开始远程连接
        public bool RemoteConnect(bool bConnected)
        {
            int res;

            NETRESOURCEA[] n = new NETRESOURCEA[1];
            n[0]        = new NETRESOURCEA();
            n[0].dwType = 1;
            int dwFlags = 1; // CONNECT_INTERACTIVE;

            n[0].lpLocalName  = @"X:";
            n[0].lpRemoteName = shareResDictionary;
            //n[0].lpRemoteName = @"\\wanglh\manageshare";
            n[0].lpProvider = null;
            if (bConnected)
            {
                res = WNetAddConnection2(n, userPwd, userName, dwFlags);
            }
            else
            {
                res = WNetCancelConnection2(shareResDictionary, 1, true);
            }
            return((res == 0) ? true : false);
        }