Forum Discussion

tristaanogre's avatar
tristaanogre
Esteemed Contributor
7 years ago

Re: Testing Destination of Windows Shortcut lnk in Start Menu Win7x64

Both the WShell and the FileSystem object have analogs in TestComplete where you don't need to actually instantiate new objects.

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/wshshell/index.html

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfilesystem/index.html

 

I would use these objects instead of the "new ActiveXObject" calls that are in that article.

1 Reply

  • Poida's avatar
    Poida
    Occasional Contributor

    Thanks for the tips Robert.   This is what I ended up with in case anyone else is looking for this later, in javascript

    function Test_SCExists_GetSCPath()
    {
      if (!IsShortcutValid("Programs|Accessories|Paint", "|")) {
        Log.Error("Shortcut is not valid");
        return;
      }
      Log.Message("Shortcut is valid");
      
      
      var target = GetShortcutTarget("Programs|Accessories|Paint", "|");
      if (!target) {
        Log.Error("Shortcut doesn't exist");
        return;
      }
      Log.Message(target);
      
    }
     
    function IsShortcutValid(shortcutPath, separator)
    {
      var StartDir, path, shortcut;
      StartDir = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\";
      path = shortcutPath.split(separator).join("\\") + ".lnk";
      if (aqFileSystem.Exists(StartDir + path)) {
        shortcut = WshShell.CreateShortcut(StartDir + path);
        return aqFileSystem.Exists(shortcut.TargetPath);
      }
      return false;
    }
    
    
    function GetShortcutTarget(shortcutPath, separator)
    {
      var StartDir, path, shortcut;
      StartDir = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\";
      path = shortcutPath.split(separator).join("\\") + ".lnk";
      if (aqFileSystem.Exists(StartDir + path)) {
        shortcut = WshShell.CreateShortcut(StartDir + path);
        return shortcut.TargetPath;
      }
      return false;
    }