Прикрепите крюк клавиатура на процесс дистанционного инструментария WMI
Hi I have a question about interctivity while using WMI in c#, I am running command on my remote desktop using wmi for example: cmd /c C:\test.exe Now while doing that process asks to press any key to continue. I had an idea that command would dump result to some sort of log file so command wold look like this cmd /c C:\test.exe > log.txt and then event watcher would check log in while loop for pause fraze, but then I do not know how to create press key process /keyboard hook and attach it to my command process on remote desktop. Is there an easier way to catch that message and press key when the process asks?
Что я уже пробовал:
private void ExecuteCommand(string command) { ConnectionOptions connection = new ConnectionOptions { Username = UserName, Password = Password }; this.wmiScope = new ManagementScope(string.Format(@"\\{0}\root\CIMV2", IPAddress), connection); try { this.wmiScope.Connect(); } catch (Exception e) { var exceptionMessage = string.Format("Management Connect to remote machine {0} failed with the following error {1}", this.dutConfig.IPAddress, e.Message); throw new Exception(exceptionMessage); } this.Logger.AddMessage("Start wmi process: {0}", command); ObjectGetOptions objectGetOptions = new ObjectGetOptions(); ManagementPath managementPath = new ManagementPath("Win32_Process"); using (ManagementClass processClass = new ManagementClass(this.wmiScope, managementPath, objectGetOptions)) { using (ManagementBaseObject inParams = processClass.GetMethodParameters("Create")) { inParams["CommandLine"] = command; using (ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null)) { if (outParams != null && (uint)outParams["returnValue"] != 0) { throw new Exception(string.Format("Error while starting process {0} creation returned an exit code of {1}", command, outParams["returnValue"])); } if (outParams != null) { this.processId = (uint)outParams["processId"]; this.ExitCode = Convert.ToUInt16(outParams["returnValue"]); } } } } this.Logger.AddMessage("Start monitoring event for wmi process: {0}, with id: {1}", command, this.processId); this.EventWatcher(); this.Logger.AddMessage("Wmi Command has finished"); }