|
-
Sep 21st, 2011, 02:06 PM
#1
Thread Starter
Member
Process.Start question
Hello,
I have a program that when you press a button it maps 2 drives, updates a registry value and then starts a executable which is stored in a SQL table. I'm having issues after the file opens. The program it opens does not seem to be working quite right. When you open the program by clicking on the .exe it works file. When I call it from the app, I have issues with the program after it opens. Can someone explain to me the difference between double clicking an .exe and using process.start? Is there a different way to do it? My code is listed below.
Code:
Imports System.Data.SqlClient
Imports System.Console
Imports System.Configuration
Imports System.Data
Imports System.IO.Directory
Imports System.Diagnostics
Imports Microsoft.Win32
Public Class Main
Private Sub butPds_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butPds.Click
Dim objNetwork
Dim cmbValue As String
Dim SQLConn As New SqlConnection() 'The SQL Connection
Dim SQLCmd As New SqlCommand() 'The SQL Command
Dim strSQL As String
cmbValue = cmbProjectSel.Text
'Dim ConnString As New SqlConnection
SQLConn.ConnectionString = "Server=GRN2007;Database=VB_Projects;Trusted_Connection=True" 'Set the Connection String
strSQL = "SELECT PDS_Location,LS_Location, pd_configure, PDS_exe FROM vw_PDS_SPR_Locations WHERE project =" & "'" & cmbValue & "'"
Dim myCommand As New SqlCommand(strSQL, SQLConn)
SQLConn.Open() 'Open the connection
Dim myReader As SqlDataReader
Dim uncLocation As String = ""
Dim uncLocation1 As String = ""
Dim uncLocation2 As String = ""
Dim uncLocation3 As String = ""
Dim strDriveLetter1 As String
Dim strDriveLetter2 As String
myReader = myCommand.ExecuteReader()
While myReader.Read()
uncLocation = myReader(0).ToString()
uncLocation1 = myReader(1).ToString()
uncLocation2 = myReader(2).ToString()
uncLocation3 = myReader(3).ToString()
End While
objNetwork = CreateObject("WScript.Network")
'Section which unmaps the drives,
Try
objNetwork.RemoveNetworkDrive("F:", True, True)
objNetwork.RemoveNetworkDrive("G:", True, True)
Catch ex As Exception
End Try
strDriveLetter1 = "F:"
strDriveLetter2 = "G:"
' Section which maps the drives,
Try
objNetwork.MapNetworkDrive(strDriveLetter1, uncLocation, True)
objNetwork.MapNetworkDrive(strDriveLetter2, uncLocation1, True)
Catch ex As Exception
Try
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\Software\Intergraph\PD_SHELL\07.00\", "ControlFile", uncLocation2)
Catch ex As Exception
End Try
myReader.Close()
SQLConn.Close()
Dim startInfo As New ProcessStartInfo(uncLocation3)
startInfo.WindowStyle = ProcessWindowStyle.Hidden
startInfo.UseShellExecute = False
startInfo.WorkingDirectory = "C:\win32app\ingr\pdshell\bin\"
Process.Start(uncLocation3)
'Me.Close()
End Sub
-
Sep 21st, 2011, 04:14 PM
#2
Re: Process.Start question
There should not be a difference between the two methods. Are there problems if you do not set the Window state and leave it as normal?
-
Sep 21st, 2011, 06:00 PM
#3
Junior Member
Re: Process.Start question
Change this line to True and there will be no difference:
Code:
startInfo.UseShellExecute = False
Here's more info:
ProcessStartInfo.UseShellExecute Property
-
Sep 22nd, 2011, 12:28 PM
#4
Thread Starter
Member
Re: Process.Start question
I"m afraid there was no difference. Still have the same result. Any other possibility?
-
Sep 22nd, 2011, 12:49 PM
#5
Junior Member
Re: Process.Start question
 Originally Posted by Bwilliamson
I"m afraid there was no difference. Still have the same result. Any other possibility?
Here is exactly what I do:
Code:
Try
' sReportPathName is a path to an HTML file containing a report
Dim oProcess As New ProcessStartInfo(sReportPathName)
With oProcess
.ErrorDialog = True
.ErrorDialogParentHandle = Me.Handle
.WorkingDirectory = MainCode.ReportPath
.UseShellExecute = True
End With
Process.Start(oProcess)
Catch ex As Exception
' Log my exception here
End Try
-
Sep 23rd, 2011, 12:51 AM
#6
Re: Process.Start question
If you're starting an EXE then I would guess that the issue is related to the working directory, which is the most common culprit. The working directory usually needs to be the directory containing the EXE. In that case, if your file path is:then your working directory needs to be:
Code:
IO.Path.GetDirectoryName(uncLocation3)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|