cheyou
August 18, 2022, 11:28pm
1
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
adam
September 26, 2022, 11:24pm
3
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
cheyou
September 27, 2022, 12:10am
4
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
cheyou
September 30, 2022, 1:38am
5
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
adam
September 30, 2022, 4:18pm
6
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="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>6CAFC0C6-A428-4d30-A9F9-700E829FEA51</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MyApplication</RootNamespace>
<AssemblyName>MyApplication</AssemblyName>
<Name>MyFormProject</Name>
<PackageAsExecutable>True</PackageAsExecutable>
<PackageEntryPoint>MyFormProject.ps1</PackageEntryPoint>
<Bundle>True</Bundle>
<Obfuscate>False</Obfuscate>
<HideConsoleWindow>True</HideConsoleWindow>
<RequireElevation>False</RequireElevation>
<PackageModules>False</PackageModules>
<HighDPISupport>False</HighDPISupport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<Name>System</Name>
<AssemblyName>System.dll</AssemblyName>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Name>System.Drawing</Name>
<AssemblyName>System.Drawing.dll</AssemblyName>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<Name>System.Windows.Forms</Name>
<AssemblyName>System.Windows.Forms.dll</AssemblyName>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Resources.resx" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyFormProject.designer.ps1">
<SubType>Code</SubType>
<DependentUpon>MyFormProject.ps1</DependentUpon>
</Compile>
<Compile Include="MyFormProject.ps1">
<SubType>Form</SubType>
</Compile>
<Compile Include="Script1.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MyFormProject.resx">
<DependentUpon>MyFormProject.ps1</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<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')" />
</Project>
cheyou
September 30, 2022, 4:21pm
7
Actually, i just tried without even packaging my proj.
I just opened my .ps1 with PowerShell and the cmd box is still opened.
adam
September 30, 2022, 4:42pm
8
Ah, I see. That setting only affects packaged executables.
cheyou
September 30, 2022, 6:30pm
9
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.
cheyou
October 1, 2022, 9:23pm
10
adam:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>6CAFC0C6-A428-4d30-A9F9-700E829FEA51</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MyApplication</RootNamespace>
<AssemblyName>MyApplication</AssemblyName>
<Name>MyFormProject</Name>
<PackageAsExecutable>True</PackageAsExecutable>
<PackageEntryPoint>MyFormProject.ps1</PackageEntryPoint>
<Bundle>True</Bundle>
<Obfuscate>False</Obfuscate>
<HideConsoleWindow>True</HideConsoleWindow>
<RequireElevation>False</RequireElevation>
<PackageModules>False</PackageModules>
<HighDPISupport>False</HighDPISupport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<Name>System</Name>
<AssemblyName>System.dll</AssemblyName>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Name>System.Drawing</Name>
<AssemblyName>System.Drawing.dll</AssemblyName>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<Name>System.Windows.Forms</Name>
<AssemblyName>System.Windows.Forms.dll</AssemblyName>
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Windows.Forms.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Resources.resx" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyFormProject.designer.ps1">
<SubType>Code</SubType>
<DependentUpon>MyFormProject.ps1</DependentUpon>
</Compile>
<Compile Include="MyFormProject.ps1">
<SubType>Form</SubType>
</Compile>
<Compile Include="Script1.ps1" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MyFormProject.resx">
<DependentUpon>MyFormProject.ps1</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<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')" />
</Project>
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.