如何更换使用SCCM在C#网络上的文件,所有用户配置文件

问题描述 投票:0回答:1

我想从一个服务器复制一个XML文件,然后连接到所有用户配置文件并覆盖它们与一个从服务器复制的用户配置文件的XML文件。我想这是一个可执行的,因此它可以与SCCM为所有用户运行。我知道有将不得不管理权限,但我不能确定如何代码它。我也开来的想法,如何做到这一点不同,但我确实想用C#来做到这一点,使之转化为SCCM一个可执行文件。

   namespace copy_delete_move_files
{
    public class SimpleFileCopy
    {
        public static object Logger { get; private set; }

        static void Main()
        {
            string fileName = "Customize.xml";
            string sourcePath = @"\\pathToServer\c$\TestFolder";
            string targetPath = @"\\pathToUserProfiles\c$\%USERPROFILE%\APPDATA\Roaming\Folder\Customize";

            // Use Path class to manipulate file and directory paths.
            string sourceFile = Path.Combine(sourcePath, fileName);       
            string destFile = Path.Combine(targetPath, fileName);

            // To copy a folder's contents to a new location:
            // Create a new target folder, if necessary.
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }

            // To copy a file to another location and 
            // overwrite the destination file if it already exists.
            File.Copy(sourceFile, destFile, true);

            // To copy all the files in one directory to another directory.
            // Get the files in the source folder.
            // Note: Check for target path was performed previously
            // in this code example.

            if (Directory.Exists(sourcePath))
            {
                string[] files = Directory.GetFiles(sourcePath);

                // Copy the files and overwrite destination files if they already exist.
                foreach (string s in files)
                {
                    // Use static Path methods to extract only the file name from the path.
                    fileName = Path.GetFileName(s);
                    destFile = Path.Combine(targetPath, fileName);
                    File.Copy(s, destFile, true);
                }
            }
            else
            {
                Console.WriteLine("Source path does not exist!");
            }

            // Keep console window open in debug mode.
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
    }
}
c# sccm
1个回答
1
投票

随着SCCM您可以通过以下步骤实现:

  1. 在它适用于一个用户的方式创建你的程序(整个多用户部分将留给SCCM你只是把它写在你的作品一倍任何用户的方式与单击它)。随着应用程序数据路径你只是使用这样的: string fileNameWithExt = "your folderpath and filename"; string destPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileNameWithExt);
  2. 在当您在向导程序的创建SCCM选择“程序可以运行:仅当用户登录”和“运行模式:与用户的权限运行”。一旦创建您进入程序的属性,进入“高级”,并选择“当此程序分配给计算机:为登录的每个用户运行一次”

这将确保不仅所有用户,但现在所有在未来将得到该计划。它也帮助你,如果你真的想从一个服务器副本,因为在默认情况下使用SCCM其中有您的服务器共享没有访问权限(虽然你能给他们)在本地系统帐户。该也应尽可能与应用程序,而不是一个项目。

缺点是:

  • 您的用户都必须被允许访问该共享(可以通过使用sccms分发点的方法来绕过但是,如果服务器上的文件经常更新会比较复杂)
  • 如果您需要任何操作管理权限是不可能这样。如果管理员权限只对那些不是每个用户特定部分,你可以将程序分为两个部分每一个机器,每台计算机之一。
© www.soinside.com 2019 - 2024. All rights reserved.