Ask a Question

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

SOLVED
Mojo
Occasional Contributor

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;
  }
}

9 REPLIES 9
AlexanderM
Staff

@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

-----

Alexander
Customer Care Manager
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. 

@Mojo I can't recall what I did exactly, but this worked for me in the past (a few years ago). I think I followed the technique the RebootAndContinue function uses:

https://support.smartbear.com/viewarticle/80655/

 

Read that topic, it may give you a clue. Also, why don't you just use RebootAndContinue?

-----

Alexander
Customer Care Manager
Mojo
Occasional Contributor

@AlexanderM I am trying to automate an installation software. The installation process after starting, restarts the machine once and then continues installation for sometime before the software gets installed successfully. After that restart, the system asks for Login credentials. This is where I am trying to update registry for auto login. Here, I cannot force reboot to use RebootAndContinue, neither does the software asks for Whether I want to reboot or not? or else I could have cancelled it and forced reboot through RebootAndContinue. I hope this explanation is to clear to you. Thanks and Regards.

@Mojo Makes sense. Looks like RebootAndContinue uses a different registry path:

 

HKEY_USERS\{USER_SID}\Software\Microsoft\Windows\CurrentVersion\RunOnce

 

Did you try using this path (need to figure out the current user ID)?

 

I would actually try to force auto-login manually first, by changing the registry in Regedit. Once this works, I would then automate this in a script.

-----

Alexander
Customer Care Manager
Mojo
Occasional Contributor

@AlexanderM Manually writing registry in regedit is my last resort, the reason being I am running the test in 10 virtual machines through VMware using Test Execute. Automating the login would have really helped actually. By the way I am providing you a link.

https://www.autoitscript.com/forum/topic/141285-resolved-autologon-in-windows-7/

If you could go through the link and check the issue that the user SlowCoder74  has raised here is quite similar to my issue. And the user JFX has provided a solution "Just add a 64 to main key, see the helpfile --> RegRead remarks" which is something I am not able to figure out. Will be really grateful if you could help me out here. Thanks and Regards.

@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.

-----

Alexander
Customer Care Manager
Mojo
Occasional Contributor

@AlexanderM Thanks a lot man, its working perfectly. 

@Mojo Awesome 🙂

-----

Alexander
Customer Care Manager
cancel
Showing results for 
Search instead for 
Did you mean: