cschneegans / unattend-generator

.NET Core library to create highly customized autounattend.xml files

Home Page:https://schneegans.de/windows/unattend-generator/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Execution of .bat File

hanton94 opened this issue · comments

Would it be possible to add the option to execute a .bat or .cmd file as an administrator that is already previously saved in a folder?

The idea is for this .bat file to run only once during the system installation.

Thank you, I await your response ^^

Such a mechanism already exists in Windows Setup: If present, the file %WINDIR%\Setup\Scripts\SetupComplete.cmd will run during Windows Setup with SYSTEM permissions.

Also note that setting Schneegans.Unattend.Configuration.RunScriptOnFirstLogon = true will run the file %WINDIR%\Setup\Scripts\UserFirstLogon.cmd whenever a user logs on for the first time.

However, I will consider adding an option to run script code from autounattend.xml in a self-contained way, without the need to add SetupComplete.cmd and UserFirstLogon.cmd.

I have now added settings (via 6d3114e) to run custom .cmd or .ps1 scripts during various stages of the Windows Setup process. See the Run custom scripts section in the web interface.

Hi you had given me a script to disable windows hibernation, I wanted to know how to make it work in the interface? To make it run by itself when I log on windows, I need administrator permissions to run the script and when I tried this section it didn't work 'Run these cmd commands when the first user logs on'

Since powercfg.exe settings are not per-user, do not use a FirstLogon script, but rather a System script.

Furthermore, unlike SetupComplete.cmd, the new custom scripts can run PowerShell commands directly, eliminating the need to call powershell.exe -NoProfile -Command "...". Therefore, a custom script might look like this:

powercfg.exe /HIBERNATE OFF;
$out = powercfg.exe /DUPLICATESCHEME 'e9a42b02-d5df-448d-aa00-03f14749eb61';
if( $out -match '\s([a-f0-9-]{36})\s' ){
	powercfg.exe /SETACTIVE $Matches[1];
}

This link will configure the SystemScript and SystemScriptType fields accordingly.

I have tested the resulting autounattend.xml file with a virtual Windows 10 Home installation, and the Ultimate Performance power plan was indeed enabled.

Also note that due to a bug custom scripts were not created (and hence not executed) if the C:\Windows\Setup\Scripts folder did not exist.

If you refresh your autounattend.xml file, you will notice an additional command <Path>cmd.exe /c "mkdir C:\Windows\Setup\Scripts"</Path>.

Thank you very much, it's just what I was looking for. I'll try to implement it to see how it works.