无法从c#执行TekRadius命令行

本文关键字:TekRadius 命令行 执行 | 更新日期: 2023-09-27 17:54:02

TekRadius是我想通过ASP访问的Radius服务器。网络应用程序。我第一次尝试使用c#直接执行TekRadius CLI。但这并没有奏效。现在我试图通过CMD执行它,在c#代码中调用它,像这样:

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工作正常时,直接通过CLI或GUI或通过Visual Studio的内部服务器执行。但是在主服务器上,我的自定义错误日志error.txt显示这个错误:

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使用SQLLite存储其用户名和密码。我知道它的TekRadius无法访问"C:'Windows'TEMP'System.Data.SQLite.dll",而不是我的应用程序,因为我使用的是SQL Server,而我的以上c#代码没有尝试访问数据库。我使用的是Windows Server 2012 R2,我也无法在Windows文件夹上设置新的权限。请告诉我我该怎么做才能让TekRadius CLI访问这个位置?

无法从c#执行TekRadius命令行

12个小时后,我终于可以自己解决了。解决的办法是在C:'Windows'Temp文件夹中对System.Data.SQLite.dll完全控制ISS_IUSRS。同样,对c:'Program Files (x86)'TekRADIUS LT'trclilt.exe执行相同的操作。