As a newcomer to stackoverflow, I am facing an issue with my asp.net web application. In one of the web forms, I need to execute cmd.exe from JavaScript on the server side after clicking a button.
function onRec(){
try{
var commandtoRun = "c:\\WINDOWS/system32/cmd.exe";
var commandParms = "dir";
alert("start recording ");
var ws = new ActiveXObject("WScript.Shell");
ws.ShellExecute(commandtoRun, commandParms, "", "open", "1");
}
catch(err)
{
alert(err.message):
}
}
<input type="button" name="Record" value="Record" onclick="OnRecStart();" />
I have tried the above code but it does not seem to invoke cmd.exe properly. I also attempted the following:
string filepath= Server.MapPath("../VideoStreaming/Record.bat");
ProcessStartInfo oProcessStartInfo = new ProcessStartInfo(filepath);
oProcessStartInfo.Arguments = "dir";
oProcessStartInfo.UseShellExecute = false;
Process oProcess = Process.Start(oProcessStartInfo);
oProcess.Start();
Although the second code snippet works fine locally, it fails when running from IIS. This has left me puzzled and I suspect there may be a browser security issue at play. Can someone provide suggestions on how to overcome this obstacle? Your help is greatly appreciated.