Ejemplo n.º 1
0
        internal void OpenWindowsUpdateLog(string username, string password)
        {
            Logger.EnteringMethod();
            string uncPath    = @"\\" + this.Name + @"\C$\Windows";
            string remoteFile = "WindowsUpdate.log";
            string localPath  = GetTemporaryFolder() + this.Name + "-" + Guid.NewGuid() + ".txt";

            NetUse netUse = new NetUse();

            if (netUse.Mount(string.Empty, uncPath, username, password))
            {
                if (System.IO.File.Exists(uncPath + "\\" + remoteFile))
                {
                    try
                    {
                        string remotePath = uncPath + "\\" + remoteFile;

                        System.IO.File.Copy(remotePath, localPath);

                        System.Diagnostics.ProcessStartInfo process = new System.Diagnostics.ProcessStartInfo(Properties.Settings.Default.OpenWindowsUpdateLogWith, "\"" + localPath + "\"");
                        System.Diagnostics.Process.Start(process);
                        System.Threading.Thread.Sleep(3000);
                        System.IO.File.Delete(localPath);
                        netUse.UnMount(uncPath);
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("**** " + ex.Message);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool DeleteFolder(string drive, string parentFolderName, string foldername, string username, string password)
        {
            Logger.EnteringMethod(drive + ":\\" + parentFolderName + "\\" + foldername);
            NetUse netUse = new NetUse();

            try
            {
                if (netUse.Mount(string.Empty, @"\\" + this.Name + @"\" + drive + "$\\" + parentFolderName, username, password))
                {
                    System.IO.DirectoryInfo folderInfo = new System.IO.DirectoryInfo(@"\\" + this.Name + @"\" + drive + "$\\" + parentFolderName + "\\" + foldername);
                    if (folderInfo.Exists)
                    {
                        int attempt = 0;

                        do
                        {
                            try
                            {
                                attempt++;
                                Logger.Write("Trying to delete : " + foldername);
                                folderInfo.Delete(true);
                                Logger.Write(foldername + " deleted");
                                return(true);
                            }
                            catch (Exception ex)
                            {
                                Logger.Write("Failed to delete : " + foldername + ". " + ex.Message);
                                System.Threading.Thread.Sleep(1000);
                            }
                        } while (attempt < 3);

                        Logger.Write("Unable to delete the folder.");
                        return(false);
                    }
                    else
                    {
                        Logger.Write("Can't find the folder");
                        return(false);
                    }
                }
                else
                {
                    Logger.Write("**** Unable to Mount the folder");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 3
0
        private bool CheckTargetDirectory(string remoteDirectory, string username, string password)
        {
            Logger.EnteringMethod(remoteDirectory);
            NetUse netUse = new NetUse();

            try
            {
                if (netUse.Mount(string.Empty, @"\\" + this.Name + @"\" + remoteDirectory, username, password))
                {
                    if (System.IO.File.Exists(@"\\" + this.Name + @"\" + remoteDirectory + @"\InstallPendingUpdates.exe"))
                    {
                        System.Diagnostics.FileVersionInfo remoteFileInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(@"\\" + this.Name + @"\" + remoteDirectory + @"\InstallPendingUpdates.exe");
                        System.Diagnostics.FileVersionInfo localFileInfo  = System.Diagnostics.FileVersionInfo.GetVersionInfo("InstallPendingUpdates.exe");
                        if (remoteFileInfo.FileVersion != localFileInfo.FileVersion)
                        {
                            CopyFile(remoteDirectory, "InstallPendingUpdates.exe");
                        }
                    }
                    else
                    {
                        CopyFile(remoteDirectory, "InstallPendingUpdates.exe");
                    }

                    if (System.IO.File.Exists(@"\\" + this.Name + @"\" + remoteDirectory + @"\Interop.WUApiLib.dll"))
                    {
                        System.Diagnostics.FileVersionInfo remoteFileInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(@"\\" + this.Name + @"\" + remoteDirectory + @"\Interop.WUApiLib.dll");
                        System.Diagnostics.FileVersionInfo localFileInfo  = System.Diagnostics.FileVersionInfo.GetVersionInfo("Interop.WUApiLib.dll");
                        if (remoteFileInfo.FileVersion != localFileInfo.FileVersion)
                        {
                            CopyFile(remoteDirectory, "Interop.WUApiLib.dll");
                        }
                    }
                    else
                    {
                        CopyFile(remoteDirectory, "Interop.WUApiLib.dll");
                    }

                    netUse.UnMount(@"\\" + this.Name + @"\" + remoteDirectory);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.Write("**** " + ex.Message);
            }

            return(false);
        }