From a9249b8f3ce8f4a0e8614bcae553afe57ec6171b Mon Sep 17 00:00:00 2001 From: gyk <147011991+gyk4j@users.noreply.github.com> Date: Mon, 13 May 2024 08:57:01 +0800 Subject: [PATCH] Add config file line parsing (#10) --- wsh/chcl3.vbs | 45 ++++++++++++++++++++++++++++++++++++++++++--- wsh/services.txt | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 wsh/services.txt diff --git a/wsh/chcl3.vbs b/wsh/chcl3.vbs index 36da6fe..a8f1fdf 100644 --- a/wsh/chcl3.vbs +++ b/wsh/chcl3.vbs @@ -1,15 +1,43 @@ +Option Explicit + +Const OPEN_READ = 1 + Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Function ReadTextFile(Path) - Dim Buffer - Set fh = fso.OpenTextFile(Path, 1) + Dim fh, Buffer + Set fh = fso.OpenTextFile(Path, OPEN_READ) Buffer = fh.ReadAll() fh.Close Set fh = Nothing ReadTextFile = Buffer End Function +Sub ReadLine(Path, Callback) + Dim fh, Buffer + Set fh= fso.OpenTextFile(Path, OPEN_READ) + Do While Not fh.AtEndOfStream + Buffer = fh.ReadLine + 'Remove comment + Dim SemiColon + SemiColon = InStr(Buffer, ";") + If Not IsNull(SemiColon) And SemiColon > 0 Then + Buffer = Left(Buffer, SemiColon - 1) + End If + + 'Split into tokens + Dim Tokens + Tokens = Split(Buffer) + + If Not IsNull(Tokens) And IsArray(Tokens) And UBound(Tokens) > 0 Then + Call Callback(Tokens) + End If + Loop + fh.Close + Set fh = Nothing +End Sub + Function DisplayLicense() Dim LicenseText LicenseText = ReadTextFile("..\LICENSE") @@ -41,6 +69,17 @@ Function DisplayWarning DisplayWarning = MsgBox(WarningText, vbYesNo + vbExclamation + vbDefaultButton2, "Warning") End Function +Sub StopService(Service) + WScript.Echo Service(LBound(Service)) +End Sub + +Sub StopServices + Dim SubRef + Set SubRef = GetRef("StopService") + Call ReadLine("services.txt", SubRef) + Set SubRef = Nothing +End Sub + Sub Main() Dim Accepted Accepted = DisplayLicense() @@ -49,7 +88,7 @@ Sub Main() Accepted = DisplayWarning() If Accepted = vbYes Then - WScript.Echo "Continue..." + Call StopServices End If End If End Sub diff --git a/wsh/services.txt b/wsh/services.txt new file mode 100644 index 0000000..8c1d422 --- /dev/null +++ b/wsh/services.txt @@ -0,0 +1,32 @@ +; Which Windows Services can you safely disable in Windows 11/10?: https://www.thewindowsclub.com/which-windows-10-services-safe-to-disable + +dmwappushservice Device Management Wireless Application Protocol (WAP) Push message Routing Service +;AVCTP service +BDESVC BitLocker Drive Encryption Service +bthserv Bluetooth Support Service +Browser Computer Browser +;Connected User Experiences and Telemetry +DPS Diagnostic Policy Service +WdiServiceHost Diagnostic Service Host +WdiSystemHost Diagnostic System Host +DiagTrack Diagnostic Tracking Service +Trkwks Distributed Link Tracking Client +;Downloaded Maps Manager +;File History Service +IEEtwCollectorService Internet Explorer ETW Collector Service +iphlpsvc IP Helper +;Infrared monitor service +SharedAccess Internet Connection Sharing +Netlogon Netlogon +PcaSvc Program Compatibility Assistant Service +;Spooler Print Spooler +WPCSvc Parental Control +RemoteRegistry Remote Registry +seclogon Secondary Logon +lmhosts TCP/IP NetBIOS Helper +TabletInputService Touch Keyboard and Handwriting Panel Service +WerSvc Windows Error Reporting Service +stisvc Windows Image Acquisition +;Windows Camera Frame Server +;Windows Insider Service +WSearch Windows Search