zoukankan      html  css  js  c++  java
  • win 10 C#解决访问长路径失败,并指定程序具有admin权限

    https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN
    https://docs.microsoft.com/en-us/archive/blogs/jeremykuhne/net-4-6-2-and-long-paths-on-windows-10
    .NetFramework 选择4.6.2
    右键项目,添加manifest

    这个文件中下图注释部分取消注释,并添加

    这个文件中下图注释部分取消注释,并添加

     <application xmlns="urn:schemas-microsoft-com:asm.v3">
      <windowsSettings>
        <longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
      </windowsSettings>
    </application>

    修改注册表
    HKLMSYSTEMCurrentControlSetControlFileSystem LongPathsEnabled (Type: REG_DWORD) 设置为1

    修改policy all setting 中enable win32 long paths

    设置程序具有admin权限

    <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <!-- UAC Manifest Options
                 If you want to change the Windows User Account Control level replace the 
                 requestedExecutionLevel node with one of the following.
    
            <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
            <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
            <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
    
                Specifying requestedExecutionLevel element will disable file and registry virtualization. 
                Remove this element if your application requires this virtualization for backwards
                compatibility.
            -->
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
          </requestedPrivileges>

    测试代码

    string reallyLongDirectory = @"C:BuildabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                        reallyLongDirectory = reallyLongDirectory + @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
                        reallyLongDirectory = reallyLongDirectory + @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
                        //Console.WriteLine($"Creating a directory that is {rea

    转:https://blog.csdn.net/weixin_43632687/article/details/104750738

  • 相关阅读:
    如果看了此文你还不懂傅里叶变换,那就过来掐死我吧【完整版】(ZZ伯乐在线)
    探索推荐引擎内部的秘密,第 2 部分: 深入推荐引擎相关算法
    Slope One :简单高效的协同过滤算法(Collaborative Filtering)(ZZ)
    非常的好的协同过滤入门文章(ZZ)
    防止rm误操作的方法(zz)
    CentOS使用YUM安装Adobe Flash Player
    今天尝试dd命令制作CentOS启动优盘
    关于php中,POST方法接收不到内容
    linux系统下使用vim 显示行号~
    打开php的错误提示
  • 原文地址:https://www.cnblogs.com/superfeeling/p/14851576.html
Copyright © 2011-2022 走看看