vb.net application is not displayed when booting from task scheduler

1

I have an application developed on vb.net and I want to put it to run automatically on a server when I boot the system, so I'm using the windows task scheduler.

The problem is that if I open the application manually (without using the task scheduler) the application form is displayed, but if the task scheduler executes it or forces it to run from it, no application opens form, although the process appears in the task manager and the application does what it should ..

Any idea where the problem might come from?

Edit

I have tried to create a .bat that opens the program, and that the task scheduler opens that .bat instead of the program directly, but the same thing still happens.

Edit 2

It seems that when you schedule the task to start even if no user starts a session, it runs as a service. That seems the reason why no form is shown.

I leave the question open in case someone comes up with something new but seems to have no solution.

    
asked by Fernando 15.03.2018 в 18:25
source

1 answer

-2
' Prueba a insertar-lo en el registro de windows con todas estas funciones podrás hacer lo que sea... 

' Para Su uso utiliza esta funcion asi, yo la pondria en el Form_Load
' AddStartup(Application.ExecutablePath, "NombreApp", RegistryStartup.StartupCurrentUser )





' Y Todo esto al principio del formulario principal

' Enumeracion de Tipos de Claves que se pueden Crear
    Public Enum RegistryKeyTypes
        RegSZ
        RegExpandSZ
        RegBinary
        RegDWord
        RegMultiSZ
    End Enum

' Enumeracion de Tipos de Registros de Inicio
Public Enum RegistryStartup
        StartupLocalMachine
        StartupCurrentUser
    End Enum

' Y Esta la agrega la App al inicio al inicio...
Public Function AddStartup(ByVal ApplicationPath As String, _
                               ByVal ApplicationName As String, _
                      Optional ByVal SetIn As RegistryStartup = RegistryStartup.StartupLocalMachine)
        On Error Resume Next

        Select Case SetIn
            Case RegistryStartup.StartupLocalMachine
                ' Esta solo funciona en XP
                WriteKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" & _
                         ApplicationName, ApplicationPath, RegistryKeyTypes.RegSZ)
            Case RegistryStartup.StartupCurrentUser
                WriteKey("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run\" & _
                         ApplicationName, ApplicationPath, RegistryKeyTypes.RegSZ)
        End Select

    End Function
' Función de Lectura de Registro
Public Function ReadKey(ByVal KeyRegPath As String) As Object
        On Error Resume Next
        Dim Reg As Object
        Reg = CreateObject("WScript.Shell")
        ReadKey = Reg.RegRead(KeyRegPath)
        Reg = Nothing
    End Function

' Función de Escritura de Registro
Public Function WriteKey(ByVal KeyRegPath As String, _
                             ByVal ValueRegKey As Object, _
                             ByVal KeyType As RegistryKeyTypes) As Object  'Add New Key in Registry
        On Error Resume Next
        Dim RegistryReg As Object
        RegistryReg = CreateObject("WScript.Shell")
        With RegistryReg
            Select Case KeyType
                Case RegistryKeyTypes.RegDWord
                    .RegWrite(KeyRegPath, ValueRegKey, "REG_DWORD")
                Case RegistryKeyTypes.RegBinary
                    .RegWrite(KeyRegPath, ValueRegKey, "REG_BINARY")
                Case RegistryKeyTypes.RegSZ
                    .RegWrite(KeyRegPath, ValueRegKey, "REG_SZ")
                Case RegistryKeyTypes.RegMultiSZ
                    .RegWrite(KeyRegPath, ValueRegKey, "REG_MULTI_SZ")
                Case RegistryKeyTypes.RegExpandSZ
                    .RegWrite(KeyRegPath, ValueRegKey, "REG_EXPAND_SZ")
            End Select
        End With
        RegistryReg = Nothing
    End Function

' Funcion de Comprobacion de Clave de Registro
Public Function ExistKey(ByVal KeyPath As String) As Boolean
        ' Comprobar si existe una Clave en el Registro
        On Error Resume Next
        Dim D As Object     ' Devuelve un Variant
        Dim ObjRegistro As Object

        ' Creamos un Objeto de Registro
        ObjRegistro = CreateObject("WScript.Shell")
        ' y accedemos a su valor
        D = ObjRegistro.RegRead(KeyPath)

        ' Si hay un error es que la Clave no existe
        If Err.Number = 0 Then ExistKey = True

        ' Descargamos el Objeto
        ObjRegistro = Nothing
    End Function
    
answered by 29.05.2018 в 17:23