示例#1
0
        private void OnedriveButton_Click(object sender, EventArgs e)
        {
            ModifyRegistry.ModifyRegistry userShellFolders = new ModifyRegistry.ModifyRegistry(Registry.CurrentUser, @"Microsoft", @"Windows\CurrentVersion\Explorer\User Shell Folders");
            ModifyRegistry.ModifyRegistry onedriveFolder   = new ModifyRegistry.ModifyRegistry(Registry.CurrentUser, @"Microsoft", @"Onedrive\Accounts\Business1");

            string oneDriveDesktopPath   = onedriveFolder.ReadString("UserFolder") + @"\Desktop\";
            string oneDriveDocumentsPath = onedriveFolder.ReadString(@"UserFolder") + @"\Documents\";
            string desktopShellPath      = userShellFolders.ReadString(@"{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}") + @"\";
            string documentsShellPath    = userShellFolders.ReadString(@"Personal") + @"\";

            try
            {
                if (@desktopShellPath != @oneDriveDesktopPath)
                {
                    UIOption       showUI       = UIOption.AllDialogs;
                    UICancelOption onUserCancel = UICancelOption.ThrowException;
                    FileSystem.CopyDirectory(@desktopShellPath, @oneDriveDesktopPath, showUI, onUserCancel);
                }
            }
            catch (Exception dMoveEx)
            {
                MessageBox.Show(dMoveEx.Message + dMoveEx.TargetSite);
            }

            userShellFolders.WriteString(@"{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}", @oneDriveDesktopPath.TrimEnd(char.Parse(@"\")));
            userShellFolders.WriteString(@"Desktop", @oneDriveDesktopPath.TrimEnd(char.Parse(@"\")));

            try
            {
                if (documentsShellPath != oneDriveDocumentsPath)
                {
                    UIOption         showUI       = UIOption.AllDialogs;
                    UICancelOption   onUserCancel = UICancelOption.ThrowException;
                    FileIOPermission f            = new FileIOPermission(PermissionState.Unrestricted);
                    f.AllFiles = FileIOPermissionAccess.AllAccess;
                    FileSystem.CopyDirectory(documentsShellPath, oneDriveDocumentsPath, showUI, onUserCancel);
                }
            }
            catch (Exception dMoveEx)
            {
                MessageBox.Show(dMoveEx.Message);
            }

            userShellFolders.WriteString(@"Personal", oneDriveDocumentsPath.TrimEnd(char.Parse(@"\")));

            RestartProcess.RestartProcessByFileName("explorer");

            UpdateOnedriveInfo();
        }
示例#2
0
        private void RestoreOneDriveReg()
        {
            ModifyRegistry.ModifyRegistry userShellFolders = new ModifyRegistry.ModifyRegistry(Registry.CurrentUser, @"Microsoft", @"Windows\CurrentVersion\Explorer\User Shell Folders");
            ModifyRegistry.ModifyRegistry onedriveFolder   = new ModifyRegistry.ModifyRegistry(Registry.CurrentUser, @"Microsoft", @"Onedrive\Accounts\Business1");

            string desktopShellPath   = userShellFolders.ReadString(@"{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}");
            string documentsShellPath = userShellFolders.ReadString(@"Personal");

            string defaultDesktopShellPath   = @"C:\Users\" + Environment.UserName + @"\Desktop";
            string defaultDocumentsShellPath = @"C:\Users\" + Environment.UserName + @"\Documents";

            RestartProcess.KillProcessByFileName("OneDrive");


            userShellFolders.WriteString(@"{754AC886-DF64-4CBA-86B5-F7FBF4FBCEF5}", defaultDesktopShellPath);
            userShellFolders.WriteString(@"Desktop", defaultDesktopShellPath);

            try
            {
                if (documentsShellPath != defaultDocumentsShellPath)
                {
                    FileSystem.CopyDirectory(documentsShellPath, defaultDocumentsShellPath, false);
                }
            }
            catch (Exception fileMoveE)
            {
                MessageBox.Show(fileMoveE.Message);
            }

            userShellFolders.WriteString(@"Personal", defaultDocumentsShellPath);

            RestartProcess.KillProcessByFileName("explorer");

            Process.Start("explorer.exe");

            UpdateOnedriveInfo();
        }