C# 在远程计算机上尝试exec exe时登录失败

C# 在远程计算机上尝试exec exe时登录失败,c#,wmi,remote-access,C#,Wmi,Remote Access,我正在使用ManagementClass在远程计算机上执行exe var serverPath = new ManagementPath { Server = "SERVERNAME", NamespacePath = "\\ROOT\\CIMV2", ClassName = "Win32_Process" }; var connection = new Connection

我正在使用ManagementClass在远程计算机上执行exe

var serverPath = new ManagementPath
        {
            Server = "SERVERNAME",
            NamespacePath = "\\ROOT\\CIMV2",
            ClassName = "Win32_Process"
        };

        var connection = new ConnectionOptions
        {
            Username = _Domain + @"\" + _UserName,
            Password = _Pass,
            Impersonation = ImpersonationLevel.Impersonate,
            Authentication = AuthenticationLevel.Packet,

            EnablePrivileges = true,
            Timeout = new TimeSpan(0, 0, 15)
        };

        var ms = new ManagementScope(serverPath, connection);
        var mprocess = new ManagementClass(ms, new ManagementPath("Win32_Process"), new ObjectGetOptions());

        var inParams = mprocess.GetMethodParameters("Create");
        inParams["CommandLine"] = @"F:\Utils\Directory\program.exe";
        inParams["CurrentDirectory"] = @"F:\Utils\Directory\";

        mprocess.InvokeMethod("Create", inParams, null);
我的应用程序出现以下错误:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
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, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at KPlusSynchronizer.Tyche.StoreIntoDatabase(String tycheConnection, String sp, XDocument xml, Boolean logXml, String path, String user)
at KPlusSynchronizer.Synchronizer.Synchronize(String tycheTable, String tycheSp, String kplusSp, String path, String user)
当我使用与ConnectionOptions中相同的用户名和密码手动登录服务器并手动启动exe时,它工作正常

在尝试连接之前,我还尝试使用一个模拟用户(这使我成为管理员,与用户名和密码相同)


有人能看到我遗漏了什么吗?

我查看了我们的代码库。我们对WMI做完全相同的事情

.....
var strWmiPath = string.Format(@"\\{0}\{1}", m_remoteHost, wmiNamespacePath != null ? string.Join("\\", wmiNamespacePath) : string.Empty);
m_scope = new ManagementScope(strWmiPath, options);
m_scope.Connect(); // that is missing in your version
....
var commandLine = string.Format(CultureInfo.InvariantCulture, "{0} {1}", fileName, arguments);
var remoteCmd = new ManagementClass(m_scope, new ManagementPath("Win32_Process"), null);
var inParams = remoteCmd.GetMethodParameters("Create");
        inParams["CommandLine"] = commandLine;
        inParams["CurrentDirectory"] = null;
        inParams["ProcessStartupInformation"] = null;
remoteCmd.InvokeMethod("Create", inParams, null);

你的过程是互动的吗?远程进程在哪个操作系统上启动?Dis解决方案不适用于交互式进程(与UI交互的进程)@ManuelAmstutz操作系统是“Microsoft Windows Server 2012数据中心”。该过程不是交互式的,但它使用数据库中的集成安全性对数据库进行了一些调用……我看到了完整的错误消息,其中抱怨了一些Sql。将以完全错误更新问题