简体   繁体   English

Windows 7,无法从bat文件调用exe

[英]windows 7, cannot invoke exe from bat file

In windows 7 a bat file was made: 在Windows 7中制作了一个bat文件:

rem set UD_LOG_FILE_PATH=%temp%\defrag_native.log
C:
cd \Windows\System32
udefrag.exe --optimize-mft C:
udefrag.exe -o C:
pause

I can double click the bat file and it runs OK. 我可以双击bat文件,它运行正常。 However, the bat file was made to be invoked from a running program. 但是,bat文件是从正在运行的程序中调用的。 When the program shells out to the bat file the following error is produced: 当程序将外壳程序插入bat文件时,将产生以下错误:

'C:\\Windows\\System32\\udefrag.exe' is not recognized as an internal or external command, operable program or batch file. 无法将“ C:\\ Windows \\ System32 \\ udefrag.exe”识别为内部或外部命令,可操作程序或批处理文件。

Invocation is done using Shell in VB6. 调用是在VB6中使用Shell完成的。 Different things were tried. 尝试了不同的事情。 First the bat file was called directly, then with C:\\Windows\\System32\\cmd.exe /c, then with C:\\Windows\\SysWOW64\\cmd.exe /c. 首先直接调用bat文件,然后使用C:\\ Windows \\ System32 \\ cmd.exe / c,然后使用C:\\ Windows \\ SysWOW64 \\ cmd.exe / c。 All produce the same result. 所有产生相同的结果。 The bat file runs but will not run the exe file within the bat file. bat文件将运行,但不会在bat文件中运行exe文件。 But the bat file works OK if run directly. 但是,如果直接运行bat文件,则可以正常运行。 Please help. 请帮忙。 Thanks 谢谢

Google says that udefrag.exe is a third party program. Google说udefrag.exe是第三方程序。 If it is in c:\\windows\\system32 then it is on the path and you only need the last 3 lines in your batch file. 如果它在c:\\ windows \\ system32中,则它在路径上,并且您只需要批处理文件中的最后3行。 Try this first and see if it needs elevated permissions. 首先尝试一下,看看是否需要提升的权限。 If you have UAC turned off then turn it back on for the test. 如果您关闭了UAC,请重新打开以进行测试。 Your VB program may not have the right permissions. 您的VB程序可能没有正确的权限。

@echo off
udefrag.exe --optimize-mft C:
udefrag.exe -o C:
pause

I used task scheduler to resolve this. 我使用任务计划程序来解决此问题。 A task was created with no trigger named "defragment". 创建了一个没有名为“碎片整理”的触发器的任务。 The task invokes the bat file. 该任务将调用bat文件。 Instead of invoking the bat file from the running program the following command is given: 而不是从正在运行的程序中调用bat文件,而是给出以下命令:

schtasks /Run /TN defragment schtasks / Run / TN碎片整理

This runs the bat file through the task scheduler. 这将通过任务计划程序运行bat文件。 I don't know why I have to do it that way, but it works good. 我不知道为什么我必须这样做,但是效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM