Smalls 2 Junior Developer

k, what i'm trying to do is create a windows service to run in the background to monitor vmplayer.exe to see if it is running or not. then if it is running, then turn on the various hardware, software, and services it needs/uses to run, and if it is not running, then to turn these things back off.

this seems to be the only hump that i can't get over is getting this service to watch for this item and adjust the system accordingly

the reason for doing so is that from the time that the PC is booted, 4 processes and 4 services are always running along with 2 hardware bits that are install by vmware that give vmware os's internet


i'm trying to call an exe file called devcon.exe which is a file supplied by MS that provides a command line alternative to the device manager, i am trying to use it to enable and disable these 2 bits of hardware

i am also using 2 batch files that use to the 'net start' and 'net stop' to start and stop the 4 services

if anyone could help it would be greatly appreciated
along with suggestions on how to make this a little bit shorter


i haven't been able to get this to work
i've uploaded the files that i'm using
but, this is what i've got and i'm pretty sure that this is all that i need
i've got it to install and run, but thats about it

Imports System.IO
Imports System.Diagnostics


Public Class Service1
    Dim vmnet1 As Process
    Dim vmnet8 As Process
    Dim vmserv As Process
    

    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        Timer1.Enabled = True
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
    End Sub

    Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Dim processes() As Process
        Dim instance As Process
        Dim process As New Process()
        processes = process.GetProcesses
        For Each instance In processes
            If instance.ProcessName = "vmplayer" = True Then
                vmnet1.StartInfo.FileName = "devcon.exe"
                vmnet1.StartInfo.Arguments = "enable *VMnetAdapter1"
                vmnet1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                vmnet1.Start()

                vmnet8.StartInfo.FileName = "devcon.exe"
                vmnet8.StartInfo.Arguments = "enable *VMnetAdapter8"
                vmnet8.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                vmnet8.Start()

                vmserv.StartInfo.FileName = "C:\VMServStart.bat"
                vmserv.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                vmserv.Start()
            End If
        Next
        For Each instance In processes
            If instance.ProcessName = "vmplayer" = False Then
                vmnet1.StartInfo.FileName = "devcon.exe"
                vmnet1.StartInfo.Arguments = "disable *VMnetAdapter1"
                vmnet1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                vmnet1.Start()

                vmnet8.StartInfo.FileName = "devcon.exe"
                vmnet8.StartInfo.Arguments = "disable *VMnetAdapter8"
                vmnet8.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                vmnet8.Start()

                vmserv.StartInfo.FileName = "C:\VMServStop.bat"
                vmserv.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                vmserv.Start()
            End If
        Next
    End Sub
End Class

that you for taking the time to look over
,Smalls

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.