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-ID: 2280006942

Url: https://administrator.de/forum/eingabekonsole-in-den-hintergrund-2280006942.html

Ausgedruckt am: 09.04.2025 um 12:04 Uhr

1915348599
Lösung 1915348599 25.03.2022 um 11:44:58 Uhr
Goto Top
Start-Process mit dem Parameter -NoNewWindow benutzen.