==Problems Description==
For students, they cannot upload Arduino programs through the mBlock program interface. The following error was shown when the upload button is pressed.
C:\Program Files (x86)\mBlock\Arduino\arduino_debug.exe --upload --board arduino:avr:uno --port COM3 --verbose --preserve-temp-files C:\Users\student2022\AppData\Roaming\com.makeblock.Scratch3.4.5\Local Store\scratchTemp\project_Untitled1_1\project_Untitled1_1.ino
Loading configuration…
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:377)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
at processing.app.windows.Platform.getFolderPathFromRegistry(Platform.java:70)
at processing.app.windows.Platform.recoverSettingsFolderPath(Platform.java:55)
at processing.app.windows.Platform.init(Platform.java:50)
at processing.app.Base.guardedMain(Base.java:153)
at processing.app.Base.main(Base.java:137)
==Investigations==
Several other users reported the same problem.
Similar issues were also reported by Arduino IDE users who are using version 1.6.5. Thus, this problem is unlikely to be mBlock related.
After investigation. The problem is specific to the Arduino IDE 1.6.5 coming with the mBlock program installed at
C:\Program files (x86)\mBlock\Arduino
If this Arduino program is replaced with the most updated Arduino IDE, uploading can be completed without issues.
Further digging into the source code of the Arduino IDE 1.6.5 on github shows that the above errors relates to how the registry is being queried for the APPDATA shell folders.
private String getFolderPathFromRegistry(String folderType) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Executor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(baos, null));
CommandLine toDevicePath = CommandLine.parse("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v \"" + folderType + "\"");
executor.execute(toDevicePath);
return new RegQueryParser(new String(baos.toByteArray())).getValueOfKey();
}
Version 1.6.5 make use of the command line tool reg.exe to query the registry for shell folders. Under normal condition, this should work without problems.
However, if the registry editing tools is disabled by the Administrators on domain joined computers through GPO or Local policies, the above exception will be triggered when Arduino IDE tries to load the configuration files.
==Possible Solutions==
===Solution 1===
Allows users to use the registry tools.
===Solution 2===
Replace the Arduino IDE coming with mBlock to a newer version (>=1.6.6 is okay, as the way to query the registry is changed from 1.6.6 onwards)
However, I am not sure whether this is fully compatible with mBlock 3.X.X or not. YMMV.