// }
// }
// }
String id = WindowsSlaveInstaller.generateServiceId(path);
Win32Service slaveService = services.getService(id);
if(slaveService==null) {
logger.println(Messages.ManagedWindowsServiceLauncher_InstallingSlaveService());
if(!DotNet.isInstalled(2,0, name, auth)) {
// abort the launch
logger.println(Messages.ManagedWindowsServiceLauncher_DotNetRequired());
return;
}
// copy exe
logger.println(Messages.ManagedWindowsServiceLauncher_CopyingSlaveExe());
copyStreamAndClose(getClass().getResource("/windows-service/jenkins.exe").openStream(), new SmbFile(remoteRoot,"jenkins-slave.exe").getOutputStream());
copySlaveJar(logger, remoteRoot);
// copy jenkins-slave.xml
String xml = createAndCopyJenkinsSlaveXml(id, logger, remoteRoot);
// install it as a service
logger.println(Messages.ManagedWindowsServiceLauncher_RegisteringService());
Document dom = new SAXReader().read(new StringReader(xml));
Win32Service svc = services.Get("Win32_Service").cast(Win32Service.class);
int r;
AccountInfo logOn = getLogOn();
if (logOn == null) {
r = svc.Create(
id,
dom.selectSingleNode("/service/name").getText()+" at "+path,
path+"\\jenkins-slave.exe",
Win32OwnProcess, 0, "Manual", true);
} else {
r = svc.Create(
id,
dom.selectSingleNode("/service/name").getText()+" at "+path,
path+"\\jenkins-slave.exe",
Win32OwnProcess,
0,
"Manual",
false, // When using a different user, it isn't possible to interact
logOn.userName,
Secret.toString(logOn.password),
null, null, null);
}
if(r!=0) {
listener.error("Failed to create a service: "+svc.getErrorMessage(r));
return;
}
slaveService = services.getService(id);
} else {
createAndCopyJenkinsSlaveXml(id, logger, remoteRoot);