Visual Basic 6 applications are not meant to run as a service. There are a lot of blog posts out there on how to wrap a VB6 application in something to allow it to run as a service, etc. but I had to CALL VB6 from a .NET Windows Service application.

I’ve seen articles and posts regarding running Visual Basic Script (VBS) or batch files, but nothing that would work for me running VB6….

In my case, I had to use a service because the service checks certain conditions, and based on those conditions spawns legacy VB6 applications. However, you might have success using this method to call a VB6 application and have it mimic a service by being CALLED by one. However, remember that the application will run in the context of the user. I’ve not had any success trying to run the user with elevated privileges, so the context of the service must already have the required privileges you need (namely accessing files and directories). My particular service runs under a system account with minimal privileges.

Note I did not include code for the Task object. However, you can see it simply supplies a location of the file (full path-name) to be executed and command line arguments. That’s it.

I have run this with a VB6 application with a visible form. Of course that form doesn’t appear. However, if you have any modal dialog boxes that stop the application awaiting user input, you’re in for a tough time. You cannot have any direct user interaction through a graphical user interface.

Good luck!

 

Like this post? Share it!