add description to ServiceConfig

This commit is contained in:
Doug MacEachern 2005-06-26 02:18:05 +00:00
parent 5b87277a6f
commit bcd101741b
3 changed files with 43 additions and 0 deletions

View File

@ -23,6 +23,12 @@ extern "C" {
typedef DWORD (CALLBACK *ChangeServiceConfig2_func_t)(SC_HANDLE, typedef DWORD (CALLBACK *ChangeServiceConfig2_func_t)(SC_HANDLE,
DWORD, LPVOID); DWORD, LPVOID);
typedef DWORD (CALLBACK *QueryServiceConfig2_func_t)(SC_HANDLE,
DWORD,
LPSERVICE_DESCRIPTION,
DWORD,
LPDWORD);
JNIEXPORT jboolean SIGAR_JNI(win32_Service_ChangeServiceDescription) JNIEXPORT jboolean SIGAR_JNI(win32_Service_ChangeServiceDescription)
(JNIEnv *env, jclass, jlong handle, jstring description) (JNIEnv *env, jclass, jlong handle, jstring description)
{ {
@ -293,6 +299,7 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
jfieldID id; jfieldID id;
jclass cls = env->GetObjectClass(obj); jclass cls = env->GetObjectClass(obj);
jstring value; jstring value;
HINSTANCE lib;
if (!QueryServiceConfig((SC_HANDLE)handle, config, if (!QueryServiceConfig((SC_HANDLE)handle, config,
sizeof(buffer), &bytes)) sizeof(buffer), &bytes))
@ -332,6 +339,27 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_QueryServiceConfig)
SERVICE_SetStringField("displayName", config->lpDisplayName); SERVICE_SetStringField("displayName", config->lpDisplayName);
if ((lib = LoadLibrary(L"advapi32"))) {
LPSERVICE_DESCRIPTION desc =
(LPSERVICE_DESCRIPTION)buffer;
QueryServiceConfig2_func_t query_config =
(QueryServiceConfig2_func_t)
GetProcAddress(lib, "QueryServiceConfig2W");
if (query_config) {
BOOL retval =
query_config((SC_HANDLE)handle,
SERVICE_CONFIG_DESCRIPTION,
desc, sizeof(buffer), &bytes);
if (retval && (desc->lpDescription != NULL)) {
SERVICE_SetStringField("description",
desc->lpDescription);
}
}
FreeLibrary(lib);
}
return JNI_TRUE; return JNI_TRUE;
} }

View File

@ -360,6 +360,8 @@ public class Service extends Win32 {
if (deps.length != 0) { if (deps.length != 0) {
System.out.println(" deps..." + Arrays.asList(deps)); System.out.println(" deps..." + Arrays.asList(deps));
} }
System.out.println(" desc..." + config.getDescription());
System.out.println("");
} }
} }
} }

View File

@ -81,6 +81,7 @@ public class ServiceConfig {
String[] dependencies = null; String[] dependencies = null;
String serviceStartName; String serviceStartName;
String displayName; String displayName;
String description;
/** /**
* @return Returns the binaryPathName. * @return Returns the binaryPathName.
@ -193,4 +194,16 @@ public class ServiceConfig {
public void setType(int type) { public void setType(int type) {
this.type = type; this.type = type;
} }
/**
* @return Returns the description.
*/
public String getDescription() {
return description;
}
/**
* @param description The description to set.
*/
public void setDescription(String description) {
this.description = description;
}
} }