Hi all,

In a program I've been working on I would like to start a process and save it in a variable of type Process. This is so I can kill it later, if needed, and change the window type.

The process is an Excel document.

Here is some relevant code:

#Region "API Code"

    Private Declare Function ShowWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nCmdShow As SHOW_WINDOW) As Boolean

    <Flags()> _
    Private Enum SHOW_WINDOW As Integer
        SW_HIDE = 0
        SW_SHOWNORMAL = 1
        SW_NORMAL = 1
        SW_MAXIMIZE = 3
        SW_SHOW = 5
        SW_MINIMIZE = 6
        SW_SHOWNA = 8
        SW_RESTORE = 9
        SW_SHOWDEFAULT = 10
        SW_MAX = 11
    End Enum

#End Region

Private Sub DailyUpdate()

    ' Some code

    Dim dataFile As New ProcessStartInfo(My.Settings.dataDocument)
    Dim dataProc As Process = Process.Start(dataFile)
    ShowWindow(dataProc.MainWindowHandle, SHOW_WINDOW.SW_MINIMIZE)

    ' Some code

End Sub

For some reason, simply using

dataFile.dataFile.WindowStyle = ProcessWindowStyle.Minimized

doesn't work. The Excel document still launches maximized. The API code was taken from here: http://www.vbforums.com/showthread.php?t=650553. I don't know anything about API.

When I launch the program, I receive a NullReferenceException on the dataProc object. It doesn't seem to matter what I do, I can't get rid of this error.

Any help would be greatly appreciated.

Recommended Answers

All 2 Replies

It's also worth mentioning that I'd ideally like to hide the window from view. This has turned out to be difficult to accomplish on previous attempts but perhaps the API code that I found would help?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.