gpt4 book ai didi

java - 如何从 Java 代码打开 TestComplete

转载 作者:行者123 更新时间:2023-11-29 04:45:05 24 4
gpt4 key购买 nike

我想从 java 打开 TestComplete,但我不能这样做,因为缺少权限。当我运行我的代码时

public static void StartTC() {
try{
Process p = Runtime.getRuntime().exec(new String[] {"C:\\Program Files (x86)\\SmartBear\\TestComplete 11\\Bin\\TestComplete.exe"});
}
catch (IOException e) {
e.printStackTrace();
}
}

程序以 CreateProcess error=740 退出,并告诉我此操作需要更高的权限。我知道我可以创建一个具有管理员权限的 .lnk。在 exe 的打开属性中,但可能有正确的方法来执行此操作。

最佳答案

我认为您可以使用 File 类来设置权限。

 File file = new File("File.c");
//but file permission are OS specific.
file.setExecutable(true);

在 Linux 中它会工作。

如果您使用的是 Windows,那么您可以运行“icacls”命令来授予文件权限。

C:\>icacls "D:\test" /grant John:(OI)(CI)F /T

此命令可用于在windows中授予权限。

According do MS documentation:

F = Full Control
CI = Container Inherit - This flag indicates that subordinate containers will inherit this ACE.
OI = Object Inherit - This flag indicates that subordinate files will inherit the ACE.
/T = Apply recursively to existing files and sub-folders. (OI and CI only apply to new files and sub-folders). Credit: comment by @AlexSpence.

您可以使用 Runtime.getRuntime().exec("icacls something here") 运行上述命令;

希望对您有所帮助

关于java - 如何从 Java 代码打开 TestComplete,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37523531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com