Question

I have a program written in vb.net. After I build, I want to launch an interactive batch file that executes a psexec command remotely. How can I do that? this is my post build event:

call "$(ProjectDir)ExecOnGw.bat"

And this is my batch that if it runs in a normal command prompt, execution is ok.

c:\Sysinternal\psexec.exe \\gateway "C:\Remotepath\mybatch.bat" -u mydomain\myuser -p ******
pause

This batch calls another batch on a remote machine that does something, then if I want to exit, I have to press a "q" and "Enter". In a normal command prompt, it works fine. But in a Visual Studio post build event it goes down. Help me!

Was it helpful?

Solution

I've done this before using the start command. I created a simple pause.bat file to demonstrate:

    @echo off
    pause Press Any Key
    exit

If I put this in the post build event, I see a console that just closes.

call pause.bat

If I use this instead, I get a second console window that takes my input before closing.

start "My Process" /D c:\batch /WAIT pause.bat

OTHER TIPS

Here is info about our technical development environment :

  • Microsoft Visual Studio Enterprise 2019

    .NET Core 3.1

Just to add to @dsway good answer, I used Visual Studio 2019’s macros so that I could keep the directory path as relative:

start "My Process" /D "$(SolutionDir)Scripts" /WAIT blahblah.bat

  1. Right-click on the Project in question
  2. A context menu will show up
  3. Select the Properties option
  4. Select “Build Events”
  5. Click on “Edit Post-build…”
  6. Enter the aforementioned command that I posted above, and tailor it to your needs before pressing OK.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top