1
votes

In windows 7 a bat file was made:

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. However, the bat file was made to be invoked from a running program. When the program shells out to the bat file the following error is produced:

'C:\Windows\System32\udefrag.exe' is not recognized as an internal or external command, operable program or batch file.

Invocation is done using Shell in VB6. 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. All produce the same result. The bat file runs but will not run the exe file within the bat file. But the bat file works OK if run directly. Please help. Thanks

2
Is udefrag.exe actually in that folder? Or are you in fact running a command prompt that has a particular PATH variable that just happens to work when you launch your bat file directly?Dan Puzey
Yes, udefrag.exe is in the same folder.David McDivitt
So to confirm, if you hi Start/Run and type C:\Windows\System32\udefrag.exe, it runs successfully? If that's the case then I'd suspect you're looking at a permissions issue.Dan Puzey

2 Answers

1
votes

Google says that udefrag.exe is a third party program. 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. Try this first and see if it needs elevated permissions. If you have UAC turned off then turn it back on for the test. Your VB program may not have the right permissions.

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

I used task scheduler to resolve this. A task was created with no trigger named "defragment". The task invokes the bat file. Instead of invoking the bat file from the running program the following command is given:

schtasks /Run /TN defragment

This runs the bat file through the task scheduler. I don't know why I have to do it that way, but it works good.