java經過Telnet 遠程修改windows用戶密碼

DOS命令 :net user username newpasswordjava

如何使用java遠程鏈接到windows :https://blog.csdn.net/kerafan/article/details/50180103windows


改密代碼:ide

import java.io.IOException;
import java.net.SocketException;

import com.autoOps.util.WindowsTelnetClient;

public class RemoteWinTest {

    public static void main(String[] args) {
        String hostname = "192.168.1.10"; // or:127.0.0.1  
        int port = 23;  
        String username = "username";  
        String password = "password";  
        
        String newPassword = "123456";
        
//        password = "123456";
//        newPassword = "password";
        
        String changePwd = "net user %s %s";
        
        WindowsTelnetClient client = new WindowsTelnetClient(hostname, port, username, password);  
        try {
            System.out.print(client.connect());
            
            changePwd = String.format(changePwd, username,newPassword);
            
            System.out.print(client.sendCommand(changePwd)); // 執行windows命令 
            System.out.print(client.disconnect());  
        } catch (SocketException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
    
    }

}
相關文章
相關標籤/搜索