Example #1
0
func TestLog(t *testing.T) {
	const name = "mylog"
	const supports = eventlog.Error | eventlog.Warning | eventlog.Info
	err := eventlog.InstallAsEventCreate(name, supports)
	if err != nil {
		t.Fatalf("Install failed: %s", err)
	}
	l, err := eventlog.Open(name)
	if err != nil {
		t.Fatalf("Open failed: %s", err)
	}
	defer l.Close()
	err = l.Info(1, "info")
	if err != nil {
		t.Fatalf("Info failed: %s", err)
	}
	err = l.Warning(2, "warning")
	if err != nil {
		t.Fatalf("Warning failed: %s", err)
	}
	err = l.Error(3, "error")
	if err != nil {
		t.Fatalf("Error failed: %s", err)
	}
	err = eventlog.Remove(name)
	if err != nil {
		t.Fatalf("Remove failed: %s", err)
	}
}
Example #2
0
func (this *Service) RemoveService() error {
	l, err := eventlog.Open(this.name)
	if err != nil {
		return fmt.Errorf("Cannot open eventlog")
	}

	m, err := mgr.Connect()
	if err != nil {
		l.Error(3, fmt.Sprintf("remove service: cannot connect to windows service manager.", err))
		return err
	}
	defer m.Disconnect()

	s, err := m.OpenService(this.name)
	if err != nil {
		l.Error(3, fmt.Sprintf("remove service: service %s doesn't exists", this.name))
		return fmt.Errorf("service %s doesn't exists", this.name)
	}

	err = s.Delete()
	if err != nil {
		return err
	}

	l.Info(1, "Service Removed. removing event log")
	l.Close()

	eventlog.Remove(this.name)
	return nil
}
Example #3
0
func removeService(name string) error {
	m, err := mgr.Connect()
	if err != nil {
		return err
	}
	defer m.Disconnect()
	s, err := m.OpenService(name)
	if err != nil {
		return fmt.Errorf("service %s is not installed", name)
	}
	defer s.Close()
	err = s.Delete()
	if err != nil {
		return err
	}
	err = eventlog.Remove(name)
	if err != nil {
		return fmt.Errorf("RemoveEventLogSource() failed: %s", err)
	}
	return nil
}
func (ws *windowsService) Uninstall() error {
	m, err := mgr.Connect()
	if err != nil {
		return err
	}
	defer m.Disconnect()
	s, err := m.OpenService(ws.Name)
	if err != nil {
		return fmt.Errorf("service %s is not installed", ws.Name)
	}
	defer s.Close()
	err = s.Delete()
	if err != nil {
		return err
	}
	err = eventlog.Remove(ws.Name)
	if err != nil {
		return fmt.Errorf("RemoveEventLogSource() failed: %s", err)
	}
	return nil
}