从 CreateProcess() 执行时,diskpart 无法正确处理脚本 [英] diskpart does not process script correctly when executed from CreateProcess()

查看:23
本文介绍了从 CreateProcess() 执行时,diskpart 无法正确处理脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

diskpart "myScript.txt":

select disk 1
convert dynamic noerr
select disk 2
convert dynamic noerr
create volume stripe disk=1,2 noerr
assign letter=X noerr

.
.

从命令提示符运行时:diskpart/s myScript.txt 它按预期工作.

When running from the command prompt: diskpart /s myScript.txt it works as expected.

但是,当使用 win api 的 CreateProcess() 运行时,两个转换命令都可以工作,但是当它到达时
create volume,显示:

However, when run using win api's CreateProcess() both the convert commands do work but when it gets to
create volume, it displays:

"The arguments you specified for this command are not valid"

..

现在,让事情变得更有趣:
如果脚本再次从 CreateProcess() 第二次执行(假设磁盘现在已转换并且它为转换命令提供正确错误),当它到达创建卷时,它确实起作用了.

Now, to make things more interesting:
If the script is executed again from CreateProcess() a 2nd time (given the disks are now converted and it gives a correct error for the convert comamnds), when it gets to the create volume, it does work.

这让我觉得它与磁盘和/或可执行文件有关?

This makes me think it has something do with the disks and or executable?

任何指向正确方向的观点都值得赞赏,因为这非常令人困惑.谢谢.

Any point in the right direction is appreciated as this is very confusing. Thanks.

STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
si.cb = sizeof(si);
strncpy( command, "diskpart.exe /s myScript.txt", (sizeof(command) - 1) );  

             CreateProcess( "c:\\WINDOWS\\system32\\diskpart.exe",
                             command,
                             NULL,
                             NULL,
                             TRUE,
                             0,
                             NULL,
                             NULL,
                             &si,
                             &pi ) );

结束原始问题________________________________________________________

end original question________________________________________________________


更新和更多信息:

  • 在创建卷命令之前添加了大约 15 - 20 秒的延迟,仍然收到相同的错误消息.

  • Added about 15 - 20 seconds worth of delay before create volume command, still got the same error message.

此外,将工作拆分为两个脚本,两次调用创建过程().在第二个脚本中,只需调用创建卷"并分配,它挂了一段时间然后回来了这个此时无法完成命令".. 或效果.

Also, split the work into two scripts, with two calls to CreateProcess(). On the second script, just calling "create volume" and assign, it hung for a while and then came back with a "this command cannot be completed at this time"..or something to the effect.

还有一点要注意:在第一个脚本上,把它们放入动态,与运行相比,它的运行速度大约慢两倍命令提示符.

Another thing to note: On the first script, putting them into dynamic, it was running about twice as slow compared to running with command prompt.

也许应该只运行整个事情两次(第二次运行时出错),因为确实有效

Maybe should just run the whole thing twice (with errors on the second run) as that did work

EDIT2
这两个脚本现在正在工作,或者在我再次尝试时工作.不知道为什么它第一次不起作用.

EDIT2
The 2 scripts is now working, or worked when I tried it again. Not sure why it didn't work the first time.

推荐答案

因为您的脚本第二次运行,看起来最可能的原因与时间有关 -- 创建卷时卷尚未准备好 命令被执行.

Because your script works the second time through it seems the most likely cause is timing related -- The volumes are not ready by the time the create volume command is executed.

基于该假设:

您可以在create volume命令之前添加一个detail disk命令来查看磁盘的状态.这将告诉您有关磁盘当前状态的信息.如果磁盘 2 没有显示任何有趣的内容,也选择第一个磁盘以显示其详细信息.您从中获得的信息可能会有所帮助.

You can add a detail disk command before the create volume command to find out the state of the disk. That will tell you something about the current state of the disk. Select the first disk as well to show its details too if disk 2 doesn't show you anything interesting. The information you get from this is likely to be helpful.

至于真正解决问题,通过使磁盘联机和脱机来引入延迟可能会有所帮助.例如:

As for actually resolving the problem, introducing a delay by taking the disks online and offline may help. For example:

select disk 1
convert dynamic
select disk 2
convert dynamic
select disk 1
offline disk
select disk 2
offline disk
select disk 1
online disk
select disk 2
online disk
create volume stripe disk=1,2
assign letter=X

这篇关于从 CreateProcess() 执行时,diskpart 无法正确处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆