How to use different "shell" with Shell() in

Posted on 2005-05-03
Last Modified: 2008-01-09
I am working on a program that needs to call a 3rd party shell from my VB.NET code.  I have been trying to use the Shell() function but apparently the 3rd party shell I need to use doesn't work correctly when I call it from the default shell.  Is there a way in VB.NET I can either see the code for the built-in Shell() function so I can re-write it to use my other shell or call this other shell directly?

Here's what I'm trying to do, I am working on a program to work with CA Autosys 4.5 (a job scheduler) which creates jobs in Autosys when certain things happen.  I am doing this by creating a temporary file containing JIL script (the scripting language used by Autosys) with my VB.NET code.  Then I need to be able to do the command "jil.exe < tempfile.jil" from within the Autosys shell, which is called "initautosys.exe"  If I call the Autosys shell from Shell("initautosys.exe -i ACE -r jil.exe < tempfile.jil"), it works up to "initautosys.exe -i ACE -r jil.exe" but never gets the "< tempfile.jil".  CA tells me that I have to call initautosys.exe directly and not from the default shell.

So does anyone know a good way to handle this?  I could either write my own shell function (like maybe CAshell()) if I had a way to see how the regular Shell() function is written, or I could see if there was a way to run the Autosys shell directly.  Any idea???
Question by:MHC_bcraigh
    LVL 50

    Assisted Solution

    by:Julian Hansen
    Can you not use the Windows CreateProcess API to do this?
    LVL 23

    Assisted Solution

    See if it doesn't work putting a ^ in front of the <, to wit:
    Shell("initautosys.exe -i ACE -r jil.exe ^< tempfile.jil"
    LVL 23

    Assisted Solution

    The pipe and redirect characters are intercepted and processed  by the shell.  The ^ is the shell escape character that tells the shell to ignore any special meaning the following character may have.

    LVL 1

    Assisted Solution

    Hey  MHC_bcraigh

    Try putting the command ("initautosys.exe -i ACE -r jil.exe < tempfile.jil")
    in a batch file and executing it with the Shell...


    LVL 96

    Accepted Solution

    Shell in VB.NET:

    <SecurityPermission(SecurityAction.Demand, UnmanagedCode:=True)> _
    Public Shared Function Shell(ByVal Pathname As String, ByVal Optional Style As AppWinStyle = 2, ByVal Optional Wait As Boolean = False, ByVal Optional Timeout As Integer = -1) As Integer
          Dim num2 As Integer
          Dim startupinfo1 As New STARTUPINFO
          Dim process_information1 As New PROCESS_INFORMATION
                New UIPermission(UIPermissionWindow.AllWindows).Demand
          Catch exception1 As  Exception
                Throw exception1
          End Try
          If ((Style < AppWinStyle.Hide) OrElse (Style > CType(9, AppWinStyle))) Then
                Throw New ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", "Style"))
          End If
          startupinfo1.dwFlags = 1
          startupinfo1.wShowWindow = CType(Style, Short)
          Dim text2 As String = Nothing
          Dim text1 As String = Nothing
          Dim num1 As Integer = NativeMethods.CreateProcess(text2, Pathname, Nothing, Nothing, False, 32, IntPtr.Zero, text1, startupinfo1, process_information1)
          If (num1 = 0) Then
                Throw ExceptionUtils.VbMakeException(53)
          End If
          If Wait Then
                num1 = NativeMethods.WaitForSingleObject(process_information1.hProcess, Timeout)
                If (num1 = 0) Then
                      num2 = 0
                      num2 = process_information1.dwProcessId
                End If
                NativeMethods.WaitForInputIdle(process_information1.hProcess, 10000)
                num2 = process_information1.dwProcessId
          End If
          Return num2
    End Function


    Author Comment

    Thanks for all of your suggestions.  I tried each and every one of them.  But after doing a great deal of research and re-programming, I've determined through Computer Associates Support ( and two other sources ) that the "initautosys" does not have the functionality to handle an interactive shell.  So even though I tried using the "^" to escape the "<" and many other things, this problem is due to Computer Associates not providing the functionality that common sense would tell you that is needed.  We paid A LOT of money for this system and were told that it would allow us to do anything we wanted to do with custom scripts and programs.  We can't.

    I liked the suggestion to create a process like:

                Dim oCmd As New Process
                Dim ascmd As String = "C:\Progra~1\CA\UnicenterAutoSysJM.ACE\autosys\bin\initautosys.exe"
                Dim jilstr As String = "-i ACE -r " & """" & "C:\Progra~1\CA\UnicenterAutoSysJM.ACE\autosys\bin\jil.exe < " & mytempfile & """"

                oCmd.StartInfo.WorkingDirectory = workingdir
                oCmd.StartInfo.UseShellExecute = False  'used for debugging purposes
                oCmd.StartInfo.FileName = ascmd
                oCmd.StartInfo.Arguments = jilstr
                oCmd.EnterDebugMode()     'used for debugging purposes

    but I got the same result as using Shell().

    I'm going to abandon this idea since there doesn't appear to be a way around the limitations of Autosys without re-writing Autosys.  I am going to create all of my jobs in Autosys to be permanent jobs for now so I can at least get something working, then I will re-visit this at a later time and just write something to do what I thought Autosys should have been able to do.  Maybe we can sell the solution to other Autosys shops!?!?!  kidding.......

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    has22 challenge 11 56
    Replace a tag with sed 2 32
    How to split this in C++ 4 52
    Path of Workbook 3 30
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now