1 function Run([string]$name,$var,[bool]$wait_exp){ 2 $startclass = Get-CimClass -ClassName Win32_ProcessStartup 3 $startinfo = New-CimInstance -CimClass $startclass -Property @{ShowWindow = $var} -ClientOnly 4 $class = Get-CimClass -ClassName Win32_Process 5 [int]$r=Invoke-CimMethod -CimClass $class -MethodName Create -Arguments @{ 6 Commandline = $name; 7 ProcessStartupInformation = [CimInstance]$startinfo 8 }|Select-Object -Property ProcessId|%{[regex]::Matches([string]$_,'(\d+)').Value} 9 if ($wait_exp -eq $true) 10 { 11 Wait-Process -Id $r 12 } 13 } 14 Run cmd 1 0 15 # 参数说明 16 # 启动cmd,1表示normal正常窗口,【1是否等待进程结束/0表示不等待】