C # cannot find the specified file

Hi, I am trying to create an application that uses msg.exe to send messages over a network.

When I execute msg from cmd everything works fine, but when I open cmd with a form that I can’t go to the system32 folder with cmd and the file does not appear there, but when I view or use cmd normally, it works and works

tested it on another computer and the application works fine by running 7 bits on this 1.

Here is an example of the code that I use to open cmd:

Process.Start("cmd");

I start as an administrator, I tried to execute it directly from msg.exe, and it seems that the problem of 64 bits works on all 32-bit systems, but not on any 64-bit

edit: ok I found that a problem when launching 64-bit 32-bit applications cannot run 64-bit applications in the 32 folder of the system. when you try to access this folder, it redirects you to% WinDir% \ SysWOW64 to work with this path. C: \ Windows \ Sysnative \ file (% windir% \ Sysnative)

+3
source share
6 answers

The solution mentioned in the question was that for me there was a trick - posting the tested solution 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; }
}
+2
source

Do you need to use cmd at all? Why not use Process.Start to call msg.exe directly. If you know where it is, you should be able to run it.

+1
source

, , , "msg"

Process.Start("msg");

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "msg.exe";
startInfo.Arguments = "/SERVER hellowword";
startInfo.WorkingDirectory = @"C:\Temp";
startInfo.WindowStyle = ProcessWindowStyle.Maximized;
startInfo.ErrorDialog = true;
Process process = Process.Start(startInfo);
+1
Process p = new Process();
System.Diagnostics.ProcessStartInfo sinfo = new System.Diagnostics.ProcessStartInfo("C:\\Windows\\System32\\msg.exe");
p.StartInfo.Arguments=String.Format("/server:{0} {1} {2}",toServer,string.Compare(toUser.Trim(), "") == 0 ? "*" : toUser,message);
p.StartInfo = sinfo;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "msg.exe";
p.Start();

"Username" "Password" StartInfo . ( "msg.exe" , , , ).

+1

Windows (, Home, not Professional/Business ..) msg.exe .

0

, " ", . 64- win7 pc "x64" "Any CPU", "msg.exe".

0

Source: https://habr.com/ru/post/1785190/


All Articles