c# 隐藏 控制台应用程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices; namespace HideConsole
{
class Program
{
static void Main(string[] args)
{
Console.Title = "HideConsole";
IntPtr hwnd = FindWindow(null, Console.Title);
if (hwnd != IntPtr.Zero)
ShowWindow(hwnd, CmdShow.SW_HIDE);
//Process p = new Process();
/////cmd 名称
//p.StartInfo.FileName = Process.GetCurrentProcess().MainModule.ModuleName;
//p.StartInfo.CreateNoWindow = true;
//p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Console.WriteLine("控制台应用程序隐藏DOS界面"); Console.ReadKey();
} #region WinAPI
/// <summary>
/// Sets the specified window's show state.
/// </summary>
/// <param name="hWnd">A handle to the window.</param>
/// <param name="nCmdShow">Controls how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls</param>
/// <returns></returns>
[DllImport("User32.dll", EntryPoint = "ShowWindow")]
private static extern bool ShowWindow(IntPtr hWnd, CmdShow nCmdShow);
/// <summary>
/// Retrieves a handle to the top-level window whose class name and window name match the specified strings. This function does not search child windows. This function does not perform a case-sensitive search.
/// </summary>
/// <param name="lpClassName">The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.
/// If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.
/// If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.</param>
/// <param name="lpWindowName">The window name (the window's title). If this parameter is NULL, all window names match.</param>
/// <returns>If the function succeeds, the return value is a handle to the window that has the specified class name and window name.
///If the function fails, the return value is NULL.</returns>
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
#endregion
} /// <summary>
/// http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx
/// </summary>
public enum CmdShow : int
{
/// <summary>
/// Hides the window and activates another window.
/// </summary>
SW_HIDE = ,
/// <summary>
/// Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
/// </summary>
SW_SHOWNORMAL = ,
/// <summary>
/// Activates the window and displays it as a minimized window.
/// </summary>
SW_SHOWMINIMIZED = ,
/// <summary>
/// Activates the window and displays it as a maximized window.
/// </summary>
SW_SHOWMAXIMIZED = ,
/// <summary>
/// Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except that the window is not activated.
/// </summary>
SW_SHOWNOACTIVATE = ,
/// <summary>
/// Activates the window and displays it in its current size and position.
/// </summary>
SW_SHOW = ,
/// <summary>
/// Minimizes the specified window and activates the next top-level window in the Z order.
/// </summary>
SW_MINIMIZE = ,
/// <summary>
/// Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
/// </summary>
SW_SHOWMINNOACTIVE = ,
/// <summary>
/// Displays the window in its current size and position. This value is similar to SW_SHOW, except that the window is not activated.
/// </summary>
SW_SHOWNA = ,
/// <summary>
/// Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
/// </summary>
SW_RESTORE = ,
/// <summary>
/// Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
/// </summary>
SW_SHOWDEFAULT = ,
/// <summary>
/// Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
/// </summary>
SW_FORCEMINIMIZE =
}
}
c# 隐藏 控制台应用程序的更多相关文章
- 如何创建 C# 控制台应用程序
[转] 如何:创建 C# 控制台应用程序 本主题旨在生成最简单形式的 C# 程序(控制台应用程序)熟悉 Visual Studio 2008 开发环境.由于控制台应用程序是在命令行执行其所有的输入和输 ...
- C#取得控制台应用程序的根目录方法 判断文件夹是否存在,不存在就创建
取得控制台应用程序的根目录方法1:Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径2:AppDomain.CurrentDomain.BaseDirect ...
- 双缓冲解决控制台应用程序输出“闪屏”(C/C++,Windows)
使用 C 语言编写游戏的小伙伴们想必起初都要遇到这样的问题,在不断清屏输出数据的过程中,控制台中的输出内容会不断地闪屏.出现这个问题的原因是程序对数据处理花掉的时间影响到了数据显示,或许你可以使用局部 ...
- dotnet core 通过修改文件头的方式隐藏控制台窗口
原文:dotnet core 通过修改文件头的方式隐藏控制台窗口 在带界面的 dotnet core 程序运行的时候就会出现一个控制台窗口,本文告诉大家使用最简单方法去隐藏控制台窗口. 最近在使用 A ...
- 2018-9-30-dotnet-core-通过修改文件头的方式隐藏控制台窗口
title author date CreateTime categories dotnet core 通过修改文件头的方式隐藏控制台窗口 lindexi 2018-09-30 18:36:43 +0 ...
- Windows 隐藏控制台
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"& ...
- dotnet core 隐藏控制台
如果写一个控制台程序,需要隐藏这个控制台程序,可以使用本文的方法 如果是在 Windows 下运行, 可以使用一些系统提供的方法隐藏控制台.如果是 Linux 下,都是控制台,就不用隐藏了 复制下面的 ...
- asp.net mvc引用控制台应用程序exe
起因:有一个控制台应用程序和一个web程序,web程序想使用exe程序的方法,这个时候就需要引用exe程序. 报错:使用web程序,引用exe程序 ,vs调试没有问题,但是部署到iis就报错,如下: ...
- Win32程序和控制台应用程序的项目互转设置
一般情况下,如果是windows程序,那么WinMain是入口函数,在VS2010中新建项目为"win32项目" 如果是dos控制台程序,那么main是入口函数,在VS2010中新 ...
随机推荐
- java RMI
import java.rmi.*; public interface Hello extends Remote { public String getGreeting() throws Remote ...
- Self和Super的用法
self 是类的隐藏的参数,指向当前当前调用方法的类,另一个隐藏参数是 _cmd,代表当前类方法的 selector.这里只关注这个 self.super 是个啥?super 并不是隐藏的参数,它只是 ...
- QOS
QoS控制原理 · 基于设备的QoS保障技术——CAC· 基于优先级设置的QoS保障技术· 基于减小抖动的QoS保障-Jitter BufferIP传输在时延.抖动.丢包率方面的性能不及TDM传输,而 ...
- HBase HDFS目录树
一.0.94-cdh4.2.1版本系统级别的一级目录如下,用户自定义的均在这个/hbase 下的一级子目录下/hbase/-ROOT-/hbase/.META./hbase/.archive/hbas ...
- Java字符串的那些事儿。。。。
计划围绕以下几个方面 1.内存 2.正则表达式 3.String.format 4.编码 1.内存 先来看个经典的例子 public class Blog { public static void m ...
- interview review
缘起: 因为最近要找工作,自己总结了一下面试的注意事项. 1自我介绍方法 1.基本情况:姓名.年龄.学历.家庭与理想. 简单明了,不要啰嗦. 2.学习能力:专业知识.勤奋好学. 用事实说明学习能力不错 ...
- UVA11538 - Chess Queen(数学组合)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Linq世界走一走(LINQ TO XML)
前言:Linq to xml是一种使用XML的新方法.从本质上来说,它采用了多种当前使用的XML处理技术,如DOM和XPath,并直接在.NET Framework内将它们组合为一个单一的编程接口.L ...
- php object转数组示例
原本是这样格式的数据: object(Thrift\Server\PageCards)#32 (3) { ["cards"]=> array(10) { [0]=> o ...
- Python-S13作业-day1-之登陆程序
Python-S13-day1 需求: 1.让用户输入账号密码,账号密码正确,登陆程序,打印欢迎信息: 2.如果账号,或密码输入错误,提示用户重新输入,用户有三次机会: 3.如果用户第三次输入的账号或 ...