Can't get process to execute

jonesin

Member
Joined
Jan 10, 2012
Messages
5
Programming Experience
1-3
Hi all,

OK, I truly give up. I've been toying with this on and off for a week now (work permitting). My service is almost working as expected. I posted a message on here a while back because I couldn't get shell to work. So, I searched as recommended to use a process. I did manage to find some docs which were good. Problem is, it still doesn't work :( I've hacked the living bits out of my code and still nothing.

FIrstly, I'm running the service as a 32-bit compile. Could that be why it's not working?

I copied the code exactly as below into a windows form and it worked fine on there. JUst not the service. I even put the process part within a Try block but that didn't capture anything....

Disregard the crap in the code. I did a lot of experimenting...

Any ideas? Below is a copy of my code.

Cheers,
J

VB.NET:
Dim con As New OleDb.OleDbConnection
            Dim dbProvider As String
            Dim dbSource As String
            Dim ds As New DataSet
            Dim da As OleDb.OleDbDataAdapter
            Dim sql As String
            Dim scenarioname As String
            Dim resultsname As String
            Dim time As DateTime = DateTime.Now
            Dim format As String = "dd-MM-yyyy HH-mm-ss"
            Dim rc As Integer
            Dim sMinutesString As String
            Dim minFormat As String = "HH:mm"
            Dim sDateString As String
            Dim dateFormat As String = "dd/MM/yyyy"
            Dim minutesArray() As String

            sMinutesString = time.ToString(minFormat)
            sDateString = time.ToString(dateFormat)
            minutesArray = sMinutesString.Split(CChar(":"))

            'Only execute the query if the last 2 digits (minutes) are either 00 or 30.
            If minutesArray(1) = "00" Or minutesArray(1) = "30" Then

                Dim TextFile2 As New StreamWriter("C:\LRQuadrant\" & "changethis" & ".log")

                dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
                dbSource = "Data Source = C:\LRQuadrant\test_schedule.mdb"

                con.ConnectionString = dbProvider & dbSource

                sql = "select scenario, resultsname from scheduled_tests where execdate = #" & sDateString & "# and exectime = #" & sMinutesString & "#"

                Try
                    da = New OleDb.OleDbDataAdapter(sql, con)
                    rc = da.Fill(ds, "MakeThisNameMeaningful")

                Catch ex As Exception

                    TextFile2.WriteLine(ex.Message)

                End Try

                'rc=0 means an emptydataset.  Not tests to run for that controller on the date specified.
                If rc > 0 Then

                    con.Open()

                    scenarioname = CStr(ds.Tables("MakeThisNameMeaningful").Rows(0).Item(0))
                    resultsname = CStr(ds.Tables("MakeThisNameMeaningful").Rows(0).Item(1))

                    con.Close()

                    Dim TextFile As New StreamWriter("C:\LRQuadrant\" & resultsname & ".vbs")

                    'Create the VBS file - won't work in .Net
                    TextFile.WriteLine("Set WshShell = WScript.CreateObject(""WScript.Shell"")")
                    TextFile.WriteLine("ScenFile = """ & scenarioname & """")
                    TextFile.WriteLine("Set LRE = WScript.CreateObject (""WLRun.LrEngine"")")
                    TextFile.WriteLine("WScript.Sleep 5000")
                    TextFile.WriteLine("if LRE.Scenario.IsOpened then")
                    TextFile.WriteLine("While LRE.Scenario.IsActive")
                    TextFile.WriteLine("Wscript.Sleep 10000")
                    TextFile.WriteLine("Wend")
                    TextFile.WriteLine("end if")
                    TextFile.WriteLine("LRE.Scenario.Open ScenFile, SAVE_CURRENT")
                    TextFile.WriteLine("DateString = Year(Date) &  Right(""0"" & Month(Date), 2) &  Right(""0"" & Day(Date), 2) &""_""& Right(""0"" & Hour(Now),2) & Right(""0"" & Minute(Now),2)")
                    TextFile.WriteLine("ResultDir =  ""C:\LRQuadrant\""")
                    TextFile.WriteLine("LRE.Scenario.ResultDir = ResultDir")
                    TextFile.WriteLine("If LRE.Scenario.Start = 0 Then")
                    TextFile.WriteLine("While LRE.Scenario.IsActive")
                    TextFile.WriteLine("Wscript.Sleep 10000")
                    TextFile.WriteLine("Wend")
                    TextFile.WriteLine("end if")
                    TextFile.WriteLine("if Not LRE.Scenario.IsResultsCollated then")
                    TextFile.WriteLine("LRE.Scenario.CollateResults")
                    TextFile.WriteLine("end if")
                    TextFile.WriteLine("while not LRE.Scenario.IsResultsCollated")
                    TextFile.WriteLine("Wscript.Sleep 10000")
                    TextFile.WriteLine("wend")
                    TextFile.WriteLine("LRE.CloseController()")
                    TextFile.Close()

                    Threading.Thread.Sleep(1000)

                     'IT IS DEFINITELY GETTING THIS FAR BECAUSE THE VBS SCRIPT DOES GET CREATED.

                    Try

                        'Launch the vbs file.
                        Dim foo As New System.Diagnostics.Process
                        foo.StartInfo.WorkingDirectory = "c:\"
                        foo.StartInfo.RedirectStandardOutput = True
                        foo.StartInfo.FileName = "cmd.exe"
                        foo.StartInfo.Arguments = "/c C:\LRQuadrant\" & "servicetest" & ".vbs"
                        foo.StartInfo.UseShellExecute = False
                        foo.StartInfo.CreateNoWindow = True
                        foo.Start()
                        foo.WaitForExit()
                        foo.Dispose()

                        'Shell("cmd /c C:\LRQuadrant\" & resultsname & ".vbs", vbHide)
                        'Threading.Thread.Sleep(70000)

                        'Delete the vbs file.
                        If System.IO.File.Exists("C:\LRQuadrant \" & resultsname & ".vbs") = True Then

                            System.IO.File.Delete("C:\LRQuadrant\" & resultsname & ".vbs")

                        End If

                    Catch ex As Exception

                        TextFile2.WriteLine(ex.Message)

                    End Try
                End If
            End If
 
Back
Top