Forum Discussion

Haiyangwhu's avatar
Haiyangwhu
Contributor
8 years ago
Solved

User scope in TestComplete

I call shell to run command in TestComplete:

function RunCommand(cmd, intWindowStyle, waitOnReturn)
{
    var shell = new ActiveXObject("WScript.Shell");
    if (intWindowStyle != null){
      shell.Run(cmd, intWindowStyle, waitOnReturn || false);
    } else {
      shell.Run(cmd);
    }
}

Simply i list files and directories in C:\Windows\System32:

RunCommand("cmd /C \"dir C:\\Windows\\System32 > C:\\test.log\"");

From log file C:\test.log, i get files and dirs:
2224 File(s) 941,726,810 bytes
80 Dir(s) 2,868,465,664 bytes free

 

But if run the command directly in command line window, i get different results:

2635 File(s) 1,222,264,966 bytes
88 Dir(s) 2,868,346,880 bytes free

 

You can see 400+ files and 8 directories less in TestComplete result. I thought TestComplete was running the command in a different account, but when i ran below command in TestComplete, it said it was running as administrator:

RunCommand("cmd /C \"whoami /user > C:\\user.log\"");

/*** Output in C:\user.log ***/

USER INFORMATION
----------------

User Name SID
======================= ===========================================
oyin-win7\administrator S-1-5-21-2771899511-80630353-1606088258-500

Can someone tell me what's going on here? Thanks in advance!

 

Ocean

  • 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 Redirector

    Wikipedia on WoW64

     

    TestComplete 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!

3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    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 Redirector

    Wikipedia on WoW64

     

    TestComplete 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!

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor

    Given that there are 8 extra directories shown from your command prompt window, and the symptoms you describe, the most logical hypothesis I can come up with is that you are running the command prompt as Administrator, but you are not running Test Complete as Administrator. (or vice versa)

    I know it says you are running as administrator, but I would double check by right clicking the TestComplete shortcut and selecting Run As Administrator. Then do the same with the command window to ensure that is also running as Administrator.