Ejemplo n.º 1
0
        /// <summary>
        /// 接続する
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            bool fResult = false;

            NativeMethods.NETRESOURCE netResource = new NativeMethods.NETRESOURCE();
            netResource.dwScope       = 0;
            netResource.dwType        = 1;
            netResource.dwDisplayType = 0;
            netResource.dwUsage       = 0;
            netResource.lpLocalName   = "";
            netResource.lpRemoteName  = NetworkPath;
            netResource.lpProvider    = "";

            try
            {
                fResult = (NativeMethods.WNetCancelConnection2(NetworkPath, 0, true) == 0) ? true : false;
                fResult = (NativeMethods.WNetAddConnection2(ref netResource, NetworkPassword, NetworkUsername, 0) == 0) ? true : false;
            }
            catch (Exception)
            {
                return(fResult = false);
            }

            return(fResult);
        }
        /// <summary>
        /// 接続する
        /// </summary>
        /// <returns></returns>
        public bool Connect()
        {
            bool fResult = false;

            NativeMethods.NETRESOURCE netResource = new NativeMethods.NETRESOURCE();
            netResource.dwScope = 0;
            netResource.dwType = 1;
            netResource.dwDisplayType = 0;
            netResource.dwUsage = 0;
            netResource.lpLocalName = "";
            netResource.lpRemoteName = NetworkPath;
            netResource.lpProvider = "";

            try
            {
                fResult = (NativeMethods.WNetCancelConnection2(NetworkPath, 0, true) == 0) ? true : false;
                fResult = (NativeMethods.WNetAddConnection2(ref netResource, NetworkPassword, NetworkUsername, 0) == 0) ? true : false;
            }
            catch (Exception)
            {
                return fResult = false;
            }

            return fResult;
        }