Results 1 to 14 of 14

Thread: Can i make a batch file started from within a windows service visible

  1. #1
    blob is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    6
    Reputation
    0

    Can i make a batch file started from within a windows service visible

    Hi,
    Having trouble with this - how can i execute a batch file from a windows service but have execution and results visible on the console during execution?

    Currently i'm executing the batch file via:


    Dim pStart As New System.Diagnostics.Process Dim startInfo As New System.Diagnostics.ProcessStartInfo(strSourceFolder & strFileName) 'startInfo.RedirectStandardOutput = True startInfo.WindowStyle = ProcessWindowStyle.Normal startInfo.UseShellExecute = False pStart.StartInfo.CreateNoWindow = False pStart = System.Diagnostics.Process.Start(startInfo) pStart.WaitForExit() pStart.Close()

    thanks!

  2. #2
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1212
    Since Windows Vista the property you needed to set prior to make the service interactive is not exposed anymore. You can still set your service as interactive, but you have to hack your way through. There is a registry key for your service there:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\<YOUR SERVICE NAME>\Type

    'Type' is a bitfield. You need to read the value of the key, do an 'OR &H100', and stick it back in registry.
    Last edited by Herman; 05-11-2012 at 1:52 AM.

  3. #3
    blob is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    6
    Reputation
    0
    Thanks Mr Herman - good info.
    Just a question.. the regedit value of type is hexidecimal and 10

    didn't quite get what i should set this to?
    100?


    Quote Originally Posted by Herman View Post
    Since Windows Vista the property you needed to set prior to make the service interactive is not exposed anymore. You can still set your service as interactive, but you have to hack your way through. There is a registry key for your service there:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\<YOUR SERVICE NAME>\Type

    'Type' is a bitfield. You need to read the value of the key, do an 'OR &H100', and stick it back in registry.

  4. #4
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1212
    You take the value, and OR it with hexadecimal 100 (256 decimal). That is a bitwise addition.

    NewValue = CurrentValue OR &H100

  5. #5
    blob is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    6
    Reputation
    0
    i must be lost on this - i've change the value via regedit to hex 100..

    and no difference.

    why take the value?
    you mean read it from within the service?



    Quote Originally Posted by Herman View Post
    You take the value, and OR it with hexadecimal 100 (256 decimal). That is a bitwise addition.

    NewValue = CurrentValue OR &H100

  6. #6
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1212
    I think you need a primer on binary maths and bitfields.

  7. #7
    blob is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    6
    Reputation
    0
    Right you are - a while since i studied this.

    However i still don't get what you mean.. can i not just merely change the registry value via regedit and it work?



    Quote Originally Posted by Herman View Post
    I think you need a primer on binary maths and bitfields.

  8. #8
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1212
    The method is irrelevant, you just need to understand what ORing the two numbers does.

  9. #9
    blob is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    6
    Reputation
    0
    i still don't get it.. i'm not really interested in learning about ORing particularly.. or binary.
    I just want to know how to make a process being called from a service display its execution onscreen.

    If you're saying that i can change the value of the registry entry - great! how do i do that.




    Quote Originally Posted by Herman View Post
    The method is irrelevant, you just need to understand what ORing the two numbers does.

  10. #10
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1212
    i'm not really interested in learning about ORing particularly.. or binary.
    Well then I'm not really interested in helping you more. Besides you already have all the answers, if you won't bother actually learning what you are missing there is nothing more I can do for you.

  11. #11
    blob is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    May 2012
    Posts
    6
    Reputation
    0
    Well thankyou anyway.. i'm sorry but i still failed to see how the link you sent me was relevant.. or to be used in vb.net terms for a service to display a batch file to screen.
    my first venture into vbdotnetforums has been unsuccessful

    heres another link which i liked

    Good Answer - Wikipedia, the free encyclopedia





    Quote Originally Posted by Herman View Post
    Well then I'm not really interested in helping you more. Besides you already have all the answers, if you won't bother actually learning what you are missing there is nothing more I can do for you.

  12. #12
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    15,083
    Reputation
    2803
    Hermans replies are very straight forward if you know bitwise operations. After you now have corrupted registry you should uninstall the service and reinstall it. As a general advice, don't make manual changes in registry unless you know what you're doing, it can seriously damage your computer configuration.

    In Vista and earlier you can after service is installed go to Services management in control panel and in the service logon properties select Local System account and checkbox 'allow service to interact with desktop'.
    How to format posts with code blocks etc - present the problem/post properly

    Visual Studio Community 2017

  13. #13
    Paszt's Avatar
    Paszt is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Jun 2004
    Location
    Raleigh, NC - USA
    Posts
    1,500
    Reputation
    354
    Quote Originally Posted by blob View Post
    If you're saying that i can change the value of the registry entry - great! how do i do that.
    Quote Originally Posted by blob View Post
    i must be lost on this - i've change the value via regedit to hex 100..
    and no difference.
    why take the value?
    you mean read it from within the service?
    Love the drama!

    I think what is missing here is perhaps blob doesn't know the code to read and modify the registry. From the questions posed it appears he didn't know the service was to actually read and modify the registry.

    Yes blob, the service should modify the registry by reading it, doing a bitwise operation, and writing it back to the registry.
    Here's some links that should help:
    Registry Class (Microsoft.Win32)
    RegistryKey Class (Microsoft.Win32)
    - Stephen Paszt

  14. #14
    Herman is offline VB.NET Forum Idol
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2011
    Location
    Montreal, QC, CA
    Posts
    866
    Reputation
    1212
    In reality you only have to do the operation once, after the service is installed. This is the kind of thing that would go in a deployment project for your project.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •