C
C#•5mo ago
Ander507

How can i minimize a console app to the tray

I could only find outdated things online i use C# .net 8.0
54 Replies
Mayor McCheese
Mayor McCheese•5mo ago
There's not really anything that won't be a kludge that I'm aware of.
Ander507
Ander507•5mo ago
oh ok its just because i wanna hide the console fully
Mayor McCheese
Mayor McCheese•5mo ago
I mean if you want to just hide the console that's easier
Ander507
Ander507•5mo ago
yea that will also work
Mayor McCheese
Mayor McCheese•5mo ago
You'll have to do some research here, you'll need to bring some [DllImport]s
Ander507
Ander507•5mo ago
Stack Overflow
Show/Hide the console window of a C# console application
I googled around for information on how to hide one’s own console window. Amazingly, the only solutions I could find were hacky solutions that involved FindWindow() to find the console window by its
Mayor McCheese
Mayor McCheese•5mo ago
yeah that's using some DLLImports I'm not certain about the other answer, changing to a windows application
Ander507
Ander507•5mo ago
That just minimized the window
Mayor McCheese
Mayor McCheese•5mo ago
which the dll import?
Ander507
Ander507•5mo ago
The code
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_HIDE = 0;
const int SW_SHOW = 5;
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

const int SW_HIDE = 0;
const int SW_SHOW = 5;
Mayor McCheese
Mayor McCheese•5mo ago
Changing to a windows application appears to work fine
Ander507
Ander507•5mo ago
Not for me the is exits with code 0
Mayor McCheese
Mayor McCheese•5mo ago
$code
MODiX
MODiX•5mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Ander507
Ander507•5mo ago
BlazeBin - vcopxspiyefl
A tool for sharing your source code with the world!
Ander507
Ander507•5mo ago
here @<![cdata[🧀]]> ?
Mayor McCheese
Mayor McCheese•5mo ago
did you try to change to a windows application?
Ander507
Ander507•5mo ago
ye
Mayor McCheese
Mayor McCheese•5mo ago
I tried locally with a console application, creates a number of problems
Ander507
Ander507•5mo ago
Not for me
Mayor McCheese
Mayor McCheese•5mo ago
my main issues was that sigint isn't intercepted at that point though that's likely fixable
Ander507
Ander507•5mo ago
It works fine as a console app I HATE CHATGPT
I'm sorry, but I cannot provide assistance or guidance on activities that involve hiding applications or any other potentially unethical or malicious actions. If you have a legitimate programming or software development question, please feel free to ask, and I'll be happy to help within ethical boundaries.
I'm sorry, but I cannot provide assistance or guidance on activities that involve hiding applications or any other potentially unethical or malicious actions. If you have a legitimate programming or software development question, please feel free to ask, and I'll be happy to help within ethical boundaries.
Mayor McCheese
Mayor McCheese•5mo ago
I mean I had...
using test_console;

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
using test_console;

var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddHostedService<Worker>();

var host = builder.Build();
host.Run();
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-test_console-fd66e8e3-8617-42e0-9b55-384bf9e34d6f</UserSecretsId>
<RootNamespace>test_console</RootNamespace>
<!--<OutputType>WinExe</OutputType>-->
<OutputType>WinExe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-test_console-fd66e8e3-8617-42e0-9b55-384bf9e34d6f</UserSecretsId>
<RootNamespace>test_console</RootNamespace>
<!--<OutputType>WinExe</OutputType>-->
<OutputType>WinExe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>
</Project>
Ander507
Ander507•5mo ago
WHAT????
Mayor McCheese
Mayor McCheese•5mo ago
like I said, this breaks some things
jcotton42
jcotton42•5mo ago
how did you even phrase the question?
Ander507
Ander507•5mo ago
idk
jcotton42
jcotton42•5mo ago
"idk"? you can just copy/paste it here kek
Mayor McCheese
Mayor McCheese•5mo ago
I mean this is starting to sound sus 😦
Ander507
Ander507•5mo ago
Because i want to hide a console for an application for my personal use?
Mayor McCheese
Mayor McCheese•5mo ago
no because you got dodgy about what you asked chatgpt but like I said, setting to a windows application does what you want ¯\_(ツ)_/¯ it just has some consequences
Ander507
Ander507•5mo ago
Not for me it just closes with code 0
Mayor McCheese
Mayor McCheese•5mo ago
did you run my code?
Ander507
Ander507•5mo ago
idk where to put it
jcotton42
jcotton42•5mo ago
I'd now really like to see what you asked chatgpt
Ander507
Ander507•5mo ago
No description
Mayor McCheese
Mayor McCheese•5mo ago
oh, hiding in task manager is a whole other ball of wax
jcotton42
jcotton42•5mo ago
yeah that's a malware thing buddy
Mayor McCheese
Mayor McCheese•5mo ago
and you're in a bad land at that point
jcotton42
jcotton42•5mo ago
the answer is "you can't" and "if you figured out how to, you'd go collect your nice bug bounty check"
Mayor McCheese
Mayor McCheese•5mo ago
it's how root kits work and ummm
Ander507
Ander507•5mo ago
@<![cdata[🧀]]> Where do i put your code
Mayor McCheese
Mayor McCheese•5mo ago
I mean that you're doing some questionable stuff I need to bow out
Ander507
Ander507•5mo ago
I just need to have a console app running 24/7 on my pc
Patrick
Patrick•5mo ago
there's literally no good reason to hide an application from task manager hiding it from desktop, sure. minimising to tray, absolutely. hiding it from the tray and desktop? questionnable. hiding it from task manager? no.
Ander507
Ander507•5mo ago
I need to hide it to the tray works also but its imposible
Patrick
Patrick•5mo ago
this is just some crappy malware/joke app.
Nox
Nox•5mo ago
!ban 1118073170499473431 Now I ain't much of a learn-ed man. Ain't know nothin' 'bout hidin' applications from yer good ol' task manager, no sir. I'm a simple boy, I run my applications in the god-given foreground like ma momma was done tought me. But what I do know is that some some of a gun comes into MY town, asking to do the devil's work of hiding applications in the background - no siree, we don't tolerate that here. No new folks comin' in with good intentions askin' questions like that. Good day to ya sir.
jcotton42
jcotton42•5mo ago
@Nox 🌺 how long did you spend writing that?
Nox
Nox•5mo ago
give or take 30 seconds.
Mayor McCheese
Mayor McCheese•5mo ago
so does this forum thread need to get deleted @Nox 🌺 @Patrick ?
Nox
Nox•5mo ago
hwhich oh need to? I like the precedent.
Mayor McCheese
Mayor McCheese•5mo ago
what stare decisis?
Want results from more Discord servers?
Add your server
More Posts