0

I've been trying to get this working all morning.

These answers have not helped me at all..

And like 10 more similar to those. I've tried the answers in all of these posts and none of them work for me.

I am trying to develop an executable that runs a program on a remote machine with admin credentials.

I'm not using Visual Studio, I'm just compiling with the .Net version 4.0.30319 csc.exe.

      Process process = new Process();
      string pw = "pass";
      SecureString password = new SecureString();
      for (int i = 0; i < pw.Length; i++){
        password.AppendChar(pw.ToCharArray()[i]);
      }
      password.MakeReadOnly();

      var processInfo = new ProcessStartInfo(@"my_program.exe");
      // not working
      // processInfo.WorkingDirectory = @"C:\Users\myuser\Desktop";          
      // not working
      processInfo.WorkingDirectory = @"\\remote\Apps";

      // credentials
      processInfo.UserName = "admin_username";
      processInfo.Password = password;
      processInfo.Domain = "WORK_DOMAIN";
      processInfo.UseShellExecute = false;
      //

      try{
        Process.Start(processInfo);
      }catch (Exception ex){
        MessageBox.Show(ex.Message.ToString(),"Error");
      }

Running this as is throws 'the system cannot find the file specified

But when I comment out the credentials the program opens successfully.

The "admin_user" has all access rights to the share.

Beefjeff
  • 371
  • 4
  • 12
  • 3
    Really? You have been trying all morning yet the answer is on the first question you linked? "Using non full filepath on Process.Start only works if the file is found in System32 folder." you are using a **relative path**. In your case, it should be `\\remote\apps\my_program.exe` – Camilo Terevinto Feb 23 '18 at 19:16
  • Even if the user is an admin, it doesn't mean they have rights to access that machine's share or the remote machine's disk. You have to make sure the user has rights to both. –  Feb 23 '18 at 19:18
  • @CamiloTerevinto I should have kept all my commented lines in the question so you could see what I've tried. "\\remote\apps\my_program.exe" is what I started with. – Beefjeff Feb 23 '18 at 19:22
  • @Will I am the admin user and I do have access to the share and everything within. – Beefjeff Feb 23 '18 at 19:23
  • I believe SecureString is machine specific and the target machine won't be able to read the password you are passing to it. I'm looking for confirmation of this now. – R.Laney Feb 23 '18 at 19:32
  • @R.Laney I actually tried using the same program from local desktop. Editing post to reflect. – Beefjeff Feb 23 '18 at 19:43
  • when you ran it on the remote machine did you change the working DIR as well? what error did you get? Here is a reference that securestring is machine specific [https://stackoverflow.com/questions/6982236/how-is-securestring-encrypted-and-still-usable](https://stackoverflow.com/questions/6982236/how-is-securestring-encrypted-and-still-usable) – R.Laney Feb 23 '18 at 19:52
  • @Beefjeff, are both the client and remote machine part of the same domain? – Artak Feb 23 '18 at 19:59
  • @Artak Yeah they are. – Beefjeff Feb 23 '18 at 20:01
  • @R.Laney The working dir for the remote would be \\remote\apps while it would be C:\users\myuser\Desktop. The filename is the same. – Beefjeff Feb 23 '18 at 20:02

0 Answers0