Question

Locked

Calling Script files from C programs

By cykeong ·
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?

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Example

by jcooper987 In reply to Calling Script files from ...

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();
}
}
}

Collapse -

Calling scripts using ShellExecute(Ex) or CreateProcess

by andrei.ciprian In reply to Calling Script files from ...

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);

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums