Windows service setup project custom dialog - how do i get the variables? - vb.net

Quick question about a windows service, I've added a setup project for my Windows service, and ive added a custom dialog to it, with 4 text fields, but my question is how to i get these informations/variables?
Ive also added an installer for the windows service also, and afterwards the setup project, with the custom dialog.
The informations is something like database connection strings, and so on - so just string values.
This is my code for the "project installer" . the installer item ive added for the windows serive if you wanted to see it.
Imports System
Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.ServiceProcess
Imports System.Runtime.InteropServices
Public Class ProjectInstaller
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
My.Settings.TestSetting = Context.Parameters.Item("PathValue")
#If DEBUG Then
Dim ServicesToRun As ServiceBase()
ServicesToRun = New ServiceBase() {New tdsCheckService()}
ServiceBase.Run(ServicesToRun)
#Else
Dim listener As New tdsCheckService()
listener.Start()
#End If
End Sub
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Dim regsrv As New RegistrationServices
regsrv.RegisterAssembly(MyBase.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase)
End Sub
Public Overrides Sub Uninstall(ByVal savedState As System.Collections.IDictionary)
MyBase.Uninstall(savedState)
Dim regsrv As New RegistrationServices
regsrv.UnregisterAssembly(MyBase.GetType().Assembly)
End Sub
Private Sub ServiceProcessInstaller1_AfterInstall(sender As Object, e As InstallEventArgs) Handles ServiceProcessInstaller1.AfterInstall
End Sub
Private Sub ServiceInstaller1_AfterInstall(sender As Object, e As InstallEventArgs) Handles ServiceInstaller1.AfterInstall
End Sub
End Class

You should eb able to access them using the Context object.
'Get Protected Configuration Provider name from custom action parameter
Dim variableName As String = Context.Parameters.Item("dialogSettingName")
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)

Related

VSTO for Office 2010 Globals.Thisaddin is always null

I have a Powerpoint addin, which when I need to reference Globals.ThisAddin.Application (the current instance or active instance of powerpoint calling to the addin) It returns a null reference. I do need `Globals.ThisAddIn.Application' or another method to get the current active instance of Powerpoint because it is used to generate something in the active presentation's active slide.
Watches
I tried using watches to track the error, but it says the following.
Code
VBA
Private Sub tst()
Dim tmp As object
Set tmp = New object
tmp.dosomething ' error triggered is here
Set tmp = Nothing
End Sub
Simplified VB.NET
ThisAddin
Imports Microsoft.Office.Interop.PowerPoint
Imports System.Diagnostics
Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
End Class
Custom Namespace and Class
Imports System.Data
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports Ppt = Microsoft.Office.Interop.PowerPoint
Namespace CustomStuff
<ComVisible(True)> _
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface IObject
Sub DoSomething()
End Interface
<ComVisible(True)> _
<ClassInterface(ClassInterfaceType.None)> _
Public Class Obj
Implements IObject
<ComVisible(True)>
Public Sub DoSomething() Implements IObject.DoSomething
Dim cpres As Ppt.Presentation
cpres = Globals.ThisAddIn.Application.ActivePresentation ' <- error is here
With cpres.Slides(cpres.Windows(1).Selection.SlideRange.SlideIndex)
...
End With
End Sub
Private Sub New()
End Sub
<ComVisible(True)>
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class
End Namespace
Software And IDE
The ThisAddIn class comes from a VSTO Add-in project. You can access this object by using the Globals.ThisAddIn property. But I don't see the code of add-in in your sample. It seems you are trying to use the Application property outside of boundaries of the add-in.
See Global access to objects in Office projects for more information.

Convert the program interface to another language interface VB.NET

What is wrong with the code to convert the program interface to another language interface? In Visual Basic .NET (Visual Studio 2019)
Imports System.Globalization
Imports System.ComponentModel
Public Class Form1
Private Sub ArButton_Click(sender As Object, e As EventArgs) Handles ArButton.Click
Languages.changelanguge("ar")
End Sub
Private Sub EnButton_Click(sender As Object, e As EventArgs) Handles EnButton.Click
Languages.changelanguge("en")
End Sub
End Class
Public Module Languages
Public Sub changelanguge(ByVal languge As String)
For Each obj As Control In Form1.Controls
Dim lang As ComponentResourceManager = New ComponentResourceManager(GetType(Form1))
lang.ApplyResources(obj, obj.Name, New CultureInfo(languge))
Next
End Sub
End Module
What is happening when you run the code? I was implementing this recently and the below link assisted a lot.
https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=netframework-4.8

Event 'Load' cannot be found

Getting the error "Event 'Load' cannot be found" referring to "Handles MyBase.Load" Please see attached code. Any help much appreciated!
I have many other applications set up the same way and they all work. However, these were in an older version of Visual Studio.
Option Explicit On
Option Strict On
Imports System, System.IO
Imports System.Text
Public Class Form1
Private Sub cleanXMLDialog_Load(ByVal eventSender As System.Object, ByVal
eventArgs As System.EventArgs) Handles MyBase.Load
Main()
End
End Sub
Public Sub Main()
Dim directories() As String = Directory.GetDirectories("C:\")
Dim files() As String = Directory.GetFiles("C:\", "*.dll")
DirSearch("c:\")
End Sub
Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String
Try
For Each d In Directory.GetDirectories(sDir)
For Each f In Directory.GetFiles(d, "*.xml")
'Dim Response As String = MsgBox(f)
Debug.Write(f)
Next
DirSearch(d)
Next
Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
End Class
Load should happen without this error.
This is the class declaration:
Public Class Form1
It looks like you intend this to inherit from a windows Form type, but there's nothing here to make that happen.
You may want this:
Public Class Form1 Inherits System.Windows.Forms.Form
but even this is unlikely to really accomplish anything. It's not enough just to inherit from the Form type if you don't have any controls are properties set and don't ever show the form.
Did you accidentally create a Console or Class Library project when you mean to create a WinForms project?

NSQ vb.net MessageHandler

I am trying to use this package in vb.net NsqSharp
There is a good code for it in C# but i need it in vb.net.
I got it to send a message to my NSQ server, but the problem is to get it.
But i get a error on consumer.AddHandler(New HandleMessage()) and i do not know if i declare the HandleMessage right.
Imports NsqSharp
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim producer = New Producer("127.0.0.1:4150")
producer.Publish("test-topic-name", Me.txt_tx.Text)
producer.Stop()
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim consumer = New Consumer("test-topic-name", "channel-name")
consumer.AddHandler(New HandleMessage())
consumer.ConnectToNsqLookupd("127.0.0.1:4161")
consumer.Stop()
End Sub
Public Interface IHandler : End Interface
Public Sub HandleMessage(message As Message)
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MsgBox(msg)
End Sub
Public Sub LogFailedMessage(message As Message)
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MsgBox(msg)
End Sub
End Class
But i get a error on Implements IHandler
Lovely description of the problem, you can't get useful answers when you don't describe the exact error message you see. You did write the code wrong, VB.NET requires the Implements keyword on interface method implementations. You'd normally fall in the pit of success by letting the IDE generate these methods for you. As soon as you type "Implements IHandler" and press the Enter key, the IDE automagically adds the methods.
So there's probably something wrong with the library reference as well. Steps one-by-one:
Tools > Nuget Package Manager > Package Manager Console.
Type "Install-Package NsqSharp". Watch it trundle while it downloads and installs the package.
Put Imports NsqSharp at the top of the source file.
You should now end up with:
Public Class MessageHandler
Implements IHandler
Private Sub IHandler_HandleMessage(message As Message) Implements IHandler.HandleMessage
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MessageBox.Show(msg)
End Sub
Private Sub IHandler_LogFailedMessage(message As Message) Implements IHandler.LogFailedMessage
Dim msg As String = Encoding.UTF8.GetString(message.Body)
MessageBox.Show(msg)
End Sub
End Class

'Sub Main' was not found. Service management console application error?

There is possibly a few things wrong with the below. Haven't had a chance to test/debug the code yet as can't run it. It stating that no main method has been found. But there is? i've even changed it to shared etc. It's probably something obvious?
It's flagging - 'Sub Main' was not found in 'ConsoleApplication1.Module1' error.
Also the main method wasn't always a separate class, I was just trying stuff. I'm importing a reference - system.processes. Was initially created as a vb.form but realised i didn't want the form part and recreated as a console app (which is very possibly where the problem lies as it's one of the first console apps i've done).
Code is basically planned to act on a service dying. Report and try and manage the restart (not finished, ideas welcome).
Imports System
Imports System.Management
Imports System.ServiceProcess
Imports System.Diagnostics
Imports System.Threading
Imports System.IO
Module Module1
Public Class Control
Public Sub Main() 'Public Sub Main(ByVal sArgs() As String)
Dim restart As New Rest
restart.startTime = DateTime.Now()
restart.cr20Services()
restart.Report()
End Sub
End Class
Public Class Rest
public startTime As String
Dim logPath As String = "C:\cr20\restart.txt"
'Dim fileExists As Boolean = File.Exists(strFile)
Dim arrcr20ServicesInitialStatus As New ArrayList
Dim failedServices As New ArrayList
Dim arrcr20Services As New ArrayList
Public Sub cr20Services()
'cr20 Services
arrcr20Services.Add("cr20 service")
arrcr20Services.Add("cr20 router")
For Each cr20Service In arrcr20Services
arrcr20ServicesInitialStatus.Add(cr20Service & " - " & cr20Status(cr20Service))
cr20Restore(cr20Service)
Next
End Sub
Private Function cr20Status(ByVal cr20Service As String)
Dim service As ServiceController = New ServiceController(cr20Service)
Return service.Status.ToString
End Function
Private Sub cr20Restore(ByVal cr20Service As String)
Dim service As ServiceController = New ServiceController(cr20Service)
'Dim p() As System.Diagnostics.Process = System.Diagnostics.Process.GetProcessesByName("calc")
If (service.Status.Equals(ServiceControllerStatus.Stopped)) Or (service.Status.Equals(ServiceControllerStatus.StopPending)) Then
failedServices.Add(service)
service.Stop()
Thread.Sleep(10000) 'give service 10 seconds to stop
service.Start()
End If
End Sub