我想从一个服务器复制一个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();
}
}
}
随着SCCM您可以通过以下步骤实现:
string fileNameWithExt = "your folderpath and filename";
string destPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileNameWithExt);
这将确保不仅所有用户,但现在所有在未来将得到该计划。它也帮助你,如果你真的想从一个服务器副本,因为在默认情况下使用SCCM其中有您的服务器共享没有访问权限(虽然你能给他们)在本地系统帐户。该也应尽可能与应用程序,而不是一个项目。
缺点是: