Esempio n. 1
0
        /// <summary>
        /// Display windows dialog for mapping a network drive
        /// </summary>
        //public void ShowConnectDialog(Form ParentForm) { zDisplayDialog(ParentForm, 1); }
        /// <summary>
        /// Display windows dialog for disconnecting a network drive
        /// </summary>
        //public void ShowDisconnectDialog(Form ParentForm) { zDisplayDialog(ParentForm, 2); }

        #endregion


        #region Internal to Class Core functions

        // Map network drive
        private int zMapDrive(string psUsername, string psPassword)
        {
            //create struct data
            netResourceStruct stNetRes = new netResourceStruct();

            stNetRes.dwScope       = (uint)WinNetConst.RESOURCE_GLOBALNET;
            stNetRes.dwType        = (uint)WinNetConst.RESOURCETYPE_DISK;
            stNetRes.dwDisplayType = (uint)WinNetConst.RESOURCEDISPLAYTYPE_SHARE;
            stNetRes.dwUsage       = (uint)WinNetConst.RESOURCEUSAGE_CONNECTABLE;
            stNetRes.sRemoteName   = ls_ShareName;
            stNetRes.sLocalName    = ls_Drive;
            //prepare params
            uint iFlags = 0;

            if (lf_SaveCredentials)
            {
                iFlags += (uint)WinNetConst.CONNECT_CMD_SAVECRED;
            }
            if (lf_Persistent)
            {
                iFlags += (uint)WinNetConst.CONNECT_UPDATE_PROFILE;
            }
            if (ls_PromptForCredentials)
            {
                iFlags += (uint)WinNetConst.CONNECT_INTERACTIVE + (uint)WinNetConst.CONNECT_PROMPT;
            }
            if (psUsername == "")
            {
                psUsername = null;
            }
            if (psPassword == "")
            {
                psPassword = null;
            }
            //if force, unmap ready for new connection
            if (lf_Force)
            {
                try { zUnMapDrive(true); } catch { }
            }
            //call and return
            try
            {
                int i = WNetAddConnection2(ref stNetRes, psPassword, psUsername, iFlags);
                if (i > 0)
                {
                    throw new System.ComponentModel.Win32Exception(i);
                }
            }
            catch (System.ComponentModel.Win32Exception w)
            {
                GenMsg4Win32Ex(w);
                return(1);
            }
            return(0);
        }
Esempio n. 2
0
 [DllImport("mpr.dll")] private static extern int WNetAddConnection2(ref netResourceStruct pstNetRes, string psPassword, string psUsername, uint piFlags);