Script to execute a bat file

  • 797 Views
  • Last Post 10 March 2017
millje posted this 07 April 2014

Does anyone have script that will work to execute a .bat file? I have been trying everything I can find and nothing will execute my bat file. My bat file works fine when I run it just not in a script in Incontrol.

Order By: Standard | Newest | Votes
monkey-magic posted this 07 April 2014

I can't help but we have been trying to get this voted up and worked on:

http://incontrolha.uservoice.com/forums/218427-general/suggestions/5390053-add-actions-to-incontrol-http-get-post-run-file

It would allow the running of batch files.

It's the one thing I'm waiting on is more control like this and especially the HTTP post/get that will allow a lot more functionality with inControl.

Things seem to be quietening off here.

Josh

MikeD99 posted this 08 April 2014

I have a .cs file that runs a .bat file correctly. I would be glad to share it with you but don't know how to. Is there a way you could send me an email?

Mike D.

millje posted this 08 April 2014

Mike I sent you a Private Message with my email. Thanks.

Ralf posted this 09 April 2014

Hi guys, perhaps you could just cut and paste the relevant lines of code here on this forum? If possible, that would be much appreciated.

Cheers.

Ralf posted this 09 April 2014

I should add, I'm trying to get this working too but not having much luck. I followed the instructions in this thread: http://store.incontrolzwave.com/boards/topic/27/run-autoit-script-or-batch-file-with-a-scene/page/2

I have verified that the code in that thread works but NOT for launching an exe. This is what I'm trying to do.

monkey-magic posted this 09 April 2014

http://incontrolha.uservoice.com/forums/218427-general/suggestions/5390053-add-actions-to-incontrol-http-get-post-run-file

Well it looks like it is in the planning stages so this might make it easier.

Josh

MikeD99 posted this 09 April 2014

Script to execute an .exe file with passed params:

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class Runbat : ScriptBase, ScriptInterface {
public void runScript() {
try {
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.Arguments = "Record Porch";
psi.FileName = @"C:\House\hs.exe";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
}
}
}

MikeD99 posted this 09 April 2014

Script to record a file from a Foscam camera and then run a .bat file with passed params:

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;
using System.Diagnostics;
using MLS.HA.DeviceController.Common.Device;

public class Max80 : ScriptBase, ScriptInterface {

///


/// This script finds any node that is above 80% and sets it to 80%.
///
/// ALWAYS MAKE COPIES OF SCRIPTS YOU INTEND TO CUSTOMIZE OR YOUR CHANGES
/// COULD BE LOST.
///

public void runScript() {
var vidfileName = "";

// How long the recording should go
var recordTimeSeconds = 120;

try {

// *****************
// * Change these to fit your system ****
var vlcPath = @"C:\program files (x86)\VideoLan\VLC\vlc.exe";

// This is where the video will be saved. Be sure it has a trailing slash at the end ()
var videoOutputPath = @"C:\House\PorchVideos\thisWeek\";

// This is the camera's short id (double click a device inside InControl to find this id)
var deviceShortId = 30;

//
*****************
//
******************

var device = getNodeByShortId(deviceShortId) as CameraDevice;

if (device != null) {

vidfileName = string.Format("{0}.asf", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss"));
var asfUrl = string.Format("http://{0}/videostream.asf?user={1}&pwd={2}", device.ip, device.userName, device.password);

var psi = new ProcessStartInfo();
psi.FileName = vlcPath;

//var args = string.Format("{0} --qt-start-minimized --no-qt-notification --run-time=15 :demux=dump :demuxdump-file={1}{2} vlc://quit", device.providerDeviceId, videoOutputPath, fileName);
//var args = string.Format("\"{0}\" --run-time={3} :demux=dump :demuxdump-file=\"{1}{2}\"", asfUrl, videoOutputPath, vidfileName, recordTimeSeconds);
//var args = string.Format("-I dummy --dummy-quiet \"{0}\" --run-time={3} --sout=#transcode{{vcodec=h264,vb=1024,acodec=mp3,ab=128,channels=2,samplerate=44100}}:std{{access=file,mux=avi,dst=\"{1}{2}\"}} vlc://quit", asfUrl, videoOutputPath, vidfileName, recordTimeSeconds);
//var args = string.Format("\"{0}\" --qt-start-minimized --no-qt-notification --run-time={3} :sout=#duplicate{{dst=file{{dst=Y:\\SecurityVids\\test.asf}},dst=display}} :sout-keep vlc://quit", asfUrl, videoOutputPath, vidfileName, recordTimeSeconds);
var args = string.Format("\"{0}\" --qt-start-minimized --no-qt-notification --run-time={3} :sout=#duplicate{{dst=file{{dst={1}{2}}}}} vlc://quit", asfUrl, videoOutputPath, vidfileName, recordTimeSeconds);

writeFileLog("CamRecord:" + args);
psi.Arguments = args;
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
}

} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
writeFileLog("CamRecord:" + message);
}



try

MikeD99 posted this 09 April 2014

Guys,
I am a retired programmer but do not know C# so I just modded the examples in the Scripts directory and other examples until I got it to work.

Let me know if you have any questions whatsoever as I would be glad to answer them.

Mike D.

millje posted this 09 April 2014

What is the Record Porch referencing? I can see where to in put address to my .bat file but I am not sure what to put here?

psi.Arguments = "Record Porch";

MikeD99 posted this 09 April 2014

That line sets the arguments to .bat call to execute.

The effect is as if you typed:
porchConvertAndFTP.bat Record Porch


In other words, if the execute line was for a Dir command and the argument line was set to *.txt

it would be like typing

Dir *.txt

on the command line.

Here is a hint that gave me some trouble:
Make sure the references to the file to execute are fully qualified because it runs in the who-knows-where directory. If you are not in the directory that the file.bat is in you will need to refer to it like this:
C:\user\Mike\myFile.bat

Mike D.

Did this help? I will be glad to help more if you'd like me to.

millje posted this 10 April 2014

So my bat file is located at C:\BiCommand folder and in that folder the bat file I want to run is AllCameraRecord.bat.

What would I put int he Argument Line and and what would I put in the line down below.

MikeD99 posted this 10 April 2014

You would just put C:\BiCommand\AllCameraRecord.bat in the exec line. Since your bat file has no arguments you don't even need the argument line.

Mike D.

MikeD99 posted this 10 April 2014

Try this:


using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class Runbat : ScriptBase, ScriptInterface {
public void runScript() {
try {
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\BiCommand\AllCameraRecord.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
}
}
}

millje posted this 11 April 2014

I am still not sure why I cant get this to work. I even moved the location of my Bat file to the default directory where cmd opens. Again the bat file works when I click on it but I get nothing from it when I put it into the script. If I open the cmd window and type the name of the bat file it works fine also?????

MikeD99 posted this 11 April 2014

Maybe post the contents of the .bat file?

Mike D.

millje posted this 11 April 2014

bicommand trigger Cam1 Cam2 Cam3

That is it.


Saved that as the allcamerarecord.bat

The bat file has to be in the same folder as the bicommand app and it is.


MikeD99 posted this 11 April 2014

Did you try what I posted in post #2263? It looks like it should work to me. I can't help anymore.

Mike D.

millje posted this 11 April 2014

Yes and nothing happened. I am still on the hunt.

millje posted this 11 April 2014

Other scrips I have tried that Ryan and others had posted with the test email in them send the email but will not fun my bat file. So I am still looking for the fix.

Show More Posts
Close