On a remote server, I've got a batch file that executes a Java app. Currently, I'm triggering the batch file with a scheduled task. I'd also like to be able to trigger the batch file or the Java app at will from a Windows app. Unfortunately, I can't seem to get it to work and I'm not entirely sure how to find out what's not working.
The java app is normally triggered by running a batch file(myapp_gt.bat) from a command prompt. The batch file simply contains this:
When it runs, there's some mostly useless output to the command line. If there are files to download I think it ends with something like "X new files received". If nothing is downloaded, it ends with "No new files received"
I decided to bypass the batch file part and just remotely execute the Java app. I can see the Java process start and end on the server, but it seems like it ends too quickly and I don't see any evidence that the Java app did what it was supposed to do (i.e. download some XML files if they're present).
This is what I have so far:
Added reference to System.Management
Can anyone tell me what I'm doing wrong, how to tell what's not working, or some alternate way to run the java app remotely (without using a third-party utility like PSExec). Also, I need some way to determine when this process has ended so that I can make sure that the rest of my code executes only after the Java app has finished.
The java app is normally triggered by running a batch file(myapp_gt.bat) from a command prompt. The batch file simply contains this:
Code:
@echo off
.\jre6\bin\java -jar myapp.jar gt
I decided to bypass the batch file part and just remotely execute the Java app. I can see the Java process start and end on the server, but it seems like it ends too quickly and I don't see any evidence that the Java app did what it was supposed to do (i.e. download some XML files if they're present).
This is what I have so far:
Added reference to System.Management
Code:
CreateProcess("myserver", """c:\Program Files (x86)\myfolder\jre6\bin\java.exe"" -jar ""c:\Program Files (x86)\myfolder\myapp.jar"" gt", "mydomain\myusername>", "mypassword")
Code:
Private Sub CreateProcess(ByVal strComputer As String, ByVal strProcess As String, ByVal UserName As String, ByVal Password As String)
Dim processBatch As ManagementClass = New ManagementClass("Win32_Process")
Dim inParams As ManagementBaseObject = processBatch.GetMethodParameters("Create")
Dim msc As ManagementScope
inParams("CurrentDirectory") = Nothing
inParams("CommandLine") = strProcess
Dim co As ConnectionOptions = New ConnectionOptions()
co.Username = UserName
co.Password = Password
Try
If (strComputer = System.Environment.MachineName) Then
msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2")
Else
msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
End If
msc.Connect()
processBatch.Scope = msc
Dim outParamas As ManagementBaseObject = Nothing
outParamas = processBatch.InvokeMethod("Create", inParams, Nothing)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Can anyone tell me what I'm doing wrong, how to tell what's not working, or some alternate way to run the java app remotely (without using a third-party utility like PSExec). Also, I need some way to determine when this process has ended so that I can make sure that the rest of my code executes only after the Java app has finished.