Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ ShellExecute格式DOS命令_C++_Windows_Visual Studio_Dos - Fatal编程技术网

C++ ShellExecute格式DOS命令

C++ ShellExecute格式DOS命令,c++,windows,visual-studio,dos,C++,Windows,Visual Studio,Dos,我正在尝试使用Windows ShellExecute API执行DOS的FORMAT命令。我不知道如何为ShellExecute运行DOS命令。目前我正在使用以下代码: DWORD returnCode=0; TCHAR Command[1024]; _stprintf_s(Command, _T("Format M: /FS:FAT32 /Q /X /V:RED")); SHELLEXECUTEINFO sexi = {0}; sexi.cbSize = sizeof(SHELLEXECU

我正在尝试使用Windows ShellExecute API执行DOS的FORMAT命令。我不知道如何为ShellExecute运行DOS命令。目前我正在使用以下代码:

DWORD returnCode=0;
TCHAR Command[1024];
_stprintf_s(Command, _T("Format M: /FS:FAT32 /Q /X /V:RED"));

SHELLEXECUTEINFO sexi = {0};
sexi.cbSize = sizeof(SHELLEXECUTEINFO);
sexi.hwnd = NULL;
sexi.fMask = SEE_MASK_NOCLOSEPROCESS;
sexi.lpFile = _T("cmd.exe");
sexi.lpParameters = Command;
sexi.nShow = SW_SHOW;

if(ShellExecuteEx(&sexi))
{
    DWORD wait = WaitForSingleObject(sexi.hProcess, INFINITE);
    if(wait == WAIT_OBJECT_0)
        GetExitCodeProcess(sexi.hProcess, &returnCode);
}
运行这段代码将挂起,因为WaitForSingleObject将等待cmd窗口关闭。我尝试将命令字符串用作SHELLEXECUTEINFO lpFile,但失败了

即使在执行这段代码时,它也只会打开一个CMD窗口,而不执行format命令

我需要安静地执行FORMAT命令,而不显示任何控制台窗口。我正在使用DiskPart在Win7上格式化驱动器,但对于XP,我一直坚持格式化

有人能帮忙吗

问候


另外,我还需要覆盖在执行格式化命令时显示的“插入新磁盘”提示,以便用户不必单击enter键即可启动格式化过程。

您可以使用该功能。这仍然会显示一个对话框。或者检查似乎确实需要的功能。

您可以使用该功能。这仍然会显示一个对话框。或者检查似乎确实需要的。您可以尝试使用
sexi.nShow=SW_HIDE
?它只是隐藏控制台窗口并一直等待。。。。除此之外,我认为上面的代码实际上没有运行format,因为它只是打开了一个cmd窗口,但我没有收到format提示消息,告诉我插入媒体。你能试试
sexi.nShow=SW_HIDE
?它只是隐藏控制台窗口,并一直等待。。。。此外,我不认为上面的代码实际运行的是format,因为它只是打开了一个cmd窗口,但我没有收到format提示消息,告诉我插入媒体。谢谢,我将检查Volume类。。至于SHFormatDrive,它可以做到这一点,但仅限于XP SP2,这使得SP3无法管理。谢谢,我们将检查Volume类。。至于SHFormatDrive,它可以做到这一点,但仅限于XP SP2,这使得SP3无法管理。