WinExec函数
#include<windows.h>
int main()
{WinExec("notepad.exe", SW_HIDE);return 0;
}
- SW_HIDE 隐藏
- SW_SHOW 显示
ShellExecute函数
在C语言中使用ShellExecute
函数可以执行外部程序,比如打开一个文件、运行一个程序等。
#include <windows.h>
#include <stdio.h>int main() {// 记事本程序路径const char* notepadPath = "notepad.exe";// 调用ShellExecute函数打开记事本HINSTANCE result = ShellExecute(NULL, "open", notepadPath, NULL, NULL, SW_HIDE);// 检查执行结果if ((INT_PTR)result <= 32) {printf("Failed to open Notepad!\n");return 1;} else {printf("Notepad opened successfully!\n");}return 0;
}
相关资料:
- C\C++控制台程序隐藏方法总结