Example #1
0
        private void RunSriptOnRemote(ChoWinRemoteExecState winRemoteExecState)
        {
            ConnectionOptions connOptions = new ConnectionOptions();

            connOptions.Username = @"{0}\{1}".FormatString(_networkCredential.Domain, _networkCredential.UserName);
            connOptions.Password = _networkCredential.Password;
            //connOptions.Impersonation = ImpersonationLevel.Impersonate;
            connOptions.EnablePrivileges = true;

            ManagementScope manScope = new ManagementScope(@"\\{0}\ROOT\CIMV2".FormatString(_remoteMachine), connOptions);

            manScope.Connect();

            ObjectGetOptions objectGetOptions = new ObjectGetOptions();
            ManagementPath   managementPath   = new ManagementPath("Win32_Process");

            ManagementClass      processClass = new ManagementClass(manScope, managementPath, objectGetOptions);
            ManagementBaseObject inParams     = processClass.GetMethodParameters("Create");

            inParams["CommandLine"] = winRemoteExecState.RemoteScriptFilePath;

            ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);

            if (outParams != null)
            {
                winRemoteExecState.ProcessId   = (uint)outParams["processId"];
                winRemoteExecState.ReturnValue = (uint)outParams["returnValue"];
            }
        }
Example #2
0
        private void CreateScriptOnRemote(string[] cmds, ChoWinRemoteExecState winRemoteExecState)
        {
            winRemoteExecState.Clean();

            using (StreamWriter sw = new StreamWriter(winRemoteExecState.RemoteScriptFilePath))
                sw.WriteLine("@CALL {0} 1> {1} 2> {2}".FormatString(winRemoteExecState.RemoteScriptInnerFilePath,
                                                                    winRemoteExecState.RemoteScriptOutputFilePath, winRemoteExecState.RemoteScriptErrorFilePath));

            using (StreamWriter sw = new StreamWriter(winRemoteExecState.RemoteScriptInnerFilePath))
            {
                foreach (string cmd in cmds)
                {
                    if (cmd.IsNullOrWhiteSpace())
                    {
                        continue;
                    }
                    if (String.Compare(cmd, "cls", true) == 0)
                    {
                        continue;
                    }

                    sw.WriteLine(cmd);
                }
            }
        }
Example #3
0
        public ChoWinRemoteExecState RunCmd(string[] cmds)
        {
            ChoGuard.ArgumentNotNullOrEmpty(cmds, "Commands");

            ChoWinRemoteExecState winRemoteExecState = new ChoWinRemoteExecState(_remoteMachine, _networkCredential);

            using (ChoNetworkShare networkShare = new ChoNetworkShare(winRemoteExecState.RemoteShareName, _networkCredential))
            {
                CreateScriptOnRemote(cmds, winRemoteExecState);
                RunSriptOnRemote(winRemoteExecState);
                return(winRemoteExecState);
            }
        }