-1

I'm making a c# console .net framework application to open the file Error.vbs, and I want to be able to choose the location of the started file's window on the desktop.

This is the code I have so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace ErrorRunner
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Process ExternalProcess = new Process();
            ExternalProcess.StartInfo.FileName = @"C:\Users\video\Downloads\Error.vbs";
            while (true)
            {
                ExternalProcess.Start();
            }
        }
    }
}

How would I choose the start location of error.vbs?

(And yes, I know it might be a bad idea to start a process indefinitely, but that's the whole purpose of this program.)

Nomadical
  • 3
  • 3
  • You can not open file dialog in Console application. – Chetan Jan 02 '22 at 04:54
  • 1
    Does this answer your question? [Opening process and changing window position](https://stackoverflow.com/questions/3032246/opening-process-and-changing-window-position) – Visne Jan 02 '22 at 05:25
  • @Chetan that is not what was asked, so I'm not sure why that is relevant – Visne Jan 02 '22 at 05:26
  • As per my understanding OP is looking to select the location of vbs file at runtime. – Chetan Jan 02 '22 at 05:35
  • @Visne, it gave me hope, but sadly that's not for an external process, so it doesn't work for me – Nomadical Jan 02 '22 at 05:37
  • @Chetan that's correct – Nomadical Jan 02 '22 at 05:38
  • @Nomadical Seems like it is, why would it not work? – Visne Jan 02 '22 at 05:46
  • Does this answer your question? [How do I add a form to a console app so that user can select file?](https://stackoverflow.com/questions/12553932/how-do-i-add-a-form-to-a-console-app-so-that-user-can-select-file) – gsharp Jan 02 '22 at 06:30

1 Answers1

1

You can retrieve the external process window handle by using ExternalProcess.MainWindowHandle. Maybe you need to wait for process to start completely (see https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.mainwindowhandle?view=net-6.0#System_Diagnostics_Process_MainWindowHandle)

So you can use the handle with a P/Invoke to SetWindowPos (see https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowpos)

GibbOne
  • 629
  • 6
  • 10