WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: DirkM on September 28, 2015, 02:16:13 PM

Title: Ole help with ProcessWindowStyle.Minimized
Post by: DirkM on September 28, 2015, 02:16:13 PM
Hello everybody,

I'm trying to execute a command but need to do something while it's running. I got my code working with the exception of hiding the CMD window while the exe is running. I found that objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized should do the trick but in WinBatch I get the following error: 3246: Ole Object: Object does not exist, or period used instead of comma.

Does anybody have an idea what I am missing?

Thanks,
Dirk

ObjectClrOption("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
objProcess   = ObjectClrNew("System.Diagnostics.Process")
objProcess.StartInfo.UseShellExecute = ObjectType("BOOL", 1)
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
objProcess.StartInfo.FileName = 'Notepad'
objProcess.StartInfo.Arguments = 'test.txt'
objProcess.Start()
objProcess.WaitForExit()
objProcess.Dispose()
Message ('','done')
Title: Re: Ole help with ProcessWindowStyle.Minimized
Post by: td on September 28, 2015, 02:35:56 PM
There are numerous simpler ways to do this but to keep the task strictly within CLR hosting, you need the following:
Code (winbatch) Select
; Enumerations need to be instantiated.
ObjectClrOption("use","System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
enumProcStyles = ObjectClrNew( 'System.Diagnostics.ProcessWindowStyle' )

objProcess   = ObjectClrNew("System.Diagnostics.Process")
objProcess.StartInfo.UseShellExecute = ObjectType("BOOL", 1)

; Property typing is strictly enforced on StartInfo's WindowStyle property
; so you need to perform a type cast.
objProcess.StartInfo.WindowStyle = ObjectClrType('System.Diagnostics.ProcessWindowStyle', enumProcStyles.Minimized)
objProcess.StartInfo.FileName = 'Notepad'
objProcess.StartInfo.Arguments = 'test.txt'
objProcess.Start()
objProcess.WaitForExit()
objProcess.Dispose()
Message ('','done')

Title: Re: Ole help with ProcessWindowStyle.Minimized
Post by: DirkM on September 29, 2015, 04:21:56 PM
Perfect, thanks a lot, work like a charm.