Jump to content

Can I login to a specific user by code?


Morteza
 Share

Recommended Posts

I need a code that when I change some settings in Windows, restart the system and log automatically in the same user, without any need to clicking on his/her name on Windows login screen. Is it possible with internal AutiIt functions or is there any command in Windows I can call by AutoIt for doing this work?

Thanks beforehand

Edited by Morteza
Link to comment
Share on other sites

That could work depending on what kind of changes you made, I've never actually used that command before.

Otherwise this should trigger an autologin for you:

RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "1")

RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUsername", "REG_SZ", "username")

RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "")

From what you said it sounds like the user has no password

You would want to add something to HKCU\Software\Microsoft\Windows\CurrentVersion\Run

Since you would need to change the AutoAdminLogon option back to 0 after the login

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

EnvUpdate

Thanks for your very fast answer. I tested EnvUpdate(), but my problem was not be solved by it. My real need is when I add a user to a Groups (e.g. Administrators), the changes will not be recognized by system to a logoff and login.

Regards

Link to comment
Share on other sites

(...)

RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "AutoAdminLogon", "REG_SZ", "1")
RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultUsername", "REG_SZ", "username")
RegWrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", "DefaultPassword", "REG_SZ", "password")
(...)

Kenny

Thanks Guys :)

Your suggestion worked great o:)

Alas that EnvUpdate was not solved my problem. Refreshing the system without restarting is very ideal for my need :)

Best Regards

Edited by Morteza
Link to comment
Share on other sites

Your welcome :)

Unfortunately it's impossible to refresh this kind of change without restarting or logging off and back on.

I've looked into it many times.

Your issued a token when you logon which reflects your rights as it pertains to your group membership, it does not change until you logon again.

____________________

Now depending on what you want to do there is a work around, I've used a few times.

This may or may not help you.

1) Add the user to the admin group

2) Issue a RunAs, the new process WILL have admin rights because it will be issues a new token.

3) Let the new process do it's thing and then remove them from the admin group if needed.

If you want this to work for AutoIT functions you can use a runas to call the script itself with a switch like "/IamAdmin"

And assign a function to that switch.

But if you don't know the users password you'll have to prompt for it.

Luckily when I used this the users were all using a generic local account so I didn't have to prompt for a password :)

Everything you never wanted to know about access tokens lol

http://technet2.microsoft.com/WindowsServe...3.mspx?mfr=true

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

(...)1) Add the user to the admin group

2) Issue a RunAs, the new process WILL have admin rights because it will be issues a new token.

3) Let the new process do it's thing and then remove them from the admin group if needed.(...)

I was tested this way before my letter, but there is a very little issue. For some users, when I reject their Admin permission, I receive an Explorer error!. I didn't know the reason to now.

If you want this to work for AutoIT functions you can use a runas to call the script itself with a switch like "/IamAdmin"

And assign a function to that switch.

Window RunAs have a very big lack; You cannot redirect the password to it by code, you must type every time by hand. So, I wrote a special RunAs for working with local computers called MyRunAs that has been very useful for me to now. I attached it to the letter and I hope be useful for other peoples in future too :)

The syntax of this program is:

  • MyRunAs /u:<Username> /p:<Password /r:<A program for run>
Examples:

  • MyRunAs /u:User1 /p:123 /r:"regedit -s c:\test.reg"
  • MyRunAs /u:user2 /p: /r:notepad.exe
If /r:<Program> be executed successfully, MyRunAs will returned 0 and if any error be occurred during this process, 1 will be returned.

But if you don't know the users password you'll have to prompt for it.

Luckily when I used this the users were all using a generic local account so I didn't have to prompt for a password :)

When I don't know my users' password and I want to execute a code silently, I erase his/her password to NULL or set a new password for he/she by PsPasswd. PsPasswd just have a problem: In first running, an EULA will be appeared and you must click on a key for going on, however, you can solve this problem very simply with some registry edits ;)

Everything you never wanted to know about access tokens lol

http://technet2.microsoft.com/WindowsServe...3.mspx?mfr=true

Good link, Thanks o:)

Best Regards

MyRunAs.rar

Link to comment
Share on other sites

Is that just a compiled autoit program or did you right it in something else?

Because AutoIT has built inRunAs and RunAsWait commands.

You write the password into the code, the user isn't prompted.

I just meant if you needed the users password you would have to prompt them for it with for example the InputBox() function.

But when you already know the password you would just run:

RunAsWait ( "username", "domain", "password", 0, "program", "working directory", @SW_HIDE)

The example above will work for most puproses but take a look at the help file for complete details.

-Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Is that just a compiled autoit program or did you right it in something else?(...)

Yes, this is a very simple compiled code with AutoIt that bypass the lack of Windows RunAs command for Command-Line needers. I didn't save simple codes, I put the compiled version :)

Edited by Morteza
Link to comment
Share on other sites

oh ok , cool

Good work :)

Just FYI:

Your better off just uploading the source code (au3).

People generally won't download an exe because they have no

way of nowing what it really is. It could be spyware or anything.

Not accusing you just letting you know :)

-Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...