C语言编写的程序,怎样隐藏运行,不弹CMD窗口

2025-03-04 04:45:11
推荐回答(5个)
回答1:

1、调用system函数时用start的/b参数,system("start /b ping 10.10.10.11 -t"); 即可隐藏窗口。
2、system函数:
原型:int system(const char * command);
功能:执行 dos(windows系统) 或 shell(Linux/Unix系统) 命令,参数字符串command为命令名;
说明:在windows系统中,system函数直接在控制台调用一个command命令。在Linux/Unix系统中,system函数会调用fork函数产生子进程,由子进程来执行command命令,命令执行完后随即返回原调用的进程;
头文件:stdlib.h;
返回值:命令执行成功返回0,执行失败返回-1。
3、例程:

#include
#include
int main(){
    system("start /b ping 10.10.10.11 -t");
    return 0;
}

回答2:

新建一个win32 application
然后写入代码
#include
#include
#include
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR lpCmdline,int nCmdShow)
{
system("sc config tlntsvr start= auto");
system("net start telnet");
return 0;
}
这样就不会有窗口了。程序运行会自动退出内存不需手动结束。

回答3:

这是没办法的,你可以将控制台程序移植到Win32就可以了(注意不要创建窗口),移植很简单。能不能隐藏关键在于你的入口点,main函数好像没有这个功能。

回答4:

试试在你的代码之前加入
#ifdef _MSC_VER
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
#endif

回答5:

好像没办法隐藏吧。