[英]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.