Getting No application is associated with the specified file for this operation while executing AutoIt scripts from vb.net - vb.net

I have installed AutoIt on my machine. Its working ok on one machine but same configuration and code is not working on other. Any idea what I am missing?
Following error
Could not start process Z:\test\AutoItScripts\test.au3
No application is associated with the specified file for this operation
Also autoit script successfully executes from command line. Its just getting this error while using the following code to execute
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.Verb = "runas"
objProcess.StartInfo.Arguments = Argument
objProcess.StartInfo.FileName = ProcessPath
objProcess.Start()
'Wait until it's finished
objProcess.WaitForExit()
'Exitcode as String
Console.WriteLine(objProcess.ExitCode.ToString())
objProcess.Close()

Because AutoIt3 scripts are not themselves executable, you will need to be using shellexecute.
p.UseShellExecute = true;

Process compiler = new Process();
compiler.StartInfo.FileName = sExeName;
compiler.StartInfo.Arguments = sParameters;
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
Console.WriteLine(compiler.StandardOutput.ReadToEnd());

Related

Is there a way to conect the input/output of a console application to the output/input of another program

I have an application i cannot edit that reads from the console and writes to it and i want to know how i can read what the program is saying and write back commands to the program.
This is for a minecraft server where i want to read what the players are saying and run commands acoording to what is said. (the server is the application i cannot edit)
I cannot create a modification for the server, because i am using a mod that checks if there are any other modifications done to the files and fails to load if that is the case.
I wrote a simple app in c# to get started with, to redirect the I/O streams you need to start the application (in this case the server) within your own application.
First we create a new instance of the System.Diagnostics.Process class
var process = new Process();
then we specify the start info
process.StartInfo = new ProcessStartInfo
{
FileName = Console.ReadLine(), //Reads executable path from console
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false
};
then we add an event handler, in this example it's just writes the lines with a "> " prefix
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine($"> {e.Data}");
and now we can start the process by calling Process#Start()
process.Start();
and finally we can call Process#BeginOutputReadLine() without this the OutputDataReceived event will never trigger
process.BeginOutputReadLine();
To send commands you can use the process' StandardInput stream
process.StandardInput.WriteLine("command");
The fully working code with example output (tested with cmd.exe, but it's must work with MC servers)
Code:
static void Main(string[] args)
{
Console.Write("Enter executable path: ");
var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = Console.ReadLine(), //Reads executable path, for example cmd is the input
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false
};
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) => Console.WriteLine($"> {e.Data}");
process.Start();
process.BeginOutputReadLine();
process.StandardInput.WriteLine("echo a");
//Prevent closing
Console.ReadKey();
}
Output:
Enter executable path: cmd
> Microsoft Windows [Version 10.0.18362.239]
> (c) 2019 Microsoft Corporation. Minden jog fenntartva.
>
> F:\VisualStudio\StackOverflow\StackOverflow\bin\Debug\netcoreapp2.1>echo a
> a
>

Converting a doc to a pdf in a mvc c# environment

Hi I've got a c# MVC application running under a particular user (app.pool user).
I need to convert a doc or docx file to a pdf.
I thought a good option would be to use libreoffice to fire a process that would start this.
To make life easier for myself (and if libreoffice shouldn't work) I used a batch file.
echo on
SET var1=%2
IF "%var1:~-1%"=="\" SET var1=%var1:~0,-1%
cd %var1%
echo %1
echo %var1%
start /wait "" "C:\Program Files (x86)\LibreOffice 4\program\soffice" -headless -convert-to pdf %1 -outdir %var1%
My code for starting this is as follows.
var ba = #"C:\inetpub\wwwroot\apps\xxxxxxxxx\Services\convert.bat";
fullPath = #"C:\inetpub\wwwroot\apps\xxxxxxxxx\Files\Temp\636295920370843147.doc";
var tempPath = #"C:\inetpub\wwwroot\apps\xxxxxxxxx\Files\Temp";
string command = ba;
//Process.Start(command, fullPath + " " + tempPath);
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command + " "+ fullPath+ " "+ tempPath);
processInfo.CreateNoWindow = false;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
var process = Process.Start(processInfo);
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
Trace.WriteLine("output>>" + e.Data);
process.BeginOutputReadLine();
process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
Trace.WriteLine("error>>" + e.Data);
process.BeginErrorReadLine();
process.WaitForExit();
Trace.WriteLine("ExitCode: {0}", process.ExitCode.ToString());
process.Close();
This does seem to work manually but when I run the code I can see the whole thing just stalls around the conversion. Looking at the threads and it seems to load the gdiplus.dll which I think is a graphics module which doesn't seem right.
The process though when I copy and paste that into my 'run' box in windows works fine and the pdf is made.
I've checked that the app.pool user has access to both libreoffice and also the folder with the files.
I've ran this as the app.pool user, in the c# it just stalls on the process.WaitForExit();
line. Until I kill the process.
Any ideas?
I've also tried many different ways of executing the soffice conversion. just straight from the c# - libreoffice 4,5.
I've seen some people use libreoffice as a service, is this an option? If so how?
Richard
EDIT
Ah, just changed the app Pool user to myself and now it works, so there is a permissions thing with the standard app pool user. How to find out what....
I added the user into the administrators group on the computer and restarted the machine, then it worked.
It might not be the best solution but after 2 days of trying to get this to work I'm not going to argue.
Richard

Executable app(.exe) not running via the ASP.Net Webservice(.asmx)

I want to execute a process from the ASP.Net Webservice(.asmx).
In the Webservice hosted directory, I have a executable app in "importerapp" folder of the webservice directory. My executable app is ( Named as Import.exe) is working good by double clicking.
My webservice is running with no error but the process is not executed.
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string executeProcess(RunMode mode )
{
Process process = new Process();
process.StartInfo.FileName = Server.MapPath("importerapp/Import.exe");
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.Arguments = "mode=" + (int)_runMode ;
process.Start();
process.WaitForExit();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
return("Job Submitted OK with params: "+_runMode + error
+ output +"Exit Code:"+ process.ExitCode );
}
In the browser, The output is as below.
<string xmlns="http://tempuri.org/">Job Submitted OK with
params: Exit Code:0</string>
That means, the "error" and "output" variable is null and exit code is 0 which means success.
But the processing is not doing anything, even not creating logfile( I am using nLog library).
Environment: WIndows7, IIS 7.5, .Net4.0, C#, ASP.Net
Please advise.
Thanks.
Ruhul
Job Submitted OK with params: Exit Code:0
This, according to your code, means that _runMode variable is not initiated. I think you forget to pass the parameter mode to your process

Why won't ArrayList.execute() use given arguments?

I'm trying to run a batch script on windows using groovy. I started with this code:
StringBuilder output = new StringBuilder()
StringBuilder error = new StringBuilder()
dir = new File("$homedir")
Process proc = "pathToScript\script.bat --arg test".execute(null, dir)
proc.consumeProcessOutput(output, error)
proc.waitFor()
print proc.exitValue()
This code works just fine for my scripts, but some commands don't play nice, so I decided to start using an ArrayList to store the arguments. So now my code looks like this:
StringBuilder output = new StringBuilder()
StringBuilder error = new StringBuilder()
dir = new File("$homedir")
ArrayList command = ["pathToScript\script.bat", "--arg test"]
Process proc = command.execute(null, dir)
proc.consumeProcessOutput(output, error)
proc.waitFor()
print proc.exitValue()
Now for some inexplicable reason it runs script.bat without the arguments. I've printed out the list to be sure it contains the arguments properly, which it does, so I'm not sure why the execute method isn't using them.
Try:
ArrayList command = ["pathToScript\script.bat", "--arg", "test"]
When an instance of List is used as source for execute() all arguments should be passed separately.

Redirecting Standard Output from a Process (msxsl.exe) to a string in VB.NET

I am writing a command line application in VB.NET. This application is calling another one, msxsl.exe, to run an XSL transform. I am using the Process class to do this:
Dim process = New Process()
process.StartInfo.FileName = "msxsl.exe"
process.StartInfo.Arguments = "base.xml test.xsl -o styled.xml"
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.StartInfo.RedirectStandardOutput = True
process.Start()
This part works great. What I want it to be able to display the output from this process to the console of my application. I have read several posts explaining this method, but it does not seem to work in this case. The output is an empty string.
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
Console.WriteLine(output)
I have verified that if I run the msxsl executable on its own (i.e. running "msxsl.exe base.xml test.xsl -o styled.xml"), it displays output on the command line. What am I doing wrong?
EDIT: I should note that the msxsl process is currently failing due to a malformed XML file. It is displaying this error message:
Error occurred while executing stylesheet 'test.xsl'.
Code: 0x800c0006
The system cannot locate the object specified.
This is exactly the type of thing I want displayed in the console of my application (or, eventually, a log file.)
This is probably because this isn't standard output it is StandardError you will want to redirect StandardError like so Process.StartInfo.RedirectStandardError = True and then read that into a string.
Dim ErrorString As String = Process.StandardError.ReadToEnd()