function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PAWAN THOSARPAWAN THOSAR 

Write an apex program, to De-Activate the user based on the specified username at runtime.

SwethaSwetha (Salesforce Developers) 
HI Pawan,
Try the below apex class
public class DeactivateUser {
    public static void deactivate(String username) {
        User user = [SELECT Id, IsActive FROM User WHERE Username = :username];
        user.IsActive = false;
        update user;
    }
}

Run the below code in anonymous
DeactivateUser.deactivate('user@example.com');
This will deactivate the user with the username "user@example.com". 
Make sure you have the appropriate permissions to modify user records in Salesforce.

If this information helps, please mark the answer as best. Thank you
Shri RajShri Raj
String usernameToDeactivate = 'exampleuser@domain.com';
List<User> usersToUpdate = [SELECT Id, IsActive FROM User WHERE Username = :usernameToDeactivate];

if (usersToUpdate.size() == 1) {
    User userToUpdate = usersToUpdate[0];
    userToUpdate.IsActive = false;
    update userToUpdate;
    System.debug('User ' + userToUpdate.Username + ' has been deactivated');
} else {
    System.debug('User ' + usernameToDeactivate + ' not found or more than one user found with this username');
}