Package as executable but hide the cmd behind it

Hi everyone,

so when i package my script to get an exe. Everything works fine but when i open it there is this cmd box that open in the back. And if i close it it close the app too.
Is there a way to hide it ?


Ive already tried this:

Also the .ico ive put there doesn’t seem to work when i package it.

Thank you

Tool: Visual Studio
Version: Latest

Any ideas ?

Apologies for not seeing this issue. Can you let me know if you are packaging a PS7 or WinPS executable? I mostly ask because they are very different packaging processes.

1 Like

Dont worry Adam ! Man i really have no idea, how do i check ? Im pretty noob sorry. Thanks for your time and your answer too

Ok so i finally understood your question and yes Im dumb haha. I am using Windows PowerShell. I’ve really tried a lot of option but the dos window that appear still come up and i cannot close it or it close the program. It’s not the end of the world but its pretty annoying.

Thank you Adam

I just tried to duplicate this myself and the window is hidden. Is there any way you can share the contents of your pssproj? Here’s mine.

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="">
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Reference Include="System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll</HintPath>
    <Reference Include="System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
      <HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll</HintPath>
    <Reference Include="System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.dll</HintPath>
    <Content Include="Resources.resx" />
    <Compile Include="MyFormProject.designer.ps1">
    <Compile Include="MyFormProject.ps1">
    <Compile Include="Script1.ps1" />
    <EmbeddedResource Include="MyFormProject.resx">
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Target Name="Build" />
  <Import Project="$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets" Condition="Exists('$(MSBuildExtensionsPath)\PowerShell Tools for Visual Studio\PowerShellTools.targets')" />

Actually, i just tried without even packaging my proj.
I just opened my .ps1 with PowerShell and the cmd box is still opened.

Ah, I see. That setting only affects packaged executables.

Even when i package it, it is the same issue. The DOS window still appear. My project have really nothing really private. I can send it to you in private message.

Ive managed to hide it following this; user interface - Opening PowerShell Script and hide Command Prompt, but not the GUI - Stack Overflow

Had to add hide-console to my form Show event. Now when i package to exe it hide the cmd behing it.