Forum Discussion

Mojo's avatar
Mojo
Occasional Contributor
9 years ago

Registry key is not getting added for auto Login using C# script.

Hi, I am trying to write registry key for auto login using C# script. The script is getting executed, but the registry is not getting added. My code is shown as below: Initially I was getting an error stated as "Registry root is invalid", but running Test Complete as Administrator, the problem got solved. Now, that the script is getting executed registry is not getting updated. Please help. 

 

function Test_FWC_UTL_Registry_Write_Registry_Key_Value()
{
var strKey
  strKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"
  FWC_UTL_Registry_Write_Registry_Key_Value (strKey, "DefaultUsername", "REG_SZ", "XXXXXXXX") 
}

 

function FWC_UTL_Registry_Write_Registry_Key_Value(strRegistryKey, strRegName, strRegType, strRegKeyValue)
{   
  var WshShellObj,OutputVal
  WshShellObj  = Sys["OleObject"]("Wscript.Shell")

  OutputVal = 0
  if (WshShellObj == null)
  {
        GL_ErrMessage = "Couldn't able to create Shell object"
  }      
  else
  {   
    WshShellObj.RegWrite(strRegistryKey + "\\" + strRegName , strRegKeyValue, aqString["ToUpper"](strRegType))   
    WshShellObj = null
    OutputVal = 1
    return OutputVal;
  }
}

  • Mojo 

    They are talking about accessing the 64-bit registry from a 32-bit application on a 64-bit system. By default, a 32-bit application will be auto-directed into the Wow6432Node folder even when it does not include that part in the registry key name. That's why you did not see the value added to the path you used, but instead it appeared under Wow6432Node - TestComplete is a 32-bit application.

     

    When writing "Just add a 64 to main key", they are talking about this help file of AutoIt:
    https://www.autoitscript.com/autoit3/docs/functions/RegRead.htm

     

    To access the 64-bit registry from a TestComplete script, you can use the Storages.Registry object, like this:

     

    function Test_FWC_UTL_Registry_Write_Registry_Key_Value()
    {
    var strKey
    strKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"
    FWC_UTL_Registry_Write_Registry_Key_Value (HKEY_LOCAL_MACHINE, strKey, "DefaultUsername", "XXXXXXXX") 
    }
    
    function FWC_UTL_Registry_Write_Registry_Key_Value(regRoot, strRegistryKey, strRegName, strRegKeyValue)
    { 
    var key = Storages.Registry(strRegistryKey, regRoot, AQRT_64_BIT);
    key.SetOption(strRegName, strRegKeyValue);
    return 1;
    }

    Does this help?

     

    Also, if you can make things work manually, you will certainly be able to automate the process. That's why I suggested figuring out how to do it manually first, and then trying to turn this into code, as opposed to writing the code right away.

  • Mojo, if you are running an x64 version of Windows, check this key in Regedit:

    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon

    • Mojo's avatar
      Mojo
      Occasional Contributor

      AlexanderM Thanks a lot. The registry "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon"  is getting written through the script from Test Complete. But, the Auto login is not working. Here in the registry I am adding three string:

      AutoAdminLogon, REG_SZ,1

      DefaultUsername,REG_SZ,xxxxxx

      DefaultPassword,REG_SZ,xxxxxx.

       

      I there anything else that needs to be added in this registry for Auto login to work? Any more help will be greatly appreciated.

      Thanks and Regards.