Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6814587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:42:24+00:00 2026-05-26T20:42:24+00:00

So I have this Windows service created in VB.Net, and all it does is

  • 0

So I have this Windows service created in VB.Net, and all it does is perform a few calls and sits there. (Does nothing really)

I have it installed on a test machine and when I start it manually, it starts up. When I stop manually, shuts down properly (onStop is called).

When I start it, and reboot the machine, the service starts like it should, but when I log in, the service isn’t running anymore and the onStop never showed up as being executed.

I installed the service with admin privileges, so that shouldn’t be an issue.

Here is what I have:

Sub New()

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    '' Open our log file
    FileReader = New IO.StreamWriter("C:\test.txt", True)



    Log("Starting service...")

    '' Get the username from the process list (If explorer is open (Meaning a user is logged in)
    Dim ProcessList As System.Diagnostics.Process()
    ProcessList = System.Diagnostics.Process.GetProcesses()
    Dim Proc As System.Diagnostics.Process
    For Each Proc In ProcessList
        If Proc.ProcessName.ToLower() = "explorer" Then
            My.Settings.Username = GetProcessUserName(Proc)
            Exit For
        End If
    Next

    Log("Fetched user name: " & My.Settings.Username)
    Try
        '' Get the IP address of the machine
        Dim h As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName)
        My.Settings.IP = h.AddressList.GetValue(0).ToString

        '' Get the Machine Information
        My.Settings.MachineName = System.Environment.MachineName()

        '' Get the Operating System Version
        Dim osInfo As New FindOsInfo
        My.Settings.OS = osInfo.OsName.ToString().Replace(" ", "").Split("|")(0)

    Catch ex As Exception
        Log("Startup error: " & ex.Message)
    End Try


    '' Start server listen here


End Sub

'Protected Overrides Sub OnStart(ByVal args() As String)

'End Sub

Protected Overrides Sub OnStop()
    ' Add code here to perform any tear-down necessary to stop your service.
    Log("Closing down service...")
    FileReader.Close()

End Sub

    Public Sub Log(ByVal str As String)
        Dim time As DateTime = DateTime.Now
        FileReader.WriteLine("[" & time.ToString("G") & "] " & str)
        FileReader.Flush()
    End Sub

Thanks for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:42:24+00:00Added an answer on May 26, 2026 at 8:42 pm

    The issue is most likely that My.Settings.UserName is nothing when you reboot the machine since there isn’t an interactive user, so your statement:

     Log("Fetched user name: " & My.Settings.Username)
    

    is throwing an exception. You should move all of your code after:

    Log("Starting service...")
    

    inside the Try and also add a test for the existence of username before logging it:

    If My.Settings IsNot Nothing AndAlso My.Settings.UserName IsNot Nothing Then
         Log("Fetched user name: " & My.Settings.Username)
    Else
         Log("No interactive user")
    End if
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows Service developed in C# and .NET 3.5 to perform various
HI All, I have successfully created a Quartz.NET remote server running inside a windows
I have created a .NET Windows Service which performs certain actions and generates reports.
I have a dot net windows service project which contains multiple services. This has
I have written a Windows service that spawns a separate process. This process creates
I have the VS2005 standard edition and MS says this: Note: The Windows Service
I have a Windows service built upon ATL 7's CAtlServiceModuleT class. This service serves
I have an executable that is started by a windows service, this program will
I have created an OData/WCF service using Visual Studio 2010 on Windows XP SP3
I created a .NET windows service that installs without any issues on the dev

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.