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_SHOWMINIMIZED = 2 SW_SHOWMAXIMIZED = 3 SW_MAXIMIZE = 3 SW_SHOWNOACTIVATE = 4 SW_SHOW = 5 SW_MINIMIZE = 6 SW_SHOWMINNOACTIVE = 7 SW_SHOWNA = 8 SW_RESTORE = 9 SW_SHOWDEFAULT = 10 SW_FORCEMINIMIZE = 11 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.