calling exe on server from asp.net

want to run exe from asp.net on my server, is this possible?

I use this method:

    System.Diagnostics.Process process1 = new System.Diagnostics.Process();
    // Set the directory where the file resides

    process1.StartInfo.WorkingDirectory = @"D:devAnalyzerbinRelease";
    // Set the filename name of the file you want to open

    process1.StartInfo.FileName = @"D:devAnalyzerbinReleaseAnalyzer.exe";
    process1.StartInfo.Arguments = "123";
    // Start the process

    process1.Start();

it works when i debug it, but when put my website on localhost then i have exception:

Login failed for user 'IIS APPPOOLdq'

where dq is name of my website.

Stack:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'IIS APPPOOLdq'. at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOp tions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBas e.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user) at System.Data.Linq.SqlClient.SqlProvider.get_IsSqlCe() at System.Data.Linq.SqlClient.SqlProvider.InitializeProviderMode() at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) at System.Data.Linq.DataQuery`1.System.Collections.Generic.IEnumerable.GetEnumerator() at Analyzer.Program.Main(String[] args) in D:devAnalyzerProgram.cs:line 59


I am assuming here that the exception you are getting is an access violation one.

If that is the case, you need to ensure to either start the process with a UserName and Password for an account with enough privileges to run the executable (and access the directory it is in), or setup the application pool with such an account.


Update:

The stack trace points at a bad LINQ query, not Process.Start . What exactly is the exception? I can't tell from the trace.

What line is this throwing on?


Update 2:

Check your connection strings and SQL Server - the site account is failing to login to SQL Server. This has absolutely nothing to do with Process.Start or LINQ syntax.

Have you set the correct password? If you are using integrated security ( SSPI=true ), have you ensured that SQL Server has this login enabled?


This approach is not recommended at all. On server, your ASP.NET website also runs as a process. Launching another process would require some extra permissions. Worker process is trying to launch analyzer.exe with its own user's (IIS APPPOOLdq) account and is failing there. You would require to run your worker process with another account which will have enough permissions to launch another executable.

BTW, this will open up your surface area for threats. Not recommended at all.

Thanks Gaurav

链接地址: http://www.djcxy.com/p/56700.html

上一篇: 用户登录失败

下一篇: 从asp.net调用服务器上的exe文件