none
Start 16 Bit EXE from SQL Server CLR Stored Procedure (VB) RRS feed

  • Question

  • All I need to do is run an executable (pathEXE), no UI is necessary, from a CLR SP. (and just for giggles, the exe was compiled in 1989)

    pathEXE retrieves values in a text file, performs some calculations, then creates an output file.

     

    I have tried the following three methods:

    One:

     

    Dim ProcessID As Integer = Microsoft.VisualBasic.Interaction.Shell(pathEXE, AppWinStyle.NormalNoFocus, True, TimeOut)

     

     

    Two:

     

    Process.Start(pathEXE)
    ' and Process.Start(pathEXE, "userid")

     

     

    Three:

     

    Dim Prog As New Process()
    Prog.StartInfo.FileName = pathEXE
    Prog.Start()

     

     

    I have read 16Bit Interoperability: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/8c604b7d-0f88-49b8-8605-593e1d92b6eb/
    but it was no help

     

    Each method starts 'ntvdm.exe', but pathEXE does not create an output file. I know the CLR SP has permissions to create files because the input file is created by the CLR SP.

     

    Development Environment:

    SQL Server 2008 Standard Edition
    Visual Studio 2010 Team Edition (.net 3.5 Project)
    Windows XP SP3

     

    Thank you for your help.

    Wednesday, April 28, 2010 4:15 PM

Answers

  • a little more research yielded: 


    Dim pcs As New System.Diagnostics.Process

    pcs.StartInfo.FileName = pathEXE pcs.StartInfo.WorkingDirectory = OpsFile.getPath(pathEXE) pcs.Start() pcs.WaitForExit(TimeOut)

    The line i needed determined the working directory...

    I find it strange that the program did not create the output file when the working direcotry was not specified...

    thanks!

    • Marked as answer by Rogge Wednesday, April 28, 2010 5:46 PM
    Wednesday, April 28, 2010 5:46 PM

All replies

  • a little more research yielded: 


    Dim pcs As New System.Diagnostics.Process

    pcs.StartInfo.FileName = pathEXE pcs.StartInfo.WorkingDirectory = OpsFile.getPath(pathEXE) pcs.Start() pcs.WaitForExit(TimeOut)

    The line i needed determined the working directory...

    I find it strange that the program did not create the output file when the working direcotry was not specified...

    thanks!

    • Marked as answer by Rogge Wednesday, April 28, 2010 5:46 PM
    Wednesday, April 28, 2010 5:46 PM
  •  I am also having same problem, trying to call Web Browser through Process.Start("Iexplorer.exe",url), is anyone knows how to call exe from CLR proc?

    It returns error "Request Failed" when I call it through CLR Procedure.

    Thursday, August 5, 2010 9:59 PM
  • Shahzad:

    This is how I opened IE:

    1) set database Trusworty to True

    2) set project to permission level to unsafe

    3) Code:

    Option Compare Binary
    Option Explicit On
    Option Strict On
    Option Infer Off
    
    Imports System.IO
    
    Partial Public Class StoredProcedures
    
      <Microsoft.SqlServer.Server.SqlProcedure()> _
      Public Shared Sub RunEXE(ByVal pathEXE As String, ByVal TimeOut As Integer)
    
        Dim pcs As New System.Diagnostics.Process
    
        pcs.StartInfo.FileName = pathEXE
        pcs.StartInfo.WorkingDirectory = OpsFile.getPath(pathEXE)
        pcs.Start()
        pcs.WaitForExit(TimeOut)
    
      End Sub
    
    End Class
    
    Friend Module OpsFile
    
      Friend Function getPath(ByVal strFilePath As String) As String
        Return Left(strFilePath, strFilePath.LastIndexOf("\"))
      End Function
    
    End Module
    

    4) Execute:

    EXEC dbo.RunEXE 'C:\Program Files\Internet Explorer\iexplore.exe', 1000;
    

    hope this helps

    FYI I am still learning about trustworthy and permission levels.

    Friday, August 6, 2010 1:46 PM