Custom properties for Windows service - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Custom properties for Windows service

ikkesjijikkesjij Posts: 6Member
hello all,

is there a way to create a windows service with a cusom property, lets say 'LogFilePath', and modify this custom property at runtime via the system.management Namespace from a winforms application?

I need to save some settings regarding my windows service and retrieve them later on, via a user interface to change and then save them again.

I hope somebody has some suggestions

regards,
ikkes

Comments

  • DrMartenDrMarten Posts: 748Member
    [b][red]This message was edited by DrMarten at 2006-6-21 19:3:50[/red][/b][hr]

    Here is the CLASS code>>

    [code]
    Public Class winService
    Private myPath As String
    Public Sub New(ByVal path As String)
    myPath = path
    End Sub
    Public Property path()
    Get
    Return myPath
    End Get
    Set(ByVal Value)
    myPath = Value
    End Set
    End Property
    End Class
    [/code]

    Then the main FORM code looks like>>
    [code]
    Dim myString As New winService("TestString")
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Use this sort of command to retrieve your path.
    TextBox1.Text = myString.path
    'To set the path use a line similiar to>>
    myString.path = "NewString"
    'Here is proof>>
    TextBox2.Text = myString.path
    End Sub
    [/code]

    or looks like this picture>>
    http://i13.photobucket.com/albums/a272/u-might-want-this/MainForm.jpg

    To add a CLASS proceed as follows>>
    1) Go to this area of your window>>

    http://i13.photobucket.com/albums/a272/u-might-want-this/Adding_a_class1.jpg

    2) Name the CLASS as winservice.vb in the NAME box see>>
    http://i13.photobucket.com/albums/a272/u-might-want-this/Adding_a_class2.jpg

    then click on OPEN

    3) The CLASS code is given above so your window should look like>>
    http://i13.photobucket.com/albums/a272/u-might-want-this/Adding_a_class3.jpg

    The FORM code as above looks like this IN FULL>>
    http://i13.photobucket.com/albums/a272/u-might-want-this/MainForm-1.jpg

    If you want the CLASS expanding for more properties then let me know. :-)

    [red][b]
    Don't forget to write all values to a file on your computer
    or another computer via the internet, otherwise the variable
    values will be lost when you switch your PC off.
    [/b][/red]



    Regards,

    Dr M.

  • ikkesjijikkesjij Posts: 6Member
    maybe i was not clear about what i want to acomplish.

    I have created a windows service, that's running as a registred windows service.

    on the other hand, i have a windows forms application. i want this app to 'talk' with my service. so i can make some custom settings while the service is running. I think i can do this by invoking a method like this

    ======================================================

    Dim wmiService As System.Management.ManagementObject
    Dim inArgs As System.Management.ManagementBaseObject
    Dim outArgs As System.Management.ManagementBaseObject

    wmiService = New System.Management.ManagementObject("Win32_service.Name='MyService'")

    wmiService.Get()

    inArgs = wmiService.GetMethodParameters("MyMethod")
    inArgs ("FilePath") = "C:MyDir"

    outArgs = wmiService.InvokeMethod("MyMethod", inArgs, Nothing)

    ======================================================

    my question is what do i have to do in my windows service project to make "Sub MyMethod(ByVal FilePath As String)" available to the outside world, so i can call it like i discribed above.

    ikkesjij.
  • DrMartenDrMarten Posts: 748Member
    : maybe i was not clear about what i want to acomplish.
    :
    : I have created a windows service, that's running as a registred windows service.
    :
    : on the other hand, i have a windows forms application. i want this app to 'talk' with my service. so i can make some custom settings while the service is running. I think i can do this by invoking a method like this
    :
    : ======================================================
    :
    : Dim wmiService As System.Management.ManagementObject
    : Dim inArgs As System.Management.ManagementBaseObject
    : Dim outArgs As System.Management.ManagementBaseObject
    :
    : wmiService = New System.Management.ManagementObject("Win32_service.Name='MyService'")
    :
    : wmiService.Get()
    :
    : inArgs = wmiService.GetMethodParameters("MyMethod")
    : inArgs ("FilePath") = "C:MyDir"
    :
    : outArgs = wmiService.InvokeMethod("MyMethod", inArgs, Nothing)
    :
    : ======================================================
    :
    : my question is what do i have to do in my windows service project to make "Sub MyMethod(ByVal FilePath As String)" available to the outside world, so i can call it like i discribed above.
    :
    : ikkesjij.
    _______________________________________________________________________

    Hi,

    Not entirely sure on this one but are you trying to call a program method from a website page?

    You may need to look at at vbscript or another scripting language
    so as to implement your idea.

    Take a look at http://www.w3schools.com/ and take a look at all
    of the scripting languages on there.


    Regards,

    Dr M.

  • ikkesjijikkesjij Posts: 6Member
    Nope,
    i'm trying to call a 'Windows service' method from a console application.
    and the call itself is working fine on default methods like 'ChangeStartMode'. But when i implement a new Method 'MyMethod' to my 'windows Service' it seems impossible to call the method 'MyMethod'. :-(

    regards
  • DrMartenDrMarten Posts: 748Member
    [b][red]This message was edited by DrMarten at 2006-6-22 3:53:46[/red][/b][hr]
    Hi,

    In your console app have you tried putting the whole line within
    double quotation marks?

    Eg.

    "MyProgram arg1 arg2 arg3 arg4etc" ?

    Try also these forum sites>>
    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=25&SiteID=1

    http://forums.microsoft.com/MSDN/default.aspx?ForumGroupID=6&SiteID=1

    If you email to me your project as an entire zip file to>>
    [email protected] or to>

    [email protected] then i may be able to help you.
    Alternatively PASTE the entire project code here including any CLASS or MODULE that it uses.
    If it uses other additional files then ZIP the lot up please.

    Could you give a shorter plain example of a console app where trying to call another method doesn't work please?


    Regards,

    Dr M.

  • ikkesjijikkesjij Posts: 6Member
    Hi,

    i think i've got it.
    'Remoting' is the answer ;-)
    I can use remoting to let my console app interact with my service.

    thanks for your responses.
    till next time.

    cheers,
    ikkes.
  • jeffmanjeffman Posts: 112Member
    : maybe i was not clear about what i want to acomplish.
    :
    : I have created a windows service, that's running as a registred windows service.
    :
    : on the other hand, i have a windows forms application. i want this app to 'talk' with my service. so i can make some custom settings while the service is running. I think i can do this by invoking a method like this
    :
    : ======================================================
    :
    : Dim wmiService As System.Management.ManagementObject
    : Dim inArgs As System.Management.ManagementBaseObject
    : Dim outArgs As System.Management.ManagementBaseObject
    :
    : wmiService = New System.Management.ManagementObject("Win32_service.Name='MyService'")
    :
    : wmiService.Get()
    :
    : inArgs = wmiService.GetMethodParameters("MyMethod")
    : inArgs ("FilePath") = "C:MyDir"
    :
    : outArgs = wmiService.InvokeMethod("MyMethod", inArgs, Nothing)
    :
    : ======================================================
    :
    : my question is what do i have to do in my windows service project to make "Sub MyMethod(ByVal FilePath As String)" available to the outside world, so i can call it like i discribed above.
    :
    : ikkesjij.
    :
    you could use the sc config command to configure a service and sc create command to create a service for windows
    for more information on the switchs and options type /? after each command at the command prompt.
    sc config allows you to edit service properties(no programming but with your code and this your program can edit services) and options or settings(change to custom settings if you want) by changing them.
    Example: sc config NewService binpath= "ntsd -d c:windowssystem32NewServ.exe" (theres more you can edit too just look through windows help or type /? after the command at the command prompt.)
    theres also more commands besides the ones listed above that do more than the example i listed. these examples or hints are just to help save you programming time and effort and not waste as much code belive me you will want to use these commands after you look at the programming code on microsofts site it saves me half of the code you have (iam also using services code in my program).
    i was just wanting to help sorry about not explaining it more,
    jeffman
  • rlcrlc Posts: 448Member
    Yeah there are several ways you can do this within the .Net framework (and a host of other unmanaged and custom options), Remoting is very flexible option. You could consider using a web service for interoperability, but sounds like this is not a concern for you if both components are .net. There is also MSMQ.

    ~rlc
Sign In or Register to comment.