Getting System Folder Paths

Applies to TestComplete 15.47, last modified on January 20, 2023
Information in this topic applies to desktop applications only.

Task Description

Different versions of operating systems store system, program and user files at different locations. For example, 64-bit operating systems store 32-bit system files in the C:\Windows\SysWOW64 folder while 32-bit operating systems store system files in the C:\Windows\System32 folder. The location of user folders in different operating systems can be different, as well.

If you access system, program or user files and folders in your test, make sure that the test can find the desired files when it is run on other operating systems.

Possible Solution

Do not use hard-coded paths to system files and folders in your tests. To specify paths to desired files and folders, use variables whose values are set according to the actual location of special folders on the current operating system.

To get the actual location of operating system files and folders, you can use environment variables. To obtain environment variables in tests, use the aqEnvironment.GetEnvironmentVariable method.

The following code snippet demonstrates how to obtain the path to 64-bit versions of the Program Files folder on a computer running a 64-bit version of the Windows operating system:

JavaScript, JScript

function Test()
{

  …
  var ProgramFiles = aqEnvironment.GetEnvironmentVariable("ProgramFiles", true);
  …

}

Python

def Test():
  ...
  ProgramFiles = aqEnvironment.GetEnvironmentVariable("ProgramFiles", True)
  ...

VBScript

Sub Test

  …
  ProgramFiles = aqEnvironment.GetEnvironmentVariable("ProgramFiles", True)
  …

End Sub

DelphiScript

procedure Test();
var ProgramFiles;
begin

  …
  ProgramFiles := aqEnvironment.GetEnvironmentVariable('ProgramFiles', true);
  …

end;

C++Script, C#Script

function Test()
{

  …
  var ProgramFiles = aqEnvironment["GetEnvironmentVariable"]("ProgramFiles", true);
  …

}

See Also

GetEnvironmentVariable Method
Using Variables
Running Tests on Multiple Operating Systems

Highlight search results