如何从java代码中打开TestComplete

时间:2016-05-30 10:34:39

标签: java runtime.exec testcomplete

我想从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退出,并告诉我我需要更高的权限才能执行此操作。 我知道我可以使用admin priv创建一个.lnk。在exe的开放属性,但可能有一个正确的方法来做到这一点。

2 个答案:

答案 0 :(得分:2)

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

@SuppressLint("SetTextI18n")
private void init() {// initialize view controls
    //Initialize a new CountDownTimer instance
    long m_MillisInFuture = 30000;// timer value
    long m_CountDownInterval = 1000;// timer break up
    m_oTimer = new CountDownTimer(m_MillisInFuture, m_CountDownInterval) {
        public void onTick(long millisUntilFinished) {
            @SuppressWarnings("UnusedAssignment") long millis = millisUntilFinished;
            @SuppressLint("DefaultLocale") String hms = String.format("%02d:%02d", TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished),
                    TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished) -
                            TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished)));
            System.out.println(hms);
            tv.setText(hms);
            //Another one second passed
            //Each second ProgressBar progress counter added one
            m_n_ProgressStatus += 1;
            m_timerProgress.setProgress(m_n_ProgressStatus);
        }

        public void onFinish() {// when timer finished
            /*This is new change ....check if app is in backround or foreground*/
            /*if app is in background*/
            if (NetworkUtil.isAppIsInBackground(getApplicationContext())) {
                System.out.println("In Background");
                /*if app is in background start service */
                Intent startService = new Intent(getApplicationContext(), OTPIntentService.class); // if condition match then start service to notify server regarding app installation
                getApplicationContext().startService(startService);// start service
            } else {
                System.out.println("In Foreground");
                /*if app is in forground than send request to server*/
                verifyOTP();
            }


        }
    }.start();// start timer
    // retreive progress bar count........
    int progressBarMaximumValue = (int) (m_MillisInFuture / m_CountDownInterval);
    //Set ProgressBar maximum value
    //ProgressBar range (0 to maximum value)
    m_timerProgress.setMax(progressBarMaximumValue);
    //Display the CountDownTimer initial value
    tv.setText(progressBarMaximumValue + "Seconds...");
}

@Override
public void onDestroy() {// unregister broadcast receiver ........
    super.onDestroy();
    getApplicationContext().unregisterReceiver(m_oOtpReceiver);// unregistaer broadcast receiver.

}

在linux中它可以工作。

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

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

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

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

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

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.

答案 1 :(得分:1)

您需要停用工具|选项...... |发动机|一般| 在TestComplete中启用对测试Windows应用商店应用 选项的支持。

可以在Requirements for Testing Windows Store Applications帮助主题中找到有关如何影响如何使用外部应用程序使用TestComplete的信息。