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>

  • 相关阅读:
    C++文件流类与文件流对象
    当java出现异常,应如何进行处理
    C语言函数的声明以及函数原型
    MySQL的create table as 与 like区别
    java中BigDecimal加减乘除基本用法
    项目小结
    自动化测试 如何快速提取Json数据
    Java Map 集合类在selenium自动化测试设计中的应用
    UFT对于PDF 文档的操作方法 VBS代码
    Selenium 自动化测试中对页面元素的value比较验证 java语言
  • 原文地址:https://www.cnblogs.com/LilianChen/p/2922458.html
Copyright © 2011-2022 走看看