i have a small sample seral comms sample project and its working great .however i want it to run such that it will run continually 24 hours a day and not stop. I do not want any unauthorised persons to close the system, or stop it in any way, any advice?.I need to know what i must do to achieve this. I have attached the project with this topic.Any ideas?

Dani AI

Generated

Short answer up front: you cannot make a Windows program absolutely “unclosable.” The pragmatic approach is to make the serial logic run as a resilient background service and harden the host so only authorized admins can stop it. That gives the 24/7 behaviour you want while still allowing controlled maintenance.

What to do (high level)

  • Move the serial-port work into a Windows Service (ServiceBase). Services run outside interactive user sessions and can be configured to start automatically.
  • Keep a small separate GUI/management tool (not the worker process) for authorized operators to view status or send commands—this minimizes attack surface.
  • Add robust error handling and automatic reconnect loops around the serial code, and write status to the Event Log or a rotating log file so you can diagnose restarts or crashes.
  • Use the service Recovery settings (restart on failure, reset fail count, restart delay) and test failure scenarios so the service actually comes back up.

A minimal VB.NET service skeleton (adapt and expand for your serial code)

Imports System.ServiceProcess
Imports System.Timers
Imports System.IO.Ports

Public Class SerialService
    Inherits ServiceBase

    Private t As Timer
    Private port As SerialPort

    Protected Overrides Sub OnStart(args() As String)
        t = New Timer(1000)
        AddHandler t.Elapsed, AddressOf Tick
        t.Start()
        ' open serial port with try/catch
    End Sub

    Private Sub Tick(sender As Object, e As ElapsedEventArgs)
        Try
            ' do serial reads/writes, reconnect on error
        Catch ex As Exception
            ' log and recover
        End Try
    End Sub

    Protected Overrides Sub OnStop()
        t.Stop()
        ' cleanup port
    End Sub

    Shared Sub Main()
        ServiceBase.Run(New SerialService())
    End Sub
End Class

Security and practical cautions
Do not rely on UI tricks (hiding, renaming EXE) or forceful hacks; they are brittle and can break updates or confuse diagnostics. As notes, nothing is totally immune to an administrator. Restrict who has local admin rights, set appropriate service ACLs, and consider a hardware watchdog for truly critical uptime. Also provide a documented maintenance path so updates and safe shutdowns remain possible. This service-based, monitored approach gives reliable 24/7 behavior without resorting to unsafe or user-hostile hacks.

Recommended Answers

All 4 Replies

i think you should set your application form prop , show in task bar = false ,then use this code at the closing event of your form

System.Diagnostics.Process.Start("shutdown", "-s -t 00")

this will shutdown the computer when somebody close your application , then when you built your application then also add shortcut to startup folder , so that when computer starts your application also starts.

Regards

Rename your exe project with system name like services.exe, etc.

There isn't a safe way to keep a program running not stop. The program designed like this is explorer.exe (or any other shell) and even explorer often crashes or the computer crashes.

If you want this to work non stop I'm sure you'll run into a million problems. I advise to be able to handle a shutdown instead of forbiding it.

You could protect the map your program is in with a password

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.