Hello Guys,
I was trying to modify AD credentials for a particular service, For that have been using JNA
com.sun.jna.platform.win32.Advapi32
library but I could not able to change or modify or upgrade AD credentials.
What I have tried:
I have tried in java.
public class JNAExample {
private static void ModifyADCredentials(String username, String password) {
SC_HANDLE serviceManager = Advapi32.INSTANCE.OpenSCManager("MLI-LAP-155", null, Winsvc.SC_MANAGER_ALL_ACCESS);
SC_HANDLE service = Advapi32.INSTANCE.OpenService(serviceManager, "ServiceName", WinNT.GENERIC_EXECUTE);
ChangeServiceConfigInfo info = new ChangeServiceConfigInfo();
info.thisAccount = "adminGod";
info.password = "admin@123";
boolean value = Advapi32.INSTANCE.ChangeServiceConfig2(service, Winsvc.SERVICE_CHANGE_CONFIG, info);
Advapi32.INSTANCE.CloseServiceHandle(service);
}
}
@FieldOrder({ "thisAccount", "password", "confirmPassword" })
public class ChangeServiceConfigInfo extends ChangeServiceConfig2Info {
static class myRef extends ChangeServiceConfigInfo implements ByReference {}
public String thisAccount;
public String password;
public String confirmPassword;
@Override
protected Memory autoAllocate(int size) {
return super.autoAllocate(100);
}
@Override
protected List<String> getFieldOrder() {
return Arrays.asList(new String[] { "thisAccount", "password" ,"confirmPassword"});
}
}