TekRadius is a Radius server that I want to access through my ASP.NET application. I first tried to execute TekRadius CLI directly using C#. But it didn't worked. Now I am trying to execute it through CMD by calling it in C# code like this:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.CreateNoWindow = true;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C \"c:\Program Files (x86)\TekRADIUS LT\trclilt.exe\" -u " + username + " " + password;
process.StartInfo = startInfo;
process.Start();
string line = "";
while (!process.StandardError.EndOfStream)
{
line = line + "\n" + process.StandardError.ReadLine();
}
File.WriteAllText(HttpContext.Current.Server.MapPath("~\\error.txt"), line);
TekRadius is working fine when executed directly through CLI or GUI or through Visual Studio's Internal Server. But on main server my custom error log error.txt is showing this error:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.UnauthorizedAccessException: Access to the path 'C:\Windows\TEMP\System.Data.SQLite.dll' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.File.InternalReadAllBytes(String path, Boolean checkHost)
at ????????????????????????????????????????.????????????????????????????????????????(String , String )
at ????????????????????????????????????????.????????????????????????????????????????()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at ????????????????????????????????????????(String[] )
TekRadius CLI uses SQLLite for storing its username and password. And I know its the TekRadius that is unable to access 'C:\Windows\TEMP\System.Data.SQLite.dll', not my application because I am using SQL Server and my above C# code is not making any attempts to access database. I am using Windows Server 2012 R2 and I am also unable to set new permissions on Windows folder. Please tell me what can I do to give access to this location to TekRadius CLI?
Finally after 12 hours I was able to solve it by myself. Solution was to give full control to ISS_IUSRS for System.Data.SQLite.dll in C:\Windows\Temp folder. Also, do the same for c:\Program Files (x86)\TekRADIUS LT\trclilt.exe.
Related
I tried to port a .net console application to a docker container. The application tries to call ffmpeg.exe, I get an error? Is it possible that I can't run an exe in this container?
static void encoder(string inputFile, string outputFolder, string outputFileName)
{
if (!Directory.Exists(outputFolder))
{
Directory.CreateDirectory(outputFolder);
}
var GetDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
// Part 1: use ProcessStartInfo class.
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.RedirectStandardInput = true;
startInfo.FileName = GetDirectory + #"/ffmpeg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
// Part 2: set arguments.
startInfo.Arguments = "-i " + inputFile + " -q:a 8 -filter:a loudnorm " + outputFolder + outputFileName;
// Part 3: start with the info we specified.
// ... Call WaitForExit.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.StandardInput.WriteLine("y");
exeProcess.WaitForExit();
}
}
Error
OPUS-Encoder System.ComponentModel.Win32Exception (8): An error occurred trying to start process '/App/ffmpeg.exe' with working directory '/App'. Exec format error
at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Program.<<Main>$>g__encoder|0_0(String inputFile, String outputFolder, String outputFileName) in /App/Program.cs:line 77
at Program.<Main>$(String[] args) in /App/Program.cs:line 34
thx
Looks like your docker container running Linux, but executable is Windows PE.
If your container is running Linux you need Linux binary not Windows
".exe".
You can get one here
API for call will be same.
If you want to support Linux and Windows you will need to change path parameter according to current OS.
Here is the question about how to do it on runtime.
I am trying the following:
1) Running a c# executable from another executable.
I am using .net core 3.1
Problem
I get the following error when I run the app in linux.
Error =>No such file or directory
Exception encountered => System.ComponentModel.Win32Exception (2): No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean
redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean
setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32&
stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal,
Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at ConsoleMQTT_Sender.ProcessClass.LaunchProcess(....) in ...
The app is generated through jenkins running in a linux environment.
The file is present but getting the above error.
Is this a cross-platform issue?
or a permission issue?
Flag when running the first executable
dotnet firstexecutable.dll --secondexecutablepath "/opt/publish/xyz.dll"
dotnet firstexecutable.dll --secondexecutablepath "dotnet /opt/publish/xyz.dll"
both giving the same exception
How I am triggering the executable inside c# console app :
process.EnableRaisingEvents = true;
process.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_OutputDataReceived);
process.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(process_ErrorDataReceived);
process.StartInfo.FileName = firstexecutablepath;
process.StartInfo.Arguments = "--secondexecutablepath \"" + executablepath + "\"";
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
process.WaitForExit();
I am creating an app in asp.net core that is run in a linux docker container using visual studio on windows. This app launches a different process depending on what platform it is on with Process.Start(). Currently, the process is launched correctly when run on my local windows machine, but when I switch to linux container I get this error (even tho both files I am attempting to launch are stored in the same directory). I did a check with File.Exists(processPath) and it shows that the file does in fact exist, but when the process is launched the Interop.Sys.ForkAndExecProcess() method seems to throw "No such file or directory" when it actually tries to launch the binary.
Unhandled Exception: System.ComponentModel.Win32Exception: No such file or directory
at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setUser, UInt32 userId, UInt32 groupId, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean shouldThrow)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
Here is the code
var assemblyFileInfo = new FileInfo(typeof(TemplateClass).Assembly.Location);
var rootDirectory = Path.Combine(assemblyFileInfo.DirectoryName, "HelmExecutables/Data/");
var processPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
processPath = Path.Combine(rootDirectory + "helm_windows.exe");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
processPath = Path.Combine(rootDirectory + "helm_linux.out");
}
var process = new Process();
var startInfo = new ProcessStartInfo();
startInfo.FileName = processPath;
process.StartInfo = startInfo;
process.Start();
One thing that came into my mind looking your code is processPath can be just an empty string if both RuntimeInformation.IsOSPlatform(OSPlatform.Windows) and RuntimeInformation.IsOSPlatform(OSPlatform.Linux) are false.
What I would do is check if RuntimeInformation.IsOSPlatform(OSPlatform.Linux) is true when the code runs in the docker image.
After that, I would Console.WriteLine(processPath) (or get the value of processPath in any other way) and try to start that executable from the command-line manually and see what happens.
There is a small program which is supposed to open file and then output it to console adding line numbers. The problem is that no matter whether program is run from command console of from IDE it throws exception regarding file permission.
I moved both executable and the file which is supposed to be read (simple TXT file) to several directories (my document, temp, etc) run console as Admin, run Visual studio as admin, gave all permissions to both files, but it always throws exception. The strangest thing is that a week or two ago I fund solution by trial and error but but I can' remember it.
Here is exception:
Exception: System.UnauthorizedAccessException: Access to the path 'C:\Users\Nena
d\documents\visual studio 2010\Projects\Listing 10.6\Listing 10.6\bin\Debug\prog
ram.cs' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, I
nt32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions o
ptions, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolea
n useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access,
FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean
bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at ListFile.Main(String[] args) in C:\Users\Nenad\documents\visual studio 201
0\Projects\Listing 10.6\Listing 10.6\Program.cs:line 22
Press any key to continue . . .
Here is code:
// ListFile.cs - program to print a listing to the console
//-----------------------------------------------------------
using System;
using System.IO;
class ListFile
{
public static void Main(string[] args)
{
try
{
int ctr = 0;
if (args.Length <= 0)
{
Console.WriteLine("Format: ListFile filename");
return;
}
else
{
FileStream fstr = new FileStream(args[0], FileMode.Open);
try
{
StreamReader t = new StreamReader(fstr);
string line;
while ((line = t.ReadLine()) != null)
{
ctr++;
Console.WriteLine("{0}: {1}", ctr, line);
}
}
catch (Exception e)
{
Console.WriteLine("Exception during read/write: {0}\n", e);
}
finally
{
fstr.Close();
}
}
}
catch (System.IO.FileNotFoundException)
{
Console.WriteLine("ListFile could not find the file {0}", args[0]);
}
catch (Exception e)
{
Console.WriteLine("Exception: {0}\n\n", e);
}
}
}
Check one of these possibilities:
File is not open in any other window/application
Run your applications .exe file as Administrator (optional extra, enable UAC so that you will see the request that the application requires elevated privileges and to explicitly give them, in Windows8 disabling UAC only hides these popups but that doesn't mean the application will have elevated rights so be careful if using Win8)
Manually set read rights to Everyone for that file
Check that the file is not in a special folder (but i think you already did that, but just to be sure create c:\temp and put it there)
CAUTION - The exception shows that there was a problem accessing C:\Users\Nena
d\documents\visual studio 2010\Projects\Listing 10.6\Listing 10.6\bin\Debug\prog
ram.cs not the a simple text file!!!
Be careful you may be providing a wrong path in your code by accident. And the Users folder is a special folder which requires elevated privileges to access, so better move the whole executable + readableFile to an ordinary folder where it will not encounter problems (like the c:\temp i mentioned above)
I am writing an application that is supposed to send an email, with up to 3 attachments.
It is just a really simple web form, with 3 FileUpload controls to browse the possible attachments.
The application is deployed in a webfarm and of course runs on server-side.
I managed to make it send the emails, but I am having problems with the attachments. Right now, I am using this procedure to attach the files:
if (fuAttatchment.HasFile)
{
fuAttatchment.SaveAs(Server.MapPath(fuAttatchment.FileName));
MyMessage.Attachments.Add(new System.Net.Mail.Attachment(Server.MapPath(fuAttatchment.FileName)));
filesize += fuAttatchment.PostedFile.ContentLength;
}
The error I am getting once I submit, is the following:
Send failure: System.UnauthorizedAccessException: Access to the path 'E:\Inetpub\IS\MSTicketRequest\wallpaper-3010.jpg' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at System.Web.UI.WebControls.FileUpload.SaveAs(String filename) at MSTicketRequest.WebForm1.btnSubmit_Click(Object sender, EventArgs e) in C:\Users\ggruschka\Desktop\ggruschka\MSTicketRequest\MSTicketRequest\Default.aspx.cs:line 54
I have not been able to figure out why is this happen, probably I am missing something regardin security policies or something like that.
Thank you very much in advance for your help !
instead of this:
fuAttatchment.SaveAs(Server.MapPath(fuAttatchment.FileName));
MyMessage.Attachments.Add(new System.Net.Mail.Attachment(Server.MapPath(fuAttatchment.FileName)));
do this:
fuAttatchment.SaveAs("somewhere local"+fuAttatchment.FileName);
MyMessage.Attachments.Add(new System.Net.Mail.Attachment("somewhere local"+fuAttatchment.FileName));
you don't need to be saving the attachments on the server!
Looks like the user that the site is running under doesn't have access to write to the target file path. Check the directory's security permissions and make sure the IIS user has write access.
Depends on what type ur application pool is. But if it is networkservice you gotta add networkservice.IIS_Users for ApplicationPoolIdentity but I'm not sure on this one.
http://www.windowsecurity.com/articles/understanding-windows-ntfs-permissions.html
If that doens't help you can try to remove the read only option.
You an send email via your gmail account. Here is how to do it (I dunno if it helps).
1. You need textbox where you are going to upload attachment.
2. Button 'Browse', and 'OpenFileDialog1'. In button 'Browse' you put this
private void btnBrowse_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txt_attachment.Text = openFileDialog1.FileName;
}
}
You need button 'Send with an attachment' in which you place this:
MailMessage mail = new MailMessage(txt_gmail.Text, txt_to.Text, txt_subject.Text, txt_body.Text);
mail.Attachments.Add(new Attachment(txt_attachment.Text));
SmtpClient client = new SmtpClient(txt_server.Text);
client.Port = 587;
client.Credentials = new System.Net.NetworkCredential(txt_gmail.Text, txt_password.Text);
client.EnableSsl = true;
client.Send(mail);
MessageBox.Show("Mail sent", "Succes", MessageBoxButtons.OK);
foreach (Control control in this.Controls)
{
TextBox box = control as TextBox;
if (box != null)
{
box.Text = "";
}
}
}
an the last thing (because when you do this it will show some errors) you need to create Gmail.dll file. Here is the link ho to do it:Here you can create Gmail.dll
I hope this helps.