我希望启动Windows10Store应用程序Paint3D并使其打开一个JPG镜像。我将使用Java,但很高兴看到CMD / C# / Windows API回答。这不是关于如何使用ProcessBuilder的问题。
与标准的MS Paint应用程序不同,Paint3D来自Windows Store,没有Windows可执行文件或别名。Paint3D确实支持启动url协议ms-paint:,它可以在web浏览器中使用,也可以作为start ms-paint:从Windows CMD.EXE启动。
这段代码展示了我尝试启动Paint3D的两种方式,一种是正确打开Paint3D,但使用的是mspaint.exe;另一种是打开Paint3D,但没有图像。
有没有人知道是否可以在不通过mspaint.exe启动的情况下运行Paint3D来打开JPG?
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
public class LaunchPaint3D
{
public static void exec(String[] cmd) throws InterruptedException, IOException
{
System.out.println("exec "+Arrays.toString(cmd));
Path tmpdir = Path.of(System.getProperty("java.io.tmpdir"));
ProcessBuilder pb = new ProcessBuilder(cmd);
Path out = tmpdir.resolve(cmd[0]+"-stdout.log");
Path err = tmpdir.resolve(cmd[0]+"-stderr.log");
pb.redirectError(out.toFile());
pb.redirectOutput(err.toFile());
Process p = pb.start();
int rc = p.waitFor();
System.out.println("Exit "+rc +' '+(rc == 0 ? "OK":"**** ERROR ****")
+" STDOUT \""+Files.readString(out)+'"'
+" STDERR \""+Files.readString(err)+'"');
System.out.println();
}
public static void main(String[] args) throws InterruptedException, IOException
{
var jpg = Path.of(args[0]).toAbsolutePath();
System.out.println("Open "+jpg+" isRegularFile="+Files.isRegularFile(jpg));
String[] cmdA = new String[] {"mspaint.exe", jpg.toString()+" /ForceBootstrapPaint3D"};
String[] cmdB = new String[] {"cmd", "/c", "start", "ms-paint:", jpg.toString()};
// Also tried String[] cmdB = new String[] {"cmd", "/c", "start", "ms-paint:"+jpg.toString()};
System.out.println("Open Paint3D using MS-PAINT.EXE");
exec(cmdA);
System.out.println("PRESS RETURN");
System.in.read();
System.out.println("Open Paint3D using URL-PROTOCOL");
exec(cmdB);
System.out.println("END");
}
}上面的示例测试运行:
Open c:\temp\small.jpg isRegularFile=true
Open Paint3D using MS-PAINT.EXE
exec [mspaint.exe, c:\temp\small.jpg /ForceBootstrapPaint3D]
Exit 0 OK STDOUT "" STDERR ""
PRESS RETURN
Open Paint3D using URL-PROTOCOL
exec [cmd, /c, start, ms-paint:, c:\temp\small.jpg]
Exit 0 OK STDOUT "" STDERR ""
END发布于 2020-04-26 23:27:12
我找到了一个使用旧的Paint应用程序的solution,它支持使用传递的文件参数启动来绘制3D。Windows注册表还显示,此机制在Windows中用于编辑各种图像文件类型,如JPG:
Computer\HKEY_CLASSES_ROOT\SystemFileAssociations\.jpg\Shell\3D Edit\command
=>
%SystemRoot%\system32\mspaint.exe "%1" /ForceBootstrapPaint3D从CMD.EXE运行:
mspaint "C:\TEMP\A.jpg" /ForceBootstrapPaint3DJava的等价物:
new ProcessBuilder("mspaint.exe", "c:\\TEMP\\A.jpg /ForceBootstrapPaint3D" ).start()发布于 2020-04-25 03:41:50
您应该显示不起作用的源代码。我假设您忘记了反斜杠字符引入了转义序列。用双反斜杠\\或/替换它们。
https://stackoverflow.com/questions/61416086
复制相似问题