Zachu / Jani Korhonen

Command line login to Minecraft

This post isn’t is definitely not supported by Mojang. Using this login may or may not lead to banning your account, so use it at your own risk. Thanks!

Previously Minecraft launcher worked like a charm when used in Internet / Gaming Cafés. Minecraft.exe took login credentials as parameters, and one could launch the game with users not even knowing what hit them. This is very essential for cafés when they want to use centralized license management for a certain games. Here in Pelitalo it’s even more essential, because we use Minecraft a lot for education purposes.

Basically how every café license management works is that the central server gives a random license (username and password combination in this case) to a computer when the user tries to launch a game. If no licenses are free, the game is not launchable. When the Minecraft launcher updated, I couldn’t find anywhere a way to log in with username and password combination, although I did find a lot of questions about it.

After a large amount of studying, googling and contacting the Mojang support (which didn’t help a t all btw), I finally happened to find a wiki page describing the new Minecraft launcher behaviour at authentication. The information isn’t provided by Mojang and therefore may be outdated and isn’t officially supported. Another of my findings was that Minecraft stores the “last logged in” information to %appdata%\.minecraft\launcher_profiles.json, and basically uses the “accessToken” to authenticate the previous user. By using this information I created a PowerShell script that takes the username and password as arguments and launches the game with those parameters.

This PowerShell script requires at least PowerShell 3.0 since it uses Invoke-RestMethod commandlet.

So first I’ll explain a bit what the script does.

First of all we need to have the username and password parameters, since that’s really the main thing we’re doing here :) We’ll provide also a way to enter the path for the game launcher and directory. The final parameter is whether to launch the game at the end or not.

param (
  [Parameter(Mandatory=$True)] [string]$username,
  [Parameter(Mandatory=$True)] [string]$password,

Then we’ll have to create a template for the launcher_profiles.json. We store the format in a PowerShell object since it’s easy to convert to JSON afterwards. The object contains information about the requesting agent (which apparently only works if provided agent name is Minecraft and the version is above 1), username and password and a clientToken which is unique identifier for the current client. The clientToken could be anything provided that it’s in the right format and doesn’t change between the request and launching the game. We’re using UUID provided by Windows.

$request = [PSCustomObject]@{
    clientToken=(Get-WmiObject -Class Win32_ComputerSystemProduct | Select-Object -Property UUID).UUID.ToLower()

Then we make a request to the Mojang authentication server using the request formed above.

    $reply=Invoke-RestMethod "" -ContentType "application/json" -Method "POST" -UserAgent "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.17 Safari/537.36" -Body (ConvertTo-Json -InputObject $request -Compress)
    $error=ConvertFrom-Json $_.ToString()
    Throw $error.error+": "+$error.errorMessage

Then we’re actually almost done. The previously made request was stored in $reply variable and now we just have to convert the request in the format which Minecraft launcher uses. The format is taken from a file that was created by the regular game launcher after logging in.


So that things wouldn’t be so easy, we had some problems concerning about Windows line endings. We had to fiddle with those and then write the file. After that we’re beginning to be ready.

[string]::Join( "`n", (ConvertTo-Json -InputObject $profile -Depth 5 -Compress)) | sc "$directory\launcher_profiles.json"

Then we can launch the game if the launch switch is present. If everything went correctly we should be able to log in by just starting the launcher as we’d normally do.

if($launch -eq $True){
    if(Test-Path $launcher){
        & $launcher
        Throw "$launcher not found"

You can download the full launcher script here. You can use it freely but like usually, the script doesn’t have any warranties and I’m not responsible of anything bad happening because you’re using it. You’re welcome :)


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Under heavy construction :(