all groups > dotnet interop > april 2004 >
You're in the

dotnet interop

group:

CreateProcess - Please help.



CreateProcess - Please help. provo1234 NO[at]SPAM hotmail.com
4/21/2004 4:32:14 PM
dotnet interop: Hi All,

Environment: Windows XP; Visual Studio .NET 2003 Edition

Problem: Calling CreateProcess Function from a Windows Service

Ultimate Aim: To print a pdf file using the command
AcroRd32.exe /t "c:\myfile.pdf" "\\PRINTERS\printer1" from a Windows
Service Program


I need to call the Win32 Function, CreateProcess, from a VB.NET
program using .NET Interoperabilty (PInvoke)

For more info about CreateProcess...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp

CreateProcess takes 10 parameters and I have no idea how to go about
it. I would be ever thankful to you if you can provide me with a code
snippet that can launch an executible using CreateProcess.

Thanks in advance
RE: CreateProcess - Please help. Sean Z
4/21/2004 4:46:06 PM
Re: CreateProcess - Please help. provo1234 NO[at]SPAM hotmail.com
4/22/2004 9:35:46 AM
Wow! It worked Jeff. You are my savior. I think I did some mistake in
setting the ProcessStartInfo attributes previously.

Thanks a million.

Re: CreateProcess - Please help. Jeff Gaines
4/22/2004 9:40:39 AM
On 21 Apr 2004 16:32:14 -0700, provo1234@hotmail.com (Shashi)
[quoted text, click to view]

Shashi

I use this to start an app from C#:

public void JStartProcess(string strCommand, string strWD)
{
ProcessStartInfo psi = new ProcessStartInfo();

// Initialize the ProcessStartInfo structure
psi.FileName = strCommand;
psi.Arguments = "";
psi.WorkingDirectory = strWD;

psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = false;
psi.UseShellExecute = false;
Process proc = new Process();
Process.Start(psi);
}

If you translated that to VB.NET would it work for you? It
avoids using the API.

You would need to pass in the parameters for psi.Arguments:

public void JStartProcess(string strCommand, string
strARguments, string strWD)

And call it so:

JStartProcess("AcroRd32.exe", @" /t c:\myfile.pdf
\\PRINTERS\printer1", strWD);

You would need to pass in the full path to the Acrobat Reader.

--
Jeff Gaines - Damerham Hampshire UK
AddThis Social Bookmark Button