Set sound volume level on login

Kasual

Well-Known Member
Messages
1,485
Reaction score
508
Sometimes people set high (or max) volume level and forget to set volume to low on shut down.

After a few years of no activity at all, I'm "rusted" on windows customization.

Has anyone asked as a feature an option to set volume to a custom level on boot?
 
Volume Boot Control

Run PowerShell / Terminal as Administrator, paste the script:
Bash:
$p="$env:LocalAppData\Programs\NirCmd\nircmd.exe";$d=Split-Path $p;$x="$d\volsvc.exe";$n="SetVolSvc";$r="HKLM:\SYSTEM\CurrentControlSet\Services\$n\Parameters";$k='HKCU:\Software\Microsoft\Windows\CurrentVersion\Run';$m='HKCU:\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache'
while($true){$i=(Read-Host 'Volume 0-100 | d=delete | q=quit').Trim().ToLower()
if($i -eq 'q'){Write-Host 'Exit' -ForegroundColor Yellow;[Console]::Beep(500,80);[Console]::Beep(300,120);exit}
if($i -eq 'd'){if(Test-Path $k){(Get-Item $k).Property|?{$_ -like 'SetVolume*'}|%{rp $k $_ -ea 0}};if(Test-Path $m){(Get-Item $m).Property|?{$_ -like '*nircmd*' -or $_ -like '*volsvc*'}|%{rp $m $_ -ea 0}};sc.exe stop $n *>$null;sc.exe delete $n *>$null;rm $d -r -fo -ea 0;rm "$env:TEMP\nircmd.zip" -fo -ea 0;rm "$env:WINDIR\Prefetch\NIRCMD.EXE-*.pf" -fo -ea 0;rm "$env:WINDIR\Prefetch\VOLSVC.EXE-*.pf" -fo -ea 0;Write-Host 'Deleted' -ForegroundColor Yellow;[Console]::Beep(600,80);[Console]::Beep(400,120);continue}
$v=0;if([int]::TryParse($i,[ref]$v) -and $v -ge 0 -and $v -le 100){
if(-not(Test-Path $p)){$pp=$ProgressPreference;$ProgressPreference='SilentlyContinue';[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;mkdir $d -Force|Out-Null;try{iwr https://www.nirsoft.net/utils/nircmd-x64.zip -OutFile "$env:TEMP\nircmd.zip" -ea Stop;Expand-Archive "$env:TEMP\nircmd.zip" $d -Force -ea Stop}catch{Write-Host 'Download failed' -ForegroundColor Red};$ProgressPreference=$pp}
if(-not(Test-Path $x)){$c=@("$env:WINDIR\Microsoft.NET\Framework64\v4.0.30319\csc.exe","$env:WINDIR\Microsoft.NET\Framework\v4.0.30319\csc.exe")|?{Test-Path $_}|Select -First 1;if(-not $c){$c=(gci "$env:WINDIR\Microsoft.NET" -r -fi csc.exe -ea 0|Select -First 1).FullName}
if($c){@'
using System;using System.ServiceProcess;using System.Diagnostics;using System.Threading;using Microsoft.Win32;
class V:ServiceBase{protected override void OnStart(string[] a){try{using(var s=new ServiceController("AudioSrv"))s.WaitForStatus(ServiceControllerStatus.Running,TimeSpan.FromSeconds(15));Thread.Sleep(200);using(var k=Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\SetVolSvc\\Parameters")){if(k!=null){string e=k.GetValue("NirCmdPath")as string;int v=Convert.ToInt32(k.GetValue("Volume")??0);if(e!=null&&System.IO.File.Exists(e)){var p=new ProcessStartInfo(e,"setsysvolume "+v){UseShellExecute=false,CreateNoWindow=true};var r=Process.Start(p);if(r!=null)r.WaitForExit(5000);}}}}catch{}Stop();}protected override void OnStop(){}static void Main(){Run(new V());}}
'@|Out-File "$d\v.cs" -Encoding UTF8;& $c /nologo /reference:System.ServiceProcess.dll /out:$x "$d\v.cs" 2>$null;rm "$d\v.cs" -fo -ea 0}else{Write-Host 'csc.exe not found' -ForegroundColor Red}}
if((Test-Path $p) -and (Test-Path $x)){$s=[int][math]::Floor($v*655.35+.5);sc.exe query $n *>$null;if($LASTEXITCODE -ne 0){sc.exe create $n binPath= "`"$x`"" start= auto obj= LocalSystem type= own *>$null;sc.exe query $n *>$null;if($LASTEXITCODE -ne 0){Write-Host 'Service create failed' -ForegroundColor Red;continue}};if(-not(Test-Path $r)){mkdir $r -Force|Out-Null};sp $r NirCmdPath $p;sp $r Volume $s -Type DWord;& $p setsysvolume $s;Write-Host "Volume $v%" -ForegroundColor Green;[Console]::Beep(900,100)}else{Write-Host 'nircmd/volsvc not found' -ForegroundColor Red}}else{Write-Host 'Invalid input' -ForegroundColor Red}}
Sets Windows volume to a specified level before the welcome sound plays at boot. Works through a Windows service SetVolSvc that starts during the service loading phase — before winlogon and the shell. On first numeric input, the script downloads the NirCmd utility (nirsoft.net - 152KB), compiles the service volsvc.exe using the built-in Windows csc.exe compiler, and registers it via sc.exe. Subsequent inputs only update the volume in the service registry.

Input: 0–100 | Set volume: immediately + at every boot

Input: d | Full removal: stop and delete the SetVolSvc service, NirCmd folder, archive, HKCU:\...\Run entries, MUICache, Prefetch files

Input: q | Exit the script
 
Too much info o_O
internet needed
How can I add it into windows unattended install image without internet set up?
 
Back
Top