后台执行格式化的例程

来源:互联网 发布:关于网络的作文600字 编辑:程序博客网 时间:2024/05/30 13:41
#include "stdafx.h"

#include "windows.h"
#include "shellapi.h"

#include <string>
#include <iostream>
using namespace std;

int main()
{
    /*
    system("format G: /q /y");
    system("format G: /q /y");
    */

    /*
    char *FormatW2K = "CMD.EXE";
    char *FormatW2KParam = "/C //"format.com h:/force/q/u/x/V:MISC//"";
    */

    string strDsk;
    cout << "Please enter diskname : ";
    cin >> strDsk;

    string strCMD = "CMD.EXE";
    string formatParameter = "/C /"format.com ";
    formatParameter += strDsk;
    formatParameter += ":/force/q/u/x/V:MISC/"";

    //在后台执行格式化命令
    ShellExecute(NULL, "open", strCMD.c_str(), formatParameter.c_str(), NULL, SW_HIDE);

    return 0;
}