Batch won't work properly after conversion to exe
Moderator: DosItHelp
Batch won't work properly after conversion to exe
Three batch files that work with each other won't do the job properly after being converted to exe files, but they do everything correctly in their bat form. I tried setting up both 64 bit and 32 bit conversions, but both won't work. How would I go about determining where the error is?
Yes, where they mention each other, I changed every instance of .bat to .exe in the code, so that's not it.
Yes, where they mention each other, I changed every instance of .bat to .exe in the code, so that's not it.
Re: Batch won't work properly after conversion to exe
If you really do want an answer you'd probably have to provide the content of all of your batch files prior to 'conversion' and possibly even the name/version of the application you used together with the parameters/options you invoked for the 'conversion' process.
You may not be aware that these 'converters' don't really convert anything, they wrap the script into essentially a self extractor and run the script from a usually hidden location prior to usually deleting it. The most common problem therefore is scripts which do not specifically define paths or do not make them relative to their extracted locations as those are often unknown at the time or script writing.
You may not be aware that these 'converters' don't really convert anything, they wrap the script into essentially a self extractor and run the script from a usually hidden location prior to usually deleting it. The most common problem therefore is scripts which do not specifically define paths or do not make them relative to their extracted locations as those are often unknown at the time or script writing.
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Batch won't work properly after conversion to exe
Obligatory "yeah... don't do that" post
Re: Batch won't work properly after conversion to exe
Batch 1:
Batch 2:
Batch 3:
I used Bat to Exe Converter v2.4.8 from http://www.f2ko.de
Code: Select all
start /min x1\x2\image_c-1.bat
start /min x1\temp_storage\check.bat
Batch 2:
Code: Select all
set mdir=%~dp0
cd %mdir%
cd..
cd temp_storage
:getPID [RtnVar]
setlocal disableDelayedExpansion
:getLock
set "lock=%temp%\%~nx0.%time::=.%.lock"
set "uid=%lock:\=:b%"
set "uid=%uid:,=:c%"
set "uid=%uid:'=:q%"
set "uid=%uid:_=:u%"
setlocal enableDelayedExpansion
set "uid=!uid:%%=:p!"
endlocal & set "uid=%uid%"
2>nul ( 9>"%lock%" (
for /f "skip=1" %%A in (
'wmic process where "name='cmd.exe' and CommandLine like '%%<%uid%>%%'" get ParentProcessID'
) do for %%B in (%%A) do set "PID=%%B"
(call )
))||goto :getLock
echo %PID% >>pid.txt
ping localhost -n 1
set /p pid=<pid2.txt
for /r "%userprofile%\folder_22" %%a in (*.gif) do @copy /y "%%a"
taskkill /pid %pid%
erase pid.txt
erase pid2.txt
Batch 3:
Code: Select all
set mdir=%~dp0
cd %mdir%
:getPID [RtnVar]
setlocal disableDelayedExpansion
:getLock
set "lock=%temp%\%~nx0.%time::=.%.lock"
set "uid=%lock:\=:b%"
set "uid=%uid:,=:c%"
set "uid=%uid:'=:q%"
set "uid=%uid:_=:u%"
setlocal enableDelayedExpansion
set "uid=!uid:%%=:p!"
endlocal & set "uid=%uid%"
2>nul ( 9>"%lock%" (
for /f "skip=1" %%A in (
'wmic process where "name='cmd.exe' and CommandLine like '%%<%uid%>%%'" get ParentProcessID'
) do for %%B in (%%A) do set "PID=%%B"
(call )
))||goto :getLock
echo %PID% >>pid2.txt
ping localhost -n 1 >nul
set /p pid=<pid.txt
:loop
setlocal EnableDelayedExpansion
set /a value=0
set /a sum=0
FOR /R %1 %%I IN (*) DO (
set /a value=%%~zI/45000
set /a sum=!sum!+!value!
)
if %sum% gtr 2500 goto end_pic
goto loop
:end_pic
taskkill /pid %pid%
erase pid.txt
erase pid2.txt
I used Bat to Exe Converter v2.4.8 from http://www.f2ko.de
Re: Batch won't work properly after conversion to exe
Oh, why do I see extensions .bat? Didn't you say you converted everyting to .exe files? And what is x1 in reality, a relative or an absolute path?eax22 wrote:Code: Select all
start /min x1\x2\image_c-1.bat
start /min x1\temp_storage\check.bat
This expands to the path where the .bat file will be extracted after you run the .exe file. Probably somewhere in the %temp% folder.eax22 wrote:Code: Select all
set mdir=%~dp0
You want to know my experinces with nonsense like bat2exe? Enjoy!: viewtopic.php?t=5908#p36858
Batch is an interpreted scripting language - period. If you want to have an .exe file you should realy learn a compilable language.
Steffen
Re: Batch won't work properly after conversion to exe
aGerman, I changed them to .exes as I said. The version you are seeing is the batch version, which I use to confirm that everything should work, there is literally no difference in those two, except the .bat/.exe difference.
I converted batch codes to exes successfully in the past, it's only rarely that I encounter problems. When I do, I hope that I can find solutions to them instead of starting up on thenewboston's tutorials on C++ ... although I'm planning to do that in the future.
I converted batch codes to exes successfully in the past, it's only rarely that I encounter problems. When I do, I hope that I can find solutions to them instead of starting up on thenewboston's tutorials on C++ ... although I'm planning to do that in the future.
Re: Batch won't work properly after conversion to exe
Am I correct in assuming that Batch 2 refers to "image_c-1.bat" and Batch 3 refers to "check.bat"?
I agree with aGerman in respect to the content of Batch 1, are you sure that the relative path of the self extracting file "image_c-1.exe" is going to be "%~dp0x1\x2\" also how do you know that the relative path of the self extracting file "check.exe" is going to be "%~dp0x1\temp_storage\". I'm not saying that you don't just that your provided information does not tell us that. If you look at your code for Batch 2 you can clearly see that you are expecting to change to the directory named temp_storage which is relative to the batch file not to the exe file, this means that you must be expecting each exe to extract each bat file adjacent to itself into a known directory structure. This seems a little optimistic from my experience with these batch file wrappers.
I agree with aGerman in respect to the content of Batch 1, are you sure that the relative path of the self extracting file "image_c-1.exe" is going to be "%~dp0x1\x2\" also how do you know that the relative path of the self extracting file "check.exe" is going to be "%~dp0x1\temp_storage\". I'm not saying that you don't just that your provided information does not tell us that. If you look at your code for Batch 2 you can clearly see that you are expecting to change to the directory named temp_storage which is relative to the batch file not to the exe file, this means that you must be expecting each exe to extract each bat file adjacent to itself into a known directory structure. This seems a little optimistic from my experience with these batch file wrappers.
Re: Batch won't work properly after conversion to exe
I tested this setup numerous times and it works perfectly fine, while in the batch form. So I think that it's safe to assume the paths are all set correctly? I may not be as techy as some of you guys on here so... plz extra patience.
What I noticed, is that Batch 2 and 3, when they are launched by Batch 1, seem like they don't know their true position unless I tell them. That is why I have
What I noticed, is that Batch 2 and 3, when they are launched by Batch 1, seem like they don't know their true position unless I tell them. That is why I have
Code: Select all
set mdir=%~dp0
cd %mdir%
Re: Batch won't work properly after conversion to exe
If you do not read and understand my last post then I'm afraid you will not get an answer.
The following works:
You now reportedly have the following structure, which doesn't work:
When you invoke batch1.exe it extracts batch1.bat to a secret location before running it, (it may even randomise it's filename too):
At this time you want to invoke "C:\Users\eax22\Desktop\Test\x1\x2\image_c-1.exe" so it needs to reference that location not "C:\Users\eax22\AppData\Local\Temp\RandomName\x1\x2\image_c-1.exe".When you do that, it extracts image_c-1.bat to a secret location before running it, (it may even randomise it's file name too):
When that batch file is run, you are setting the current directory to that of the running script, "C:\Users\eax22\AppData\Local\Temp\AnotherRandomName". Then you are stepping up a level to "C:\Users\eax22\AppData\Local\Temp" and then expecting to drop into "C:\Users\eax22\AppData\Local\Temp\temp_storage" which is most unlikely to exist.
At the same time this is happening you are wanting to invoke "C:\Users\eax22\Desktop\Test\x1\temp_storage\check.exe" so it needs to reference that location not "C:\Users\eax22\AppData\Local\Temp\RandomName\x1\temp_storage\check.exe".When you do that, it extracts check.bat to a secret location before running it, (it may even randomise it's file name too):When that batch file is run it's current directory is being set to "C:\Users\eax22\AppData\Local\Temp\DifferentRandomName".…etc.
The first thing you need to do to help simplify the process is to not 'convert' batch1.bat to an exe, this will then reference the correct paths to the executables:You then need to restructure your other two individual batch files to ensure that they are not referencing each other or each others relative locations, which will be unknowns.Then 'convert' to exe's again and try once more.
The following works:
Code: Select all
C:\USERS\EAX22\DESKTOP\TEST
| batch1.bat
|
\---x1
+---temp_storage
| check.bat
|
\---x2
image_c-1.bat
You now reportedly have the following structure, which doesn't work:
Code: Select all
C:\USERS\EAX22\DESKTOP\TEST
| batch1.exe
|
\---x1
+---temp_storage
| check.exe
|
\---x2
image_c-1.exe
When you invoke batch1.exe it extracts batch1.bat to a secret location before running it, (it may even randomise it's filename too):
Code: Select all
C:\USERS\EAX22\APPDATA\LOCAL\TEMP\RANDOMNAME
batch1.bat
At this time you want to invoke "C:\Users\eax22\Desktop\Test\x1\x2\image_c-1.exe" so it needs to reference that location not "C:\Users\eax22\AppData\Local\Temp\RandomName\x1\x2\image_c-1.exe".
Code: Select all
start "" /min "C:\Users\eax22\Desktop\Test\x1\x2\image_c-1.exe"
Code: Select all
C:\USERS\EAX22\APPDATA\LOCAL\TEMP\ANOTHERRANDOMNAME
image_c-1.bat
When that batch file is run, you are setting the current directory to that of the running script, "C:\Users\eax22\AppData\Local\Temp\AnotherRandomName". Then you are stepping up a level to "C:\Users\eax22\AppData\Local\Temp" and then expecting to drop into "C:\Users\eax22\AppData\Local\Temp\temp_storage" which is most unlikely to exist.
At the same time this is happening you are wanting to invoke "C:\Users\eax22\Desktop\Test\x1\temp_storage\check.exe" so it needs to reference that location not "C:\Users\eax22\AppData\Local\Temp\RandomName\x1\temp_storage\check.exe".
Code: Select all
start "" /min "C:\Users\eax22\Desktop\Test\x1\temp_storage\check.exe"
Code: Select all
C:\USERS\EAX22\APPDATA\LOCAL\TEMP\DIFFERENTRANDOMNAME
check.bat
The first thing you need to do to help simplify the process is to not 'convert' batch1.bat to an exe, this will then reference the correct paths to the executables:
Code: Select all
start "" /min "x1\x2\image_c-1.exe"
start "" /min "x1\temp_storage\check.exe"
Code: Select all
…do that yourself