C# cmd prompt cannot see telnet.exe

与世无争的帅哥 提交于 2019-12-13 06:51:55

问题


I used C# with a console program to create a new cmd process, did not redirect stdin or stdout, so I could type into the command line from here. (I was having trouble using telnet from there, so this step was just an investigation.) Able to type into the window and receive output. When I switched to c:Windows\system32, typing dir te*.exe shows nothing. In another command prompt I created directly, I see the file (telnet.exe). Any suggestions about what is wrong?

    {

        ProcessStartInfo startInfo = new ProcessStartInfo(@"cmd.exe"); 
        startInfo.UseShellExecute = false;
        startInfo.CreateNoWindow = true;
        startInfo.WindowStyle = ProcessWindowStyle.Normal; 
        startInfo.CreateNoWindow = false;
        startInfo.Arguments = host;
        using (Process p = new Process())
        {
            p.StartInfo = startInfo;
            p.Start();
        }
    }

回答1:


Since Windows 7, I believe, you have to install Telnet as a Windows Feature.

Here you have a guide to enable Telnet on Win 7, but it's applicable to Win 8.1 as well as Windows 10.

Just in case you can't read the site, the steps are:

Go to Control Panel -> Programs -> Turn Windows Features on or off -> Scroll down until you find the Telnet Client option




回答2:


Based on the above article, looked at project build properties. Platform target was set to x86. Changing to "Any CPU" at least allows me to see the program!

BTW I have looked for the answer for several days before posting this, but in the margin in related - "C# New process created cannot access certain files" gave me the info - after I created this question

Thanks, heuristics!




回答3:


This is a really devious one. When you are using windows explorer or opening a command prompt directly, you are starting a 64-bit process. When you are starting the "cmd.exe" with Process.Start(), you will get the same version as the process that's starting it. In your case, you are creating a 32-bit process, so you get the 32-bit version of the command prompt. If you change your project to create target x64, you will see the files!

Why is this so? Because, depending on whether you are accessing System32 through a 32-bit or 64-bit app, you will actually be accessing different System32 folders! For more on this, follow this link:

https://superuser.com/questions/330941/some-files-in-system32-not-accessible-outside-explorer-on-windows-7



来源:https://stackoverflow.com/questions/38383378/c-sharp-cmd-prompt-cannot-see-telnet-exe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!