Question Locked

Calling Script files from C programs

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Hi, I have difficulty to calling script files from a C program. I have a script file like Testing.com , I want call this script files from C program. Can anybody show me some examples?

3 replies

by jcooper987

using System;
using System.Collections.Generic;
using System.Text;

namespace test
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = @"C:\test22.bat";
proc.StartInfo.Arguments = "";
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
}
}
}

by andrei.ciprian

You could use any of these calls:
1. ShellExecute
2. ShellExecuteEx
3. CreateProcess

Only ShellExecute does not return a process handle.

Here's an exemple with ShellExecuteEx:

SHELLEXECUTEINFO shexinf;
shexinf.cbSize = sizeof (SHELLEXECUTEINFO);
shexinf.hwnd = 0;
shexinf.lpVerb = _T("open");
shexinf.lpFile = GetScriptPath();
shexinf.lpParameters = GetScriptAdditionalArguments();
shexinf.lpDirectory = 0;
shexinf.nShow = SW_HIDE;
shexinf.fMask = SEE_MASK_NOCLOSEPROCESS;
shexinf.hInstApp = 0;

if (! ShellExecuteEx (&shexinf))
{
// handle error
// use shexinf.hInstApp
}

if (shexinf.hProcess)
WaitForSingleObject (shexinf.hProcess, INFINITE);

This discussion is closed to new replies.