Results 1 to 6 of 6

Thread: Process.Start question

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2011
    Location
    Greenville, SC
    Posts
    40

    Unhappy 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

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    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?

  3. #3
    Junior Member azuckerman's Avatar
    Join Date
    Sep 2011
    Location
    Texas, USA
    Posts
    29

    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
    I don't always feel like blogging, but when I do http://justsomevbcode.blogspot.com/

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2011
    Location
    Greenville, SC
    Posts
    40

    Re: Process.Start question

    I"m afraid there was no difference. Still have the same result. Any other possibility?

  5. #5
    Junior Member azuckerman's Avatar
    Join Date
    Sep 2011
    Location
    Texas, USA
    Posts
    29

    Re: Process.Start question

    Quote Originally Posted by Bwilliamson View Post
    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
    I don't always feel like blogging, but when I do http://justsomevbcode.blogspot.com/

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    Code:
    uncLocation3
    then your working directory needs to be:
    Code:
    IO.Path.GetDirectoryName(uncLocation3)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width