1

When windows server 2019 comes to the desktop, when the application.exe is run, the sql connects and runs smoothly. But when I write this application as a service, I have a Turkish character problem when the application.exe runs. It shows letters like "İŞıö.." differently. The working logic of the services is different from running the application by double-clicking on the desktop and running it with the service. how can i solve this problem. related service code

Imports System.Timers

Public Class Service1
    Dim proc As Process
    Dim tmr As Timer

    Protected Overrides Sub OnStart(ByVal args() As String)
        Try
            WriteToFile("SQL wait")
            tmr = New Timer
            tmr.Interval = 30000
            AddHandler tmr.Elapsed, AddressOf SqlRun
            tmr.Enabled = True
        Catch ex As Exception
            tmr.Enabled = False
            WriteToFile("err " & ex.Message)
        End Try
    End Sub

    Private Sub SqlRun(sender As Object, e As ElapsedEventArgs)
        tmr.Enabled = False
        Try
            WriteToFile("app run")
            proc = New Process()
            proc = Process.Start("C:\app.exe")
            WriteToFile("app run. ID " & proc.Id)
        Catch ex As Exception
            WriteToFile("app err " + ex.Message + ex.StackTrace)
        End Try
    End Sub

    Protected Overrides Sub OnStop()
        tmr.Enabled = False
        WriteToFile("app end")
        proc = New Process
        proc = Process.Start("taskkill", "/f /im app.exe")
        WriteToFile("app end. ID " & proc.Id)
    End Sub

    Private Sub WriteToFile(text As String)
        text += " " & Format(DateTime.Now, "dd/MM/yyyy hh:mm:ss")

        Using writer As New IO.StreamWriter(path, True)
            writer.WriteLine(text)
            writer.Close()
        End Using
    End Sub
End Class
Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28
FikretBa
  • 21
  • 4
  • Are you viewing the letters in the same program (e.g. Notepad) for both the desktop and service versions? – Andrew Morton Sep 04 '22 at 13:05
  • (Instead of using a StreamWriter, you can use the [File.AppendAllText Method](https://learn.microsoft.com/en-us/dotnet/api/system.io.file.appendalltext) to do those four lines as one.) – Andrew Morton Sep 04 '22 at 13:10
  • 3
    A windows service will likely be running in a different user profile with different regional and environment settings to the desktop app – Hursey Sep 04 '22 at 20:35
  • How can I change regional settings in the service without application.exe running? – FikretBa Sep 06 '22 at 09:10
  • 1
    @FikretBa Some programs don't *display* the characters correctly. Are you viewing the letters in the same program (e.g. Notepad) for both the desktop and service versions? – Andrew Morton Sep 07 '22 at 17:32
  • Default global regional setting: https://learn.microsoft.com/en-us/answers/questions/254248/default-global-regional-setting.html – Sabuncu Sep 08 '22 at 07:18
  • The application.exe application is connecting with sql, it is not the application I wrote. I want the app to run automatically from services. As in the code above proc = Process.Start("C:\app.exe") i am doing it by running it gives Turkish character problem. But when I do it with double click it doesn't give this problem. – FikretBa Sep 09 '22 at 10:38

0 Answers0