So when i manually start my bat file that is on desktop, it works because executing a bat file via its icon uses directory of the icon(file) which is "C:\Users\Michael\Desktop".
set CLASSPATH = %~dp0 &:: %~dp0 stands for the directory of the bat file
java InitArray 5 0 4 &:: comment
pause
When i run the bat file above(InitArray.bat) from its desktop icon, it works.
java InitArray 5 0 4 &:: comment
pause
When i run the bat file above(test.bat) from its desktop icon, it works.
But when i run InitArray.bat from task scheduler, it uses the directory "C:\WINDOWS\system32". But that shouldnt be a problem because the first thing the bat file does is "set CLASSPATH = C:\Users\Michael\Desktop\".
Here is the result of task scheduler trying to run InitArray.bat.
C:\WINDOWS\system32>set CLASSPATH = C:\Users\Michael\Desktop\
C:\WINDOWS\system32>java InitArray 5 0 4
Error: Could not find or load main class InitArray
C:\WINDOWS\system32>pause
Press any key to continue . . .
Now, i know i can fix this issue by adding "C:\Users\Desktop\" to environment variable CLASSPATH. But i shouldnt need to do that since i am manually setting classpath to desktop in the first line of my bat file before trying to run the java class.