"This application could not be started." Only when the file is in system32 directory
Asked Answered
E

5

16

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 - https://i.sstatic.net/FEecE.png and if I click "Yes" it opens this page in the browser - 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);
    }
}
Elephant answered 13/8, 2013 at 16:58 Comment(7)
"The app is not configured in a way that makes it possible to determine the appropriate version of the .NET Framework runtime." -- What version of the runtime are you targeting in Visual Studio?Spongy
i.imgur.com/247913M.pngElephant
i.imgur.com/XLpjGXF.png is this helps?Elephant
Is .NET 4.5 installed on the system?Snowberry
It is installed, it is the system that I'm developing on... it bothers me that it works fine everywhere else but in system32... "Are you targeting 64 bit or 32 bit?" I don't care... I just want it to work..Elephant
Have you tried running your app as an Administrator?Baggs
Yes, It didn't make a difference.Elephant
K
21

Short Answer: Uncheck "Prefer 32-bit".

Long Answer: (Not 100% sure but here goes)

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. Typically, 32-bit applications that access System32 will go through a file system redirector to the SysWOW64 folder. 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.

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. 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.

Kindless answered 13/8, 2013 at 21:26 Comment(3)
great.. "put the app elsewhere and add it in the environment path variable" worked for me..Jimmyjimsonweed
For those that do not already know: The 'Prefer 32-bit' property is on the Build tab of the project properties page in Visual Studio.Piles
I resolved this issue by copying both to the System32 and SystemWOW64 folder the executable. Prefer 32 bit unchecked will guide the application to look only inside the SystemWOW64 folder.Limy
M
2

This answer may not be applicable to the OP's problem (which has been solved anyway), but maybe for others who end up here due to a search on “This application could not be started" and System32. In my case I had written a screensaver program in C# that had to run 32-bit, and the solution was to install it in the Windows directory, not Windows\System32. Then it works OK on both 32- and 64-bit systems.

Minimus answered 6/8, 2014 at 0:45 Comment(0)
N
2

If you put your 32-bit exe in both the System32 and the SysWOW64 folder. 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.

Naman answered 19/2, 2015 at 10:28 Comment(8)
This seems like an answer to a different question than what the OP asked.Somniferous
The OP was trying to put his command line application "My intentions are to use it thru the command line". "it just show me this messagebox". He gets this message because his application is not in the SysWOW64 folder. If he puts his application in this folder also. It will work. He will get not the “This application could not be started.” error message. It is a solution to his problem and an answer to his question.Naman
Your answer covers other applications finding the specified program. Some look in System32, others look in SysWOW64, and so you're putting it in both so that all applications will find it. But the question here is about a program that, even though it is already found, cannot be started.Somniferous
Yes. It is the exact same issue that I had with NuGet.exe. If you put NuGet.exe in System32 you vill get the exact same eror message “This application could not be started.” If you put NuGet.exe in both System32 and SysWOW64 it works. If you put it in System32 you will get the error message. If you put it in SysWOW64 windows won't find it. If you put it in both directories without any changes to the exe. It will work! No, he does not have a problem with NuGet.exe. But it is the exact same issue and an answer to the OP question: "What should I do to get it working?"Naman
Ah, okay, that wasn't clear from your answer. That seems unlikely to me to really be the case, that seems like some testing went wrong, but I cannot test myself right now, and if you did get your testing right, then I agree, then your answer is perfectly valid.Somniferous
Thanks! I know it sounds strange and that's why I called it "magic". I just tested it on a clean Win 2012 server. If you put your exe in both folders, it works!Naman
I tried to clarify this strange Win64 behavior in my answer.Naman
This is due to file system redirection. Basically, 64 bit processes get sent to System32 for backwards compatibility while 32 bit processes get silently redirected to SysWow64 without ever knowing it. Sytstem32 now houses 64 bit files while SysWow64 houses 32 bit files. When trying to execute a 32 bit application on a 64 bit system there could be confusion because the application doesn't have the awareness of the architecture it is running on. Running a 32 bit application in System32 can be problematic.Coddle
C
0

I just moved the NuGet.exe from c:\Windows\System32 to c:\Windows and it works.

Caseinogen answered 4/8, 2017 at 12:1 Comment(0)
B
0

Maybe this answer is not directly applicable for OP answer, but for sure it is connected and it solved my issue.
On my company computer I have a few folders, which automatically sync with 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):
enter image description here

Just after that, my program works perfectly.

Boycott answered 22/10, 2020 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.