enrixk
Goto Top

Eingabekonsole in den Hintergrund

Hallo,

ich habe ein Powershell-Skript geschrieben, das die IDE Visual Studio Code mit dem &-Operator startet. Der folgende Code bewirkt, das das Projektverzeichnis nach H: verschoben wird, wenn der Benutzer Visual Code wieder schließt (siehe Zeile 31 bis 36). Dabei hat mir der Benutzer Pretty aus diesem Forum geholfen. Vielen Dank an dieser Stelle! Mein Problem ist nun, dass sich beim Aufruf von Code.exe (Zeile 28) über den &-Operator eine schwarze Comamnd Promt öffnet. Kann man diese auch irgendwie in den Hintergrund verschieben?

class VSCodeSetup{

	[string] $WorkingDir
	[string] $userDataDir
	[string] $projectpath
	[string] $packagepath
	[string] $backupDir
		
	VSCodeSetup([string]$workingDir,[string]$userDataDir,[string]$projectpath,[string] $packagepath){
		$this.workingDir=$workingDir
		$this.userDataDir=$userDataDir
		$this.projectpath=$projectpath
		$this.packagepath=$packagepath
		$this.backupDir="H:\"  

		If(!(test-path -Path $this.WorkingDir)){
      		New-Item -ItemType Directory -Force -Path $this.WorkingDir
	  		New-Item -ItemType Directory -Force -Path $this.userDataDir
			New-Item -ItemType Directory -Force -Path $this.projectpath
			Copy-Item "C:\Program Files\Microsoft VS Code\projects\" -Destination $this.projectpath -Recurse  
		}		
	}

	[void] startVSCode(){
		$this.projectpath+="\projects"  
		$userDataPath=$this.userDataDir
		$arguments=@("--extensions-dir=""C:\Program Files\Microsoft VS Code\ext""","--user-data-dir=""$userDataPath""", $this.projectpath)  
		& "C:\Program Files\Microsoft VS Code\Code.exe"  $arguments  
	}
	
	[void] copyProjectFolder(){
		while((Get-Process -Name Code -EA SilentlyContinue)){
			#hier passiert gar nichts.
		}
		Move-Item -path $this.workingDir -Destination "H:\"   
	}
	
	[void] clearUserdata(){
		If(!(test-path -Path ($this.userDataDir))){
			Remove-Item 'C:\tmp\userdata' -Recurse  
		}
	}

}
$workingDir=$env:USERPROFILE+"\vscode"  
$extensionsDir="C:\Program Files\Microsoft VS Code\ext"  
$userDataDir="C:\tmp\userdata"  
$projectpath=$workingDir
$packagepath="C:\"  

$start= [VSCodeSetup]::new($workingDir,$userDataDir,$projectpath,$packagepath)
$start.clearUserdata()
$start.startVSCode()
$start.copyProjectFolder()

Content-Key: 2280006942

Url: https://administrator.de/contentid/2280006942

Printed on: May 10, 2024 at 22:05 o'clock

Mitglied: 1915348599
Solution 1915348599 Mar 25, 2022 at 10:44:58 (UTC)
Goto Top
Start-Process mit dem Parameter -NoNewWindow benutzen.