PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Mit einer Batchdatei vier Befehle nacheinander mit einem Klick ausführen


Snoopy69
2023-02-14, 16:11:55
Ich möchte 4 verschiedene Befehle mit nur einem Klick ausführen. Als ein Befehl ist fertig, danach startet automatisch der nächste Befehl usw

Blase
2023-02-14, 16:16:50
"Start /wait" wäre ne Option, um die Befehle erst dann fortzuführen, wenn der vorherige durch ist. Du könntest auch mit "Call" weitere Batch Dateien aufrufen, und so Batch für Batch automatisch nacheinander aufrufen.

Was hast du denn konkret vor?

MfG Blase

Snoopy69
2023-02-14, 16:24:34
Mit Batches schreiben (start/wait/call etc) hab ich es nicht so ;(
Ein kleines Beispiel mit 2 Befehlen nacheinander wäre klasse

Blase
2023-02-14, 16:31:21
Nun sag doch schon, was du eigentlich vor hast ;)

https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb491005(v=technet.10)?redirectedfrom=MSDN

https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb490873(v=technet.10)?redirectedfrom=MSDN

MfG Blase

Snoopy69
2023-02-14, 16:35:10
Es sollen 4 DISM-Befehle nacheinander ausgeführt werden :)

Κριός
2023-02-14, 16:48:57
Chat GPT kann helfen:
https://abload.de/img/screenshot2023-02-141jff1e.png

Du kannst es auch direkt von CHatGPT schreiben lassen. Dann musst du es die Befehle nennen.

Birdman
2023-02-14, 17:07:21
Du kannst verschiedene Befehle auf eine Zeile schreiben und mit dem & Zeichen "verknüpfen"
je nachdem ob du hierbei ein oder zwei & Zeichen verwendest wird der nachfolgende Befehl immer ausgeführt, oder nur wenn der vorherige erfolgreich war.

ShinyMcShine
2023-02-15, 08:11:53
Es sollen 4 DISM-Befehle nacheinander ausgeführt werden :)



@ECHO OFF

REM 1 - mount the Windows image

dism /Mount-Image /ImageFile:C:\myimage.wim /Index:1 /MountDir:C:\mountdir

REM 2 - add a driver package to the image

dism /Image:C:\mountdir /Add-Driver /Driver:C:\drivers\mydriver.inf

REM 3 - Unmount the image and save changes

dism /Unmount-Image /MountDir:C:\mountdir /Commit



Sind jetzt zwar nur 3, aber ich denke, das zeigt Dir wie es geht.

Snoopy69
2023-02-17, 16:53:15
Ich danke euch :up:

Lokadamus
2023-03-02, 05:44:58
Du kannst verschiedene Befehle auf eine Zeile schreiben und mit dem & Zeichen "verknüpfen"
je nachdem ob du hierbei ein oder zwei & Zeichen verwendest wird der nachfolgende Befehl immer ausgeführt, oder nur wenn der vorherige erfolgreich war.Hier ein Beispiel.

Hab mich letztens mit der CPU Affnität (der Core- Zuweisung) bezgülich AMD Ryzen CCX beschäftigt und das ist dabei herausgekommen.
Wenn man weiß, wie Intel seine L2 Caches verwaltet, weiß man, dass auch Intel davon profitiert, wenn nicht mehr auf allen Cores von den Programmen zugegriffen wird.
Über Taskmanager > Karteireiter Details > Rechtsklick auf Programm > Zugehörigkeit festlegen kann man es manuell machen.
Nach einem Neustart sind die Einstellungen wieder weg, weshalb die Batch es machen soll.

Der Tasklist |find dient dazu, um zu sehen, ob der Process aktiv ist oder nicht. Dadurch kann die Batch bei Win10 und 11 eingesetzt werden ohne nenneswerte Fehlermeldungen zu erzeugen.
Ein paar Fehlermeldungen gibt es immer wieder, weil Windows einige Sachen zwischendurch beendet (dllhost z.B.)


@ECHO OFF
rem Run as admin!
rem Autor: Lokadamus, 24.02.2023 ...
rem csrss, MsMpEng, NisSrv, Registry, SecurityHealthService, services, SgrmBroker, smss, wininit Zugriff verweigert!
rem svchost = virtualbox!
rem CPU Cores = bin dec or bin hex calculator!

rem Explorer (AF0 = Core 1-12), Windows Default Stuff (AF1 = Core 1-2, 1-4), Epic Games Launcher (AF2 = 6-12), Steam (AF3 = 3-6), AF6 = 1-6, ...
set AF0=0xFFF
set AF1=0x3
rem set AF1=0xF
set AF2=0xFC0
set AF3=0x3C
set AF6=0x3F

echo.
echo Run as admin!
echo.
echo Changing cpu affinity ...
echo.

rem Windos Default Stuff
rem audiodg start
PowerShell -c (New-Object Media.SoundPlayer "%windir%\Media\ding.wav").Play(); Start-Sleep -s 1; Exit
tasklist |find "audiodg" && PowerShell "ForEach($PROCESS in GET-PROCESS audiodg) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "AggregatorHost" && PowerShell "ForEach($PROCESS in GET-PROCESS AggregatorHost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "ApplicationFrameHost" && PowerShell "ForEach($PROCESS in GET-PROCESS ApplicationFrameHost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "conhost" && PowerShell "ForEach($PROCESS in GET-PROCESS conhost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "ctfmon" && PowerShell "ForEach($PROCESS in GET-PROCESS ctfmon) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "dllhost" && PowerShell "ForEach($PROCESS in GET-PROCESS dllhost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "dwm" && PowerShell "ForEach($PROCESS in GET-PROCESS dwm) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "fontdrvhost" && PowerShell "ForEach($PROCESS in GET-PROCESS fontdrvhost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "fontdrvhost" && PowerShell "ForEach($PROCESS in GET-PROCESS fontdrvhost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "LockApp" && PowerShell "ForEach($PROCESS in GET-PROCESS LockApp) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "lsass" && PowerShell "ForEach($PROCESS in GET-PROCESS lsass) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "OneDrive" && PowerShell "ForEach($PROCESS in GET-PROCESS OneDrive) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "PhoneExperienceHost" && PowerShell "ForEach($PROCESS in GET-PROCESS PhoneExperienceHost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "RuntimeBroker" && PowerShell "ForEach($PROCESS in GET-PROCESS RuntimeBroker) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "SearchApp" && PowerShell "ForEach($PROCESS in GET-PROCESS SearchApp) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "SearchIndexer" && PowerShell "ForEach($PROCESS in GET-PROCESS SearchIndexer) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "SecurityHealthSystray" && PowerShell "ForEach($PROCESS in GET-PROCESS SecurityHealthSystray) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "sihost" && PowerShell "ForEach($PROCESS in GET-PROCESS sihost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "smartscreen" && PowerShell "ForEach($PROCESS in GET-PROCESS smartscreen) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "spoolsv" && PowerShell "ForEach($PROCESS in GET-PROCESS spoolsv) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "StartMenuExperienceHost" && PowerShell "ForEach($PROCESS in GET-PROCESS StartMenuExperienceHost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "svchost" && PowerShell "ForEach($PROCESS in GET-PROCESS svchost) { $Process.ProcessorAffinity=%AF6%}" > NUL
tasklist |find "SystemSettings" && PowerShell "ForEach($PROCESS in GET-PROCESS SystemSettings) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "taskhostw" && PowerShell "ForEach($PROCESS in GET-PROCESS taskhostw) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "Taskmgr" && PowerShell "ForEach($PROCESS in GET-PROCESS Taskmgr) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "TextInputHost" && PowerShell "ForEach($PROCESS in GET-PROCESS TextInputHost) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "UserOOBEBroker" && PowerShell "ForEach($PROCESS in GET-PROCESS UserOOBEBroker) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "winlogon" && PowerShell "ForEach($PROCESS in GET-PROCESS winlogon) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "WmiApSrv" && PowerShell "ForEach($PROCESS in GET-PROCESS WmiApSrv) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "WmiPrvSE" && PowerShell "ForEach($PROCESS in GET-PROCESS WmiPrvSE) { $Process.ProcessorAffinity=%AF1%}"

rem Driver
tasklist |find "atieclxx" && PowerShell "ForEach($PROCESS in GET-PROCESS atieclxx) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "atiesrxx" && PowerShell "ForEach($PROCESS in GET-PROCESS atiesrxx) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "BrYNSvc" && PowerShell "ForEach($PROCESS in GET-PROCESS BrYNSvc) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "NVDisplay.Container" && PowerShell "ForEach($PROCESS in GET-PROCESS NVDisplay.Container) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "RtkAudUService64" && PowerShell "ForEach($PROCESS in GET-PROCESS RtkAudUService64) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "runSW" && PowerShell "ForEach($PROCESS in GET-PROCESS runSW) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "SwUSB" && PowerShell "ForEach($PROCESS in GET-PROCESS SwUSB) { $Process.ProcessorAffinity=%AF1%}"

rem Launcher. Inheritance problem! set explorer to max of your cores or rem the line!
tasklist |find "explorer" && PowerShell "ForEach($PROCESS in GET-PROCESS explorer) { $Process.ProcessorAffinity=%AF0%}"
tasklist |find "EpicGamesLauncher" && PowerShell "ForEach($PROCESS in GET-PROCESS EpicGamesLauncher) { $Process.ProcessorAffinity=%AF2%}"
tasklist |find "EpicWebHelper" && PowerShell "ForEach($PROCESS in GET-PROCESS EpicWebHelper) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "EpicWebHelper" && PowerShell "ForEach($PROCESS in GET-PROCESS EpicWebHelper) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "steam" && PowerShell "ForEach($PROCESS in GET-PROCESS steam) { $Process.ProcessorAffinity=%AF3%}"
tasklist |find "SteamService" && PowerShell "ForEach($PROCESS in GET-PROCESS SteamService) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "steamwebhelper" && PowerShell "ForEach($PROCESS in GET-PROCESS steamwebhelper) { $Process.ProcessorAffinity=%AF1%}"

rem other software
tasklist |find "cmd" && PowerShell "ForEach($PROCESS in GET-PROCESS cmd) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "GoogleCrashHandler" && PowerShell "ForEach($PROCESS in GET-PROCESS GoogleCrashHandler) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "GoogleCrashHandler64" && PowerShell "ForEach($PROCESS in GET-PROCESS GoogleCrashHandler64) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "ImDiskTk-svc" && PowerShell "ForEach($PROCESS in GET-PROCESS ImDiskTk-svc) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "msedge" && PowerShell "ForEach($PROCESS in GET-PROCESS msedge) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "msedgewebview2" && PowerShell "ForEach($PROCESS in GET-PROCESS msedgewebview2) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "PnkBstrA" && PowerShell "ForEach($PROCESS in GET-PROCESS PnkBstrA) { $Process.ProcessorAffinity=%AF1%}"
tasklist |find "Robocopy" && PowerShell "ForEach($PROCESS in GET-PROCESS Robocopy) { $Process.ProcessorAffinity=%AF1%}"

pause

GanjaBob
2023-03-02, 10:18:51
Hier ein Beispiel.

Hab mich letztens mit der CPU Affnität (der Core- Zuweisung) bezgülich AMD Ryzen CCX beschäftigt und das ist dabei herausgekommen.
Wenn man weiß, wie Intel seine L2 Caches verwaltet, weiß man, dass auch Intel davon profitiert, wenn nicht mehr auf allen Cores von den Programmen zugegriffen wird.
Über Taskmanager > Karteireiter Details > Rechtsklick auf Programm > Zugehörigkeit festlegen kann man es manuell machen.
Nach einem Neustart sind die Einstellungen wieder weg, weshalb die Batch es machen soll.

Der Tasklist |find dient dazu, um zu sehen, ob der Process aktiv ist oder nicht. Dadurch kann die Batch bei Win10 und 11 eingesetzt werden ohne nenneswerte Fehlermeldungen zu erzeugen.
Ein paar Fehlermeldungen gibt es immer wieder, weil Windows einige Sachen zwischendurch beendet (dllhost z.B.)

...

sehr kreativ :D
wieso nicht gleich alles in Powershell? ;)
Nofification z. Bsp. mit:
[console]::beep(500,300)
Alle Prozesse welche Core X - Y laufen sollen in ein Array (z. Bsp.:[array]$cpuaffi1 = "audiodg","AggregatorHost","...") und darauf das "foreach":
foreach ($process in $cpuaffi1) {$Process.ProcessorAffinity=%AF1%}


Anstatt "Tasklist | find" kannst du "Get-Process -ErrorAction SilentlyContinue" angeben, da werden die Fehlermeldungen unterdrückt bei Prozessen die gerade nicht aktiv sind.