C#中无法找到文件

C#中无法找到文件

本文介绍了C#中无法找到文件中指定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想创建一个使用msg.exe通过网络发送消息的应用程序。

Hi I am trying to create a app that uses the msg.exe to send messages over a network.

当我执行味精从CMD一切正常,但是当我打开在cmd的形式,我不能,去与CMD和文件system32文件夹是不是有显示,但是当我浏览或使用CMD通常它是和evrything作品

When i execute msg from cmd everything works fine, but when i open cmd with the form i am unable to, went to the system32 folder with cmd and the file is not shown there, but when i browse or use cmd normally it is and evrything works

测试它在另一台计算机和应用程序工作正常,运行的win 7 64位这个1。

tested it on another computer and app works fine, running win 7 64 bit on this 1.

下面是我用它来打开CMD一个code样品:

Here is a code sample that i use to open cmd:

Process.Start("cmd");

我运行作为管理员我曾尝试从msg.exe藏汉执行它直接,这似乎是一个问题,在64位适用于所有的32位系统,但不能在任何64位

i am running as admin i have tried executed it directly from msg.exe aswell, it seems to be a problem on 64 bit works on all 32 bit systems but not on any 64bit

编辑:好吧,我发现这个问题时,运行64位的32位应用程序不能运行在系统中的文件夹32的64位应用程序。试图访问该文件夹重定向您%WINDIR%时\ Syswow64资料周围的工作就是用这种路径C:\ WINDOWS \ Sysnative \文件(%WINDIR%\ Sysnative)

edit: ok i found the problem when running 64bit 32 bit applications cannot run 64 bit apps in the system 32 folder. when trying to access this folder it redirects you to %WinDir%\SysWOW64 a work around is to use this path C:\Windows\Sysnative\file (%windir%\Sysnative)

推荐答案

在问题中提到的解决方案是什么样的伎俩我 - 在这里张贴测试的解决方案,为后人:

The solution mentioned in the question was what did the trick for me - posting testable solution here for posterity:

public class Messenger : IMessenger
{
    private readonly IProcessWrapper _process;

    public Messenger(IProcessWrapper process)
    {
        _process = process;
    }

    public void SendMessage(string message)
    {
        var info = new ProcessStartInfo
            {
                WorkingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "sysnative"),
                FileName = "msg.exe",
                Arguments = string.Format(@" * ""{0}""", message),
                WindowStyle = ProcessWindowStyle.Hidden,
                UseShellExecute = true,
                Verb = "runas"
            };
        _process.Start(info);
    }
}


public interface IProcessWrapper : IDisposable
{
    IEnumerable<Process> GetProcesses();
    void Start(ProcessStartInfo info);
    void Kill();

    bool HasExited { get; }
    int ExitCode { get; }
}

这篇关于C#中无法找到文件中指定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 01:35