TheWizardofInt Posted August 25, 2004 Posted August 25, 2004 I need to print Word Documents and MS Projects, without showing them. These are standard templates that just need to be printed and mailed to clients Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal _ hwnd As IntPtr, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Integer) As Integer Public Function PrintFromShell(ByVal sFile As String) As Integer 'use the shell command to print Dim NewProcess As Process = New Process Dim hHandle As System.IntPtr Dim i As Integer Dim proc As Process proc.GetProcesses(Environment.MachineName) For Each proc In proc.GetProcesses If proc.ProcessName = Application.ProductName Then hHandle = proc.Handle Exit For End If Next i = ShellExecute(hHandle, "print", _ sFile, vbNullString, sGlobTemplates, 0) Return i End Function This words, but it shows the document as it prints it. I tried setting constant SW_Hide=0 but of course got the same result Any idea what the new SW_Hide value in .Net should be? Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Administrators PlausiblyDamp Posted August 25, 2004 Administrators Posted August 25, 2004 If you are using .Net why don't you use the System.Diagnostics.Process class? It will be much easier than calling into ShellExecute. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
TheWizardofInt Posted August 25, 2004 Author Posted August 25, 2004 If you are using .Net why don't you use the System.Diagnostics.Process class? It will be much easier than calling into ShellExecute. It wouldn't print at all I am assuming process(sFile, "Print") - probably got that wrong Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Administrators PlausiblyDamp Posted August 25, 2004 Administrators Posted August 25, 2004 Dim pi As New System.Diagnostics.ProcessStartInfo pi.Verb = "Print" pi.FileName = "c:\autoexec.bat" Dim p As New System.Diagnostics.Process p.StartInfo = pi pi.WindowStyle = ProcessWindowStyle.Hidden p.Start() Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts