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>

  • 相关阅读:
    MySQL基础知识-安装MySQL
    java 安装环境 疑问(1)
    java 安装环境
    “64位调试操作花费的时间比预期要长",无法运行调试解决办法
    office完全卸载
    完全卸载oraclean安装
    不能安装64位office提示已安装32位的
    java 之 基础加强(一)
    java 之 dom4j解析xml
    java 之 schema解析
  • 原文地址:https://www.cnblogs.com/LilianChen/p/2922458.html
Copyright © 2011-2022 走看看