예제 #1
0
            public void Dispose()
            {
                if (!_mapped)
                {
                    return;
                }

                WshNetwork net = null;

                try
                {
                    net = new WshNetworkClass();
                    object force         = true;
                    object updateProfile = false;
                    net.RemoveNetworkDrive(_letterPath, ref force, ref updateProfile);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to disconnect drive: {0}.", ex.Message);
                }
                finally
                {
                    if (net != null)
                    {
                        Marshal.ReleaseComObject(net);
                    }
                }
            }
예제 #2
0
        private async void restartDisk_Click(object sender, EventArgs e)
        {
            try
            {
                WshNetwork network     = new WshNetwork();
                Ping       pngSERV     = new Ping();
                PingReply  replictSERV = await pngSERV.SendPingAsync(addressSERV);

                if (replictSERV.Status == IPStatus.Success)
                {
                    //поиск сетевого диска
                    foreach (DriveInfo d in DriveInfo.GetDrives())
                    {
                        if (d.DriveType == DriveType.Network && d.Name == "Z" + @":\")
                        {
                            network.RemoveNetworkDrive("Z:", true, true); //Отключение найденного сетевого диска
                        }
                    }
                    //Подключение сетевого диска
                    object save = false;
                    object user = "******", pass = "******";
                    network.MapNetworkDrive("Z:", @"\\10.7.0.1\share500gb", ref save, ref user, ref pass);
                }
                else
                {
                    XtraMessageBox.Show("Сервер не доступен! Проверьте подключение VPN!");
                }
            }
            catch (Exception)
            {
                XtraMessageBox.Show("Сервер не доступен! Проверьте подключение VPN!");
            }
        }
예제 #3
0
            public MappedDrive(char driveLetter, string url)
            {
                _letterPath = driveLetter + ":";

                WshNetwork net = null;

                try
                {
                    net = new WshNetworkClass();
                    object updateProfile = false;
                    net.MapNetworkDrive(_letterPath, url, ref updateProfile);
                    _mapped = true;
                    // use windows explorer to test it!
                    using (System.Diagnostics.Process.Start(_letterPath)) { }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Failed to connect drive: {0}.", ex.Message);
                }
                finally
                {
                    if (net != null)
                    {
                        Marshal.ReleaseComObject(net);
                    }
                }
            }
예제 #4
0
파일: Form1.cs 프로젝트: Annushka34/WinForm
        private void butGetPrinters_Click(object sender, EventArgs e)
        {
            WshNetwork network = new WshNetwork();

            foreach (IEnumerable printer in network.EnumPrinterConnections())
            {
                listBox1.Items.Add(printer);
            }
        }
예제 #5
0
파일: Form1.cs 프로젝트: Annushka34/WinForm
        private void butNetworkDrives_Click(object sender, EventArgs e)
        {
            WshNetwork network = new WshNetwork();

            foreach (IEnumerable driver in network.EnumNetworkDrives())
            {
                MessageBox.Show(driver.ToString());
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            WshNetwork network = new WshNetwork();

            foreach (IEnumerable driver in network.EnumNetworkDrives())
            {
                Console.WriteLine(driver.ToString());
            }

            Console.ReadLine();
        }
예제 #7
0
        static void Main(string[] args)
        {
            WshNetwork network = new WshNetwork();

            foreach (IEnumerable printer in
                     network.EnumPrinterConnections())
            {
                Console.WriteLine(printer.ToString());
            }

            Console.ReadLine();
        }
예제 #8
0
파일: Form1.cs 프로젝트: Annushka34/WinForm
        private void butSetDefaultPrinter_Click(object sender, EventArgs e)
        {
            WshNetwork network = new WshNetwork();

            // ѕолучим список принтеров
            IWshCollection Printers = network.EnumPrinterConnections();

            if (Printers.Count() > 0)
            {
                // ¬ыбираем индекс устанавливаемого принтера
                object index = (object)"1";
                // ”станавливаем выбранный принтер как принтер по умолчанию
                network.SetDefaultPrinter((string)Printers.Item(ref index));
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            WshNetwork network = new WshNetwork();

            // получить список принтеров
            IWshCollection Printers = network.EnumPrinterConnections();

            if (Printers.Count() > 0)
            {
                // индекс устанавливаемого принтера в списке принтеров
                object index = (object)"1";
                // установка принтера с выбранным индексом
                // как принтера по умолчанию
                network.SetDefaultPrinter((string)Printers.Item(ref index));
            }
        }
예제 #10
0
        public void MapNetworkDrive(string driveLetter, string path)
        {
            IWshNetwork wshn = new WshNetwork();

            try
            {
                try
                {
                    object missingArgument = Type.Missing;
                    wshn.MapNetworkDrive(driveLetter, path, ref missingArgument, ref missingArgument, ref missingArgument);
                }
                catch (Exception ex)
                {
                    // Ignore unc path
                    editNarrative.AppendText(string.Format("\r\n\r\nHMRCFilingService: Error mapping drive {0} to {1}\r\n{2}", driveLetter, path, ex.Message));
                }
            }
            finally
            {
                wshn = null;
            }
        }
예제 #11
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            printersplit = args[0].TrimStart('z', 'p', 'r', 'i', 'n', 't', 'e', 'r', ':').Split('+');
            servername   = printersplit[0];
            sharename    = Uri.UnescapeDataString(printersplit[1]);
            printershare = "\\\\" + servername + "\\" + sharename;


            Ping ping = new Ping();

            try {
                pingReply = ping.Send(servername);
            } catch
            {
                MessageBox.Show("Print server is not available.\nPlease make sure you can access Zeon's network.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (pingReply.Status == IPStatus.Success)
            {
                PrintServer printServer = new PrintServer(@"\\" + servername);
                try
                {
                    PrintQueue printQueue = printServer.GetPrintQueue(printershare);
                } catch
                {
                    MessageBox.Show("Printer cannot be found on print server.\nPlease verify that printer exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                BackgroundWorker bg = new BackgroundWorker();
                bg.DoWork             += new DoWorkEventHandler(bg_DoWork);
                bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);

                foreach (string printer in PrinterSettings.InstalledPrinters)
                {
                    if (printershare == printer)
                    {
                        printerExist = true;
                    }
                }
                if (printerExist)
                {
                    MessageBox.Show("Printer is already available on your computer.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    bg.RunWorkerAsync();
                    progressBar.ShowDialog();
                }
                void bg_DoWork(object sender, DoWorkEventArgs e)
                {
                    WshNetwork printerAdd = new WshNetwork();

                    printerAdd.AddWindowsPrinterConnection(printershare);
                }

                void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
                {
                    do
                    {
                        foreach (string printer in PrinterSettings.InstalledPrinters)
                        {
                            if (printershare == printer)
                            {
                                printerExist = true;
                            }
                        }
                        Thread.Sleep(500);
                    } while (!printerExist);
                    progressBar.FormClosed += new FormClosedEventHandler(addComplete);
                    progressBar.Close();

                    void addComplete(object sender1, FormClosedEventArgs e1)
                    {
                        MessageBox.Show("Printer has been successfully added!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else
            {
                MessageBox.Show("Print server is not available.\nPlease make sure you can access Zeon's network.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #12
0
        //Drive Mappings
        public static string[] GetMappedNetworkDrives()
        {
            //Get Network
            IWshNetwork_Class network = new IWshNetwork_Class();
            WshNetwork net = new WshNetwork();

            //Get Network Drives
            IWshCollection colNetDrives = net.EnumNetworkDrives();

            //CYcle
            var enumerator = colNetDrives.GetEnumerator();
            var rll = new List<string>();
            while (enumerator.MoveNext())
            {

                //Get current item
                string item = enumerator.Current as string;

                //If Item is localname of drive and the local name is null, set onlocalname to false for next iteratoni and continue
                if (item == "")
                {
                    enumerator.MoveNext();
                    continue;
                }

                //item has name, store in return list
                enumerator.MoveNext();
                rll.Add(item + "?" + (enumerator.Current as string));
            }

            return rll.ToArray();
        }
예제 #13
0
 public static void UnMapNetworkDrive(String localName)
 {
     WshNetwork net = new WshNetwork();
     net.RemoveNetworkDrive(localName, true, true);
 }
예제 #14
0
 public static void MapNetworkDrive(String local, String remote)
 {
     WshNetwork net = new WshNetwork();
     net.MapNetworkDrive(local, remote);
 }