2

I have been trying to write a script batch file or an exe to perform login. It should perform a basic operation- just login my windows 7 pc which is not in a network. I have a jar file running on the background. I want to write a script with a password to login my own windows 7 pc.

I have already looked into some utilities Logon.exe

The above utility is not working in my pc shows some error like

Windows Logon version 1.04
Copyright (c) 2003-2010 SoftTree Technologies, Inc.

Unable to install logon service (OpenSCManager failed).
Logon failed.

Somewhere its told that the file should be run as admin.

This is my code:

Process process = new ProcessBuilder("C:\\Logon.exe","-p","welcome").start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
  System.out.println(line);
}

And I have also tried using AutoLogon using LogonExpert

The above tool is working perfectly. But my need is to login only using java and when needed.

Please help me guys...

Community
  • 1
  • 1
GOBINATH.M
  • 663
  • 2
  • 12
  • 24
  • 2
    Why so complicated? Why in java? Why not just add "Auto logon" entry to registry? – AlexR Dec 29 '14 at 10:37
  • Thanks bro. I have to login when certain event triggered. I don't mind using another language. Which way to go? – GOBINATH.M Dec 30 '14 at 03:08
  • 2
    Please update your question and explain what kind of event should trigger the login. The answer will probably depend on your specific use case. – AlexR Dec 30 '14 at 08:53
  • 1
    Okai I am creating a Bluetooth application which allows the user to login their system when they have entered the range. The service is working very wwel even before they login. I tried to manually input the password credentials using java.awt.robot. But the password is not entered in login screen. That's why I am trying to write a script which will login the system only on entering the range. And I don't want to write automatic login. – GOBINATH.M Jan 02 '15 at 04:20

3 Answers3

5

What you want to do is feasible, but you must play by the rules, which don't include Java. Here is a little history, why your current attempt does not work, and how you can fix it.

It won't be easy.

A little history

First, there was a fundamental change in the way Windows acquire credentials starting with Windows Vista. That logon.exe utility you mentioned uses the old architecture. Back then, you could do pretty much anything you wanted, as anything fiddling with the logon architecture ran as a DLL in Winlogon's process. You might have already found a few custom GINA, like this one I wrote. They are ignored in recent versions of Windows.

Nowadays, Winlogon asks LogonUI to acquire credentials. LogonUI is a process that will hosts Credential Providers. A credential provider is represented by a "tile" on the logon screen. There is a few COM interfaces to implement so that LogonUI asks you for credentials.

The important things to remember are:

  1. You must implement a COM interface to interact with the logon process
  2. You get to decide what UI you present, or no UI at all

Implementing a COM interface pretty much excludes Java.

The problem you are facing right now

Logging a user in means getting a security token for him. But logging a user interactively means that you must tell Winlogon to open the door. The only process Winlogon will listen to for that is LogonUI.

In other words, even if you had code that can create a security token, you won't be able to use it to unlock the desktop.

The Windows API to create a security token is LogonUser, by the way.

How you can fix it

You must write a Credential Provider. I never heard of way to do it in Java, this is too platform specific and non-portable. All of the documentation if for C++, but I heard that it can be done in .Net. A good starting place is the Credential Providers samples in the Platform SDK.

When your Credential Provider initialzes, you will spawn a thread that waits for some event, like a Bluetooth device showing up. Running a service will work, as long as you can communicate back to your CP.

You also need to save a pointer to LogonUI's event mechanism in your implementation of ICredentialProvider::Advise.

When your hardware detection thread detects your bluetooth device, have it call ICredentialProviderEvents::CredentialsChanged. It will tell LogonUI to go through all of the Credential Providers again. When called, you must answer that you are the default auto-logon provider.

Phew! And we have not logged on, yet!

The last step is to retreive the password you save for that user, and send it to LogonUI in when ICredentialProviderCredential::GetSerialization is called.

LogonUI will take it from there. It will instruct Winlogon to call an authentication package for you and log the user in.

This SO answer says the same thing, but it is a little terse. This MSDM article is old be more complete than my answer.


+Encrypting and managing the user's password is left as an exercice ;) but you might want to take a look at the Data Protection API.

Community
  • 1
  • 1
ixe013
  • 9,559
  • 3
  • 46
  • 77
1

You could also use the auto logon function that already exists.

Log in as admin and execute (WIN-R) this:

control userpasswords2

Uncheck Users must enter a user name and password to use this computer.

Your PC will still be safe from remote access.

Babbage
  • 13
  • 4
1

As ixe013 answer explained the native way to accomplish interactive logon (also check this SO Q&A), I took sometime to study logonExpert tool which already doing the job successfully based on your feedback, the tool written in Borland Delphi (checked with PEiD).

I am not sure if you noticed le.exe cmd tool, which give you the ability to invoke it on demand in similar fashion to logon.exe. (found by reading help chm file).

though my answer not adding valuable technical highlights, I assumed that you might missed cmd tool option.

disclaimer: i have no relation at all with logonexpert.

Edit: I just discovered that MS SysinternalsSuite include autologon tool which can be invoked from cmd (autologon user domain password).

Community
  • 1
  • 1
Jawad Al Shaikh
  • 2,475
  • 2
  • 28
  • 41