简体   繁体   English

具有管理员访问权限,但抛出 System.ComponentModel.Win32Exception:“访问被拒绝。”

[英]has admin access but throws System.ComponentModel.Win32Exception: 'Access is denied.'

Ok so it opens as administrator, I've put requireAdministrator in the app.manifest, it has access because it writes the file but it does the System.ComponentModel.Win32Exception: 'Access is denied.'好的,所以它以管理员身份打开,我已将 requireAdministrator 放在 app.manifest 中,它具有访问权限,因为它写入文件但它执行 System.ComponentModel.Win32Exception:'访问被拒绝。' when it tries to run it.当它试图运行它时。 so is it the folder its going to or is it something else?那么是它要去的文件夹还是其他东西?

using System;
using System.IO;
namespace testing_code
{
class Program
{
    static void Main(string[] args)
    {

        Console.WriteLine("type off");
        string userInput = Console.ReadLine();
        if(userInput == "off")
            {
            turnOffUAC();
            };
        Console.WriteLine("well did it work?");
        Console.ReadLine();
        static void turnOffUAC()
        {
       
                //this is the path the document or in our case batch file will be placed
                
                string path1 = "c:\\LegendTools";

                // this is the batch commands remember its "", the comma seperates the lines
                string[] lines =
                {
                "@echo off",
                "reg.exe ADD HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v EnableLUA /t REG_DWORD /d 0 /f",
                "del \"%~f0\""
                };
            //this writes the string to the file
            using (StreamWriter outputFile = new StreamWriter(Path.Combine(path1, "test.bat")))
            {
                //This writes the file line by line
                foreach (string line in lines)
                    outputFile.WriteLine(line);
            }
            System.Diagnostics.Process.Start(path1);

thanks to thanks to Dxiv's wise words its been fixed It throws the error at System.Diagnostics.Process.Start(path1);多亏了Dxiv 的明智的话,它已得到修复它在 System.Diagnostics.Process.Start(path1); 处引发错误this is because string path1 = "c:\LegendTools";这是因为 string path1 = "c:\LegendTools"; is trying to start the directory not the bat file.正在尝试启动目录而不是 bat 文件。

using System;
using System.IO;
namespace testing_code
{
class Program
{
static void Main(string[] args)
{

    Console.WriteLine("type off");
    string userInput = Console.ReadLine();
    if(userInput == "off")
        {
        turnOffUAC();
        };
    Console.WriteLine("well did it work?");
    Console.ReadLine();
    static void turnOffUAC()
    {
   
            //this is the path the document or in our case batch file will be placed
            
            string docPath = "c:\\LegendTools";
            string path1 = docPath + "\\Test.bat";

            // this is the batch commands remember its "", the comma seperates the lines
            string[] lines =
            {
            "@echo off",
            "reg.exe ADD HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v EnableLUA /t REG_DWORD /d 0 /f",
            "del \"%~f0\""
            };
        //this writes the string to the file
         using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, "test.bat")))
        {
            //This writes the file line by line
            foreach (string line in lines)
                outputFile.WriteLine(line);
        }
        System.Diagnostics.Process.Start(path1);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.ComponentModel.Win32Exception:访问被拒绝 - System.ComponentModel.Win32Exception : Access is denied System.ComponentModel.Win32Exception:访问被拒绝...错误 - System.ComponentModel.Win32Exception: Access is denied… Error System.ComponentModel.Win32Exception:访问被拒绝 - System.ComponentModel.Win32Exception: Access is denied System.ComponentModel.Win32Exception:访问被拒绝错误 - System.ComponentModel.Win32Exception: Access is denied Error System.ComponentModel.Win32Exception(0x80004005):访问被拒绝 - System.ComponentModel.Win32Exception (0x80004005): Access is denied System.ComponentModel.Win32Exception:尝试从 ebay 获取令牌时拒绝访问 - System.ComponentModel.Win32Exception: Access is denied while trying to get token from ebay System.ComponentModel.Win32Exception:“拒绝访问” - System.ComponentModel.Win32Exception: „Acces is denied” System.ComponentModel.Win32Exception: 使用 FlaUI+SpecFlow 自动化 WPF 应用程序时出现“拒绝访问”错误 - System.ComponentModel.Win32Exception: 'Access is denied' error while Automating a WPF app using FlaUI+SpecFlow C#Process.GetProcessById(4)引发System.ComponentModel.Win32Exception - C# Process.GetProcessById(4) throws System.ComponentModel.Win32Exception Selenium C# 4.7.0 在尝试使用 chromedriver 时抛出 System.ComponentModel.Win32Exception - Selenium C# 4.7.0 throws System.ComponentModel.Win32Exception when tried to use the chromedriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM