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>

  • 相关阅读:
    利用STM32播放音乐
    在MDK中使用$Sub$$和$Super$$的记录
    printf函数输出格式控制记录
    I2C软件实现
    C语言单项链表
    CreateEvent函数使用记录
    C语言宏定义使用记录
    GIT推送本地数据到远程空仓库
    2020-ECCV-Local Correlation Consistency for Knowledge Distillation阅读笔记
    2020-ECCV-Feature Normalized Knowledge Distillation for Image Classfication阅读笔记
  • 原文地址:https://www.cnblogs.com/LilianChen/p/2922458.html
Copyright © 2011-2022 走看看