User scope in TestComplete
- 9 years ago
Hi Haiyangwhu,
It looks like you are using 64-bit Windows. 64-bit Windows have two System32 folders:
- %windir%\System32 - for 64-bit applications
- %windir%\SysWOW64 - for 32-bit applications
When a 32-bit application tries to access the %windir%\System32 folder, Windows redirects it to the %windir%\SysWOW64 folder for compatibility purposes. You can read more about this here:
File System RedirectorTestComplete is a 32-bit application, so it launches 32-bit cmd, which gets redirected to the SysWOW64 folder. The cmd you launch directly from Windows is 64-bit, so it accesses the "true" System32 folder. That's why you get different results.
The workaround to access the "true" System32 folder from a 32-bit application is to use the %windir%\Sysnative alias.
RunCommand("cmd /C \"dir C:\\Windows\\Sysnative > C:\\test.log\"");
Note that this alias works only in 32-bit apps on 64-bit Windows. It does not work on 32-bit Windows and in 64-bit apps on 64-bit Windows.
Another solution is to launch 32-bit or 64-bit cmd depending on Windows bitness:
if (Sys.OSInfo.Windows64bit) {
strCommand = "%windir%\\Sysnative\\cmd /C \"dir %windir%\\System32 > C:\\test.log\"";
}
else {
strCommand = "cmd /C \"dir %windir%\\System32 > C:\\test.log\"";
}
RunCommand(strCommand);Hope this helps!