zoukankan      html  css  js  c++  java
  • Copy files to a folder which need have Administrator approve and overwrite the existing same readonly files

    1. Program.cs

    using System;

    using System.IO;

    namespace CopyUnitTestDriver

    {

    classProgram

    {

    staticvoid Main(string[] args)

    {

    string destinationPath = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Blend\Test\";

    string sourcePath = @"\\authoring\Public\User\v-lingc\blendRun\UnitTestDriver";

    string[] filePath = newstring[] { destinationPath + @"UnitTestDriver.exe", destinationPath + @"UnitTestDriver.exe.config", destinationPath + @"UnitTestDriver.exe.vspscc", destinationPath + @"UnitTestDriver.pdb" };

    FileInfo[] oldFiles = newFileInfo[] { newFileInfo(filePath[0]), newFileInfo(filePath[1]), newFileInfo(filePath[2]), newFileInfo(filePath[3]) };

    foreach (string file in filePath)

    {

    FileAttributes attributes = File.GetAttributes(file);

    if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)

    {

    attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);

    File.SetAttributes(file, attributes);

    }

    }

    foreach (FileInfo file in oldFiles)

    {

    file.Delete();

    }

    DirectoryInfo info = newDirectoryInfo(sourcePath);

    foreach (FileSystemInfo fsi in info.GetFileSystemInfos())

    {

    String destName = Path.Combine(destinationPath, fsi.Name);

    File.Copy(fsi.FullName, destName, true);

    }

    }

    privatestaticFileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)

    {

    return attributes & ~attributesToRemove;

    }

    }

    }

     2. Add a new item Application Manifest File:

    <?xmlversion="1.0"encoding="utf-8"?>

    <asmv1:assemblymanifestVersion="1.0"xmlns="urn:schemas-microsoft-com:asm.v1"xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

      <assemblyIdentityversion="1.0.0.0"name="MyApplication.app"/>

      <trustInfoxmlns="urn:schemas-microsoft-com:asm.v2">

        <security>

          <requestedPrivilegesxmlns="urn:schemas-microsoft-com:asm.v3">

            <requestedExecutionLevellevel="highestAvailable"uiAccess="false" />

          </requestedPrivileges>

        </security>

      </trustInfo>

      <compatibilityxmlns="urn:schemas-microsoft-com:compatibility.v1">

        <application>

        </application>

      </compatibility>

    </asmv1:assembly>

  • 相关阅读:
    阿里云安装Mono 发生错误解决方法
    在Entity Framework 中执行Tsql语句
    WinRT app guide
    开源稳定的消息队列 RabbitMQ
    Catpic: OpenSocial Container on .NET
    MSDTC 故障排除
    HTML5 canvas图形库RGraph
    《我的WCF之旅》博文系列汇总
    TSQL Enhancement in SQL Server 2005[下篇]
    谈谈基于SQL Server 的Exception Handling[上篇]
  • 原文地址:https://www.cnblogs.com/LilianChen/p/2922458.html
Copyright © 2011-2022 走看看