Commit b9da31f1 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

msi: Implement the DeleteServices standard action.

parent 3d38c077
......@@ -4570,26 +4570,12 @@ error:
return FALSE;
}
static UINT ITERATE_StopService(MSIRECORD *rec, LPVOID param)
static UINT stop_service( LPCWSTR name )
{
MSIPACKAGE *package = param;
MSICOMPONENT *comp;
SC_HANDLE scm = NULL, service = NULL;
SERVICE_STATUS status;
SERVICE_STATUS_PROCESS ssp;
SC_HANDLE scm = NULL, service = NULL;
LPWSTR name, args;
DWORD event, needed;
event = MSI_RecordGetInteger(rec, 3);
if (!(event & msidbServiceControlEventStop))
return ERROR_SUCCESS;
comp = get_loaded_component(package, MSI_RecordGetString(rec, 6));
if (!comp || comp->Action == INSTALLSTATE_UNKNOWN || comp->Action == INSTALLSTATE_ABSENT)
return ERROR_SUCCESS;
deformat_string(package, MSI_RecordGetString(rec, 2), &name);
deformat_string(package, MSI_RecordGetString(rec, 4), &args);
DWORD needed;
scm = OpenSCManagerW(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!scm)
......@@ -4604,16 +4590,14 @@ static UINT ITERATE_StopService(MSIRECORD *rec, LPVOID param)
SERVICE_ENUMERATE_DEPENDENTS);
if (!service)
{
WARN("Failed to open service (%s): %d\n",
debugstr_w(name), GetLastError());
WARN("Failed to open service (%s): %d\n", debugstr_w(name), GetLastError());
goto done;
}
if (!QueryServiceStatusEx(service, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp,
sizeof(SERVICE_STATUS_PROCESS), &needed))
{
WARN("Failed to query service status (%s): %d\n",
debugstr_w(name), GetLastError());
WARN("Failed to query service status (%s): %d\n", debugstr_w(name), GetLastError());
goto done;
}
......@@ -4628,8 +4612,28 @@ static UINT ITERATE_StopService(MSIRECORD *rec, LPVOID param)
done:
CloseServiceHandle(service);
CloseServiceHandle(scm);
msi_free(name);
msi_free(args);
return ERROR_SUCCESS;
}
static UINT ITERATE_StopService( MSIRECORD *rec, LPVOID param )
{
MSIPACKAGE *package = param;
MSICOMPONENT *comp;
LPWSTR name;
DWORD event;
event = MSI_RecordGetInteger( rec, 3 );
if (!(event & msidbServiceControlEventStop))
return ERROR_SUCCESS;
comp = get_loaded_component( package, MSI_RecordGetString( rec, 6 ) );
if (!comp || comp->Action == INSTALLSTATE_UNKNOWN || comp->Action == INSTALLSTATE_ABSENT)
return ERROR_SUCCESS;
deformat_string( package, MSI_RecordGetString( rec, 2 ), &name );
stop_service( name );
msi_free( name );
return ERROR_SUCCESS;
}
......@@ -4653,6 +4657,69 @@ static UINT ACTION_StopServices( MSIPACKAGE *package )
return rc;
}
static UINT ITERATE_DeleteService( MSIRECORD *rec, LPVOID param )
{
MSIPACKAGE *package = param;
MSICOMPONENT *comp;
LPWSTR name = NULL;
DWORD event;
SC_HANDLE scm = NULL, service = NULL;
event = MSI_RecordGetInteger( rec, 3 );
if (!(event & msidbServiceControlEventDelete))
return ERROR_SUCCESS;
comp = get_loaded_component( package, MSI_RecordGetString(rec, 6) );
if (!comp || comp->Action == INSTALLSTATE_UNKNOWN || comp->Action == INSTALLSTATE_ABSENT)
return ERROR_SUCCESS;
deformat_string( package, MSI_RecordGetString(rec, 2), &name );
stop_service( name );
scm = OpenSCManagerW( NULL, NULL, SC_MANAGER_ALL_ACCESS );
if (!scm)
{
WARN("Failed to open the SCM: %d\n", GetLastError());
goto done;
}
service = OpenServiceW( scm, name, DELETE );
if (!service)
{
WARN("Failed to open service (%s): %u\n", debugstr_w(name), GetLastError());
goto done;
}
if (!DeleteService( service ))
WARN("Failed to delete service (%s): %u\n", debugstr_w(name), GetLastError());
done:
CloseServiceHandle( service );
CloseServiceHandle( scm );
msi_free( name );
return ERROR_SUCCESS;
}
static UINT ACTION_DeleteServices( MSIPACKAGE *package )
{
UINT rc;
MSIQUERY *view;
static const WCHAR query[] = {
'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
rc = MSI_DatabaseOpenViewW( package->db, query, &view );
if (rc != ERROR_SUCCESS)
return ERROR_SUCCESS;
rc = MSI_IterateRecords( view, NULL, ITERATE_DeleteService, package );
msiobj_release( &view->hdr );
return rc;
}
static MSIFILE *msi_find_file( MSIPACKAGE *package, LPCWSTR filename )
{
MSIFILE *file;
......@@ -5995,12 +6062,6 @@ static UINT ACTION_SelfUnregModules( MSIPACKAGE *package )
return msi_unimplemented_action_stub( package, "SelfUnregModules", table );
}
static UINT ACTION_DeleteServices( MSIPACKAGE *package )
{
static const WCHAR table[] = {
'S','e','r','v','i','c','e','C','o','n','t','r','o','l',0 };
return msi_unimplemented_action_stub( package, "DeleteServices", table );
}
static UINT ACTION_ValidateProductID( MSIPACKAGE *package )
{
static const WCHAR table[] = {
......
......@@ -367,6 +367,7 @@ static const CHAR sss_install_exec_seq_dat[] = "Action\tCondition\tSequence\n"
"WriteEnvironmentStrings\t\t4550\n"
"CreateShortcuts\t\t4600\n"
"StartServices\t\t5000\n"
"DeleteServices\t\t5500\n"
"InstallFinalize\t\t6600\n"
"InstallInitialize\t\t1500\n"
"InstallValidate\t\t1400\n"
......@@ -1849,6 +1850,19 @@ static const msi_table sss_tables[] =
ADD_TABLE(property)
};
static const msi_table sds_tables[] =
{
ADD_TABLE(component),
ADD_TABLE(directory),
ADD_TABLE(feature),
ADD_TABLE(feature_comp),
ADD_TABLE(file),
ADD_TABLE(sss_install_exec_seq),
ADD_TABLE(service_control),
ADD_TABLE(media),
ADD_TABLE(property)
};
/* cabinet definitions */
/* make the max size large so there is only one cab file */
......@@ -7521,6 +7535,34 @@ static void test_start_services(void)
}
}
static void test_delete_services(void)
{
UINT r;
create_test_files();
create_database(msifile, sds_tables, sizeof(sds_tables) / sizeof(msi_table));
MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
r = MsiInstallProductA(msifile, NULL);
ok(r == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", r);
ok(delete_pf("msitest\\cabout\\new\\five.txt", TRUE), "File not installed\n");
ok(delete_pf("msitest\\cabout\\new", FALSE), "Directory not created\n");
ok(delete_pf("msitest\\cabout\\four.txt", TRUE), "File not installed\n");
ok(delete_pf("msitest\\cabout", FALSE), "Directory not created\n");
ok(delete_pf("msitest\\changed\\three.txt", TRUE), "File not installed\n");
ok(delete_pf("msitest\\changed", FALSE), "Directory not created\n");
ok(delete_pf("msitest\\first\\two.txt", TRUE), "File not installed\n");
ok(delete_pf("msitest\\first", FALSE), "Directory not created\n");
ok(delete_pf("msitest\\filename", TRUE), "File not installed\n");
ok(delete_pf("msitest\\one.txt", TRUE), "File not installed\n");
ok(delete_pf("msitest\\service.exe", TRUE), "File not installed\n");
ok(delete_pf("msitest", FALSE), "Directory not created\n");
delete_test_files();
}
START_TEST(install)
{
DWORD len;
......@@ -7614,6 +7656,7 @@ START_TEST(install)
test_feature_override();
test_create_folder();
test_start_services();
test_delete_services();
DeleteFileA(log_file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment