954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Trouble storing Process objects in variables

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_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.

Eruditio
Newbie Poster
5 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

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?

Eruditio
Newbie Poster
5 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

i dont realy fully uderstand what you are doing.but i think that you are starting an excel file not excel program and passing all the properties to the file not the program.
http://www.daniweb.com/software-development/vbnet/threads/382886

anas alrawi
Newbie Poster
4 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: