示例#1
0
 public static extern int WNetAddConnection2
     (ref NETRESOURCE lpNetResource,
     [MarshalAs(UnmanagedType.LPTStr)]
     string lpPassword,
     [MarshalAs(UnmanagedType.LPTStr)]
     string lpUsername,
     WNetConnectOptions dwFlags);
示例#2
0
        public static void AddConnection
            (IntPtr owner_window,
            string remote_name,
            string provider,
            ResourceType resource_type,
            bool remember)
        {
            NETRESOURCE net_struct = new NETRESOURCE();

            net_struct.dwType       = resource_type;
            net_struct.lpProvider   = provider;
            net_struct.lpRemoteName = remote_name;

            WNetConnectOptions opts = WNetConnectOptions.INTERACTIVE;

            if (remember)
            {
                opts = opts | WNetConnectOptions.UPDATE_PROFILE;
            }

            int res = WinApiWNET.WNetAddConnection3
                          (owner_window,
                          ref net_struct,
                          string.Empty,
                          string.Empty,
                          opts);

            if (res != WinApiWNET.NO_ERROR)
            {
                throw new Win32Exception(res);
            }
        }