简体   繁体   English

“无法启动此应用程序。” 仅当文件在 system32 目录中时

[英]“This application could not be started.” Only when the file is in system32 directory

I wrote a little piece of software that downloads file from internet, that is, nothing more.我写了一个从互联网上下载文件的小软件,仅此而已。 My intentions are to use it thru the command line... It works great, but when I place it in C:\\Windows\\System32\\ to actually use it from everywhere I want it doesn't work now... It didn't throw an exception... it just show me this messagebox - http://i.imgur.com/a7rlMgo.png and if I click "Yes" it opens this page in the browser - http://support.microsoft.com/kb/2715633/en-us我的意图是通过命令行使用它......它工作得很好,但是当我将它放在 C:\\Windows\\System32\\ 中以从我想要的任何地方实际使用它时,它现在不起作用......它没有' t 抛出异常...它只是向我显示此消息框 - http://i.imgur.com/a7rlMgo.png ,如果我单击“是”,它会在浏览器中打开此页面 - http://support.microsoft。 com/kb/2715633/en-us

What should I do to get it working?我应该怎么做才能让它工作?

The code if it is of any use.. :代码是否有任何用处..:

private const string InsufficientParametersMessage = "Insufficient Parameters...";

private static string[] _arguments;

static void Main(string[] args)
{
    _arguments = args;

    TakeCommand();

    Environment.Exit(0);
}

private static void TakeCommand()
{
    if (_arguments.Length < 1)
    {
        Console.WriteLine(InsufficientParametersMessage);
    }
    else if (_arguments.Length == 1)
    {
        DownloadFile(_arguments[0]);
    }
    else if (_arguments.Length > 1)
    {
        DownloadFile(_arguments[0], _arguments[1]);
    }
}

private static void DownloadFile(string url)
{
    DownloadFile(url, Path.GetFileName(url));
}

private static void DownloadFile(string url, string localFileName)
{
    WebClient client = new WebClient();

    if (File.Exists(localFileName))
    {
        File.Delete(localFileName);
    }

    try
    {
        client.DownloadFile(url, localFileName);
        Console.WriteLine("Done...");
    }
    catch (Exception exception)
    {
        Console.WriteLine(exception.Message);
    }
}

Short Answer: Uncheck "Prefer 32-bit".简短回答:取消选中“首选 32 位”。

Long Answer: (Not 100% sure but here goes)长答案:(不是 100% 肯定,但在这里)

Assuming you have a 64 bit machine, keep in mind that System32 is a folder that is reserved for 64 bit application usage, and although it may seem strange, SysWOW64 contains 32 bit dlls and is reserved for 32-bit applications.假设您有一台 64 位机器,请记住 System32 是一个为 64 位应用程序保留的文件夹,虽然看起来很奇怪,但 SysWOW64 包含 32 位 dll,并为 32 位应用程序保留。 Typically, 32-bit applications that access System32 will go through a file system redirector to the SysWOW64 folder.通常,访问 System32 的 32 位应用程序将通过文件系统重定向器到达 SysWOW64 文件夹。 More info here .更多信息在这里

However, when your application (which runs as a 32-bit process) runs in System32 itself, the redirector probably doesn't do anything because it thinks there isn't any need to redirect, which is why your app works outside of System32 but not inside it.但是,当您的应用程序(作为 32 位进程运行)在 System32 本身中运行时,重定向器可能不会执行任何操作,因为它认为不需要重定向,这就是您的应用程序在 System32 之外运行的原因,但是不在里面。

So to solve this, uncheck Prefer 32-bit so that it will try to target 64 bit platform, ... or better yet , put the app elsewhere and add the application directory to your environment path variable.因此,要解决此问题,请取消选中 Prefer 32-bit 以便它尝试针对 64 位平台,...或者更好的是,将应用程序放在其他位置并将应用程序目录添加到您的环境路径变量中。 That way you can still access your application .exe anywhere, and it won't pollute your System32 folder which should only be used for Windows files anyways.这样您仍然可以在任何地方访问您的应用程序 .exe,并且它不会污染您的 System32 文件夹,该文件夹无论如何只能用于 Windows 文件。

此答案可能不适用于 OP 的问题(无论如何都已解决),但可能适用于因搜索“无法启动此应用程序”和 System32 而最终到达此处的其他人。在我的情况下,我编写了一个屏幕保护程序C# 程序必须运行 32 位,解决方案是将其安装在 Windows 目录中,而不是 Windows\\System32。然后它在 32 位和 64 位系统上都可以正常工作。

If you put your 32-bit exe in both the System32 and the SysWOW64 folder.如果您将 32 位 exe 放在System32SysWOW64文件夹中。 It works just fine.它工作得很好。 Not one, not the other, but both folders.不是一个,不是另一个,而是两个文件夹。

This might sound strange, but try it.这听起来可能很奇怪,但请尝试一下。 If you put the same exe in both folders it will start up without any modifications.如果您将相同的 exe 放在两个文件夹中,它将在不进行任何修改的情况下启动。

我刚刚将 NuGet.exe 从 c:\\Windows\\System32 移动到 c:\\Windows 并且它可以工作。

Maybe this answer is not directly applicable for OP answer, but for sure it is connected and it solved my issue.也许此答案并不直接适用于 OP 答案,但可以肯定它已连接并且解决了我的问题。
On my company computer I have a few folders, which automatically sync with OneDrive.在我公司的计算机上,我有几个文件夹,它们会自动与 OneDrive 同步。 Those files are permanently labelled as "Work", not "Personal".这些文件被永久标记为“工作”,而不是“个人”。
Each time I copied between those folders, which are syncing, I cannot run my developed application.每次我在同步的这些文件夹之间进行复制时,我都无法运行我开发的应用程序。 When I created a new directory, outside of syncing folders, I was able to change File Ownership to "Personal" (see below):当我在同步文件夹之外创建一个新目录时,我能够将文件所有权更改为“个人”(见下文):
在此处输入图片说明

Just after that, my program works perfectly.在那之后,我的程序运行良好。

暂无
暂无

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

相关问题 在system32目录中的现有文件上找不到文件异常 - file not found exception on existing file in system32 directory 服务无法启动。 System.IO.FileNotFoundException:无法加载文件或程序集“ assemblyname.dll” - Service cannot be started. System.IO.FileNotFoundException: Could not load file or assembly “assemblyname.dll” C# 应用程序搜索 System32 而不是本地文件 - C# application searches System32 instead of local file 找不到文件 &#39;c:\\windows\\system32\\inetsrv\\xxx.xlsx&#39; - Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx' 为什么服务中的File.ReadAllText会将其目录重置为“ C:\\ Windows \\ System32”? - Why does File.ReadAllText in a service reset its directory to “C:\Windows\System32”? 以32位运行时在System32中找不到C#文件 - C# file not found in System32 when running in 32 bit File.Move错误-System.IO.FileNotFoundException:找不到文件&#39;c:\\ windows \\ system32 \\ inetsrv - File.Move Error - System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv 收到 DirectoryNotFoundException: c:\\windows\\system32\\inetsrv\\Static_Files 当应用程序移动到实时服务器时 - Received a DirectoryNotFoundException: c:\windows\system32\inetsrv\Static_Files When application was moved to a live server 当程序集位于“C:\Windows\System32”内时,我得到“无法找到运行此应用程序的运行时版本” - When assembly is inside 'C:\Windows\System32' i get 'Unable to find a version of the runtime to run this application' C#Directory.GetCurrentDirectory()返回带有NUnit的system32 - C# Directory.GetCurrentDirectory() returning system32 with NUnit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM