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

blob

Member
Joined
May 10, 2012
Messages
6
Programming Experience
10+
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!
 
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\Services\<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:
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?


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\Services\<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.
 
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?



You take the value, and OR it with hexadecimal 100 (256 decimal). That is a bitwise addition.

NewValue = CurrentValue OR &H100
 
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.




The method is irrelevant, you just need to understand what ORing the two numbers does.
 
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.
 
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





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.
 
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'.
 
If you're saying that i can change the value of the registry entry - great! how do i do that.

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)
 
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.
 
Back
Top