@ECHO OFF CLS SETLOCAL ENABLEDELAYEDEXPANSION SET /A RETRY_IMAP=0 SET /A MAX_RETRIES=3 SET EXCH_IMAP= MSExchangeImap4 REM To check current status of the service. :check_imap SC QUERY %EXCH_IMAP% | FIND "RUNNING" >NUL IF %ERRORLEVEL%==0 ( ECHO Exchange IMAP4 Service is Running. GOTO end ) REM To start the service if the status is stopped. ECHO Exchange IMAP4 Service is Stopped. SC START %EXCH_IMAP% TIMEOUT /T 10 >NUL REM To re-check the service status again for confirmation. SC QUERY %EXCH_IMAP% | FIND "RUNNING" >NUL IF %ERRORLEVEL%==0 ( ECHO Exchange IMAP4 Service is Running. GOTO end ) REM Retrying to start the service with a maximum of 3 retries only. SET /A RETRY_IMAP+=1 IF !RETRY_IMAP! LSS %MAX_RETRIES% ( ECHO Retrying Start %EXCH_IMAP% (Attemp: !RETRY_IMAP!). GOTO check_imap ) ELSE ( ECHO Max Retries Reached for %EXCH_IMAP%, will stop retrying. GOTO end ) :end EXIT |
Apr 15, 2025
Windows 10/11 : Batch File to Start and Check Windows Services
Oct 3, 2024
Command : Rename Multiple Files via Batch Script
@echo off setlocal enabledelayedexpansion set prefix="[Filename]" set count=1 for %%f in (*.[Extension]) do ( set formattedCount=00!count! set formattedCount=!formattedCount:~2! ren "%%f" "!prefix!!formattedCount!.[Extension]" set /a count+=1 ) echo Done renaming files. pause |
Nov 8, 2023
Batch : Rename Hostname via Batch File
:asktorename REM To ask whether to Rename the Hostname or not. ECHO. ECHO. ECHO. ECHO ╔═════════════════════════════════════════╗ ECHO ║ RENAMING THE HOSTNAME ║ ECHO ╚═════════════════════════════════════════╝ ECHO. CHOICE /M "──────────────► DO YOU WANT TO RENAME THE HOSTNAME " IF ERRORLEVEL 2 GOTO eof IF ERRORLEVEL 1 GOTO askforname GOTO eof REM -------------------------------------------------------------------------------------- :askforname REM To ask User for the preferred hostname. ECHO. ECHO. SET /P NEWNAME="PLEASE TYPE THE NEW HOSTNAME: " ECHO. ECHO " ► ► ► THE NEW HOSTNAME IS ───► %NEWNAME%" CHOICE /M " ► ► ► IS THIS CORRECT " IF ERRORLEVEL 2 GOTO asktorename IF ERRORLEVEL 1 GOTO dorenhost GOTO eof REM -------------------------------------------------------------------------------------- :dorenhost REM To proceed Rename the Hostname as per Input by User. ECHO. ECHO " ► ► ► OK, RENAMING HOSTNAME → %NEWNAME%, PLEASE WAIT..." WMIC COMPUTERSYSTEM where name="%COMPUTERNAME%" CALL RENAME name="%NEWNAME%" TIMEOUT /t 3 /NOBREAK ECHO. ECHO " ► ► ► RENAMING HOSTNAME COMPLETE" ECHO. ECHO "THE NEW HOSTNAME WILL TAKE EFFECT AFTER COMPUTER RESTART" TIMEOUT /t 5 /NOBREAK GOTO eof REM -------------------------------------------------------------------------------------- :eof START SHUTDOWN /r /f /t 10 COLOR >NUL CHCP 437 EXIT /b |
Jan 6, 2023
PowerShell : Command Line
PowerShell Command for Windows 10 22H2.
1) Enable/Install SMB v1 Client Protocol.
Enable-WindowsOptionalFeature -Online -FeatureName "SMB1Protocol-Clinet" -All
2) Mount ISO image file.
Mount-DiskImage -ImagePath "%ISO_FILE_PATH%"
3) Unmount/Eject ISO Image file.
Dismount-DiskImage -ImagePath "%ISO_FILE_PATH%"
4) To run a PowerShell Script File (.ps1) inside a Batch File.
POWERSHELL.EXE -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%POWERSHELL_SCRIPT_FILE%""' -Verb RunAs}"
!!! HAPPY COMPUTING !!!
Jan 5, 2023
Batch : Rename Hostname
Inside batch file, create the following command line to rename the current computer with a new hostname.
WMIC COMPUTERSYSTEM where name="%COMPUTERNAME%" CALL RENAME name="%NEWPCNAME%"
Need to restart computer to take effect.
!!! HAPPY COMPUTING !!!
Apr 27, 2022
Batch - IF Calculation
Batch File Command "IF"
- EQU = Equal to...
- NEQ = Not Equal to...
- LSS = Less than...
- LEQ = Less than or Equal to...
- GTR = Greater than...
- GEQ = Greater than or Equal to...
Feb 5, 2017
Windows 10 - Remove Provisioned Apps
Now my last post was to remove those built-in apps, but later I found it was still in Windows 10 when another user logged-in. After much googling and studying MSDN and TechNet, I found a powershell script and I wrote some sample of my own.
First of all, you still need to run the previous powershell script to ensure that all users are not provisioned with the built-in apps, just in case I have re-posted those script here for your references.
Get-AppxPackage -allusers *3dbuilder* | Remove-AppxPackage
Get-AppxPackage -allusers *windowsalarms* | Remove-AppxPackage
Get-AppxPackage -allusers *zunevideo* | Remove-AppxPackage
Get-AppxPackage -allusers *officehub* | Remove-AppxPackage
Get-AppxPackage -allusers *skypeapp* | Remove-AppxPackage
Get-AppxPackage -allusers *getstarted* | Remove-AppxPackage
Get-AppxPackage -allusers *zunemusic* | Remove-AppxPackage
Get-AppxPackage -allusers *solitairecollection* | Remove-AppxPackage
Get-AppxPackage -allusers *bingfinance* | Remove-AppxPackage
Get-AppxPackage -allusers *bingnews* | Remove-AppxPackage
Get-AppxPackage -allusers *people* | Remove-AppxPackage
Get-AppxPackage -allusers *windowsphone* | Remove-AppxPackage
Get-AppxPackage -allusers *commsphone* | Remove-AppxPackage
Get-AppxPackage -allusers *bingsports* | Remove-AppxPackage
Get-AppxPackage -allusers *windowsstore* | Remove-AppxPackage
Get-AppxPackage -allusers *bingweather* | Remove-AppxPackage
Get-AppxPackage -allusers *xboxapp* | Remove-AppxPackage
Get-AppxPackage -allusers *twitter* | Remove-AppxPackage
Get-AppxPackage -allusers *office.sway* | Remove-AppxPackage
Get-AppxPackage -allusers *xboxonesmartglass* | Remove-AppxPackage
Get-AppxPackage -allusers *messaging* | Remove-AppxPackage
|
After you have completed the above script, now you can run the 2nd script as below, also you can choose which apps you want to retain back.
Remove-AppxProvisionedPackage -online -packagename
Microsoft.3DBuilder_11.0.47.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.BingWeather_4.9.51.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.Getstarted_3.11.3.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.Messaging_2.7.1001.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.MicrosoftOfficeHub_2015.6801.23751.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.MicrosoftSolitaireCollection_3.9.5100.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename Microsoft.Office.OneNote_2015.6868.57981.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.OneConnect_1.1605.17.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.People_2016.709.155.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.People_2016.709.155.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.SkypeApp_11.4.86.0_neutral_~_kzf8qxf38zg5c
Remove-AppxProvisionedPackage -online -packagename
Microsoft.StorePurchaseApp_1.0.454.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.WindowsAlarms_2016.622.2118.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename microsoft.windowscommunicationsapps_2015.6868.41201.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.WindowsFeedbackHub_1.3.1741.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename Microsoft.WindowsMaps_2016.701.2235.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.WindowsStore_11606.1001.394.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.XboxApp_2016.623.248.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.XboxIdentityProvider_2016.616.818.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.ZuneMusic_2019.6.19261.0_neutral_~_8wekyb3d8bbwe
Remove-AppxProvisionedPackage -online -packagename
Microsoft.ZuneVideo_2019.6.19281.0_neutral_~_8wekyb3d8bbwe
|
I find this to be useful especially when you want to create a consistent operating environment (COE) for a corporate/enterprise system.
!!! HAPPY SCRIPTING !!!
!!! HAPPY CHINESE NEW YEAR !!!
Oct 6, 2015
Batch - Batch to EXE Converter
Ever created a batch file (.bat) that you don't want other people to mess with it ? Or simply you just wanted to hide the commands ?
There's a lot of free tools available when you google it but none are free for commercial use or there's no limitation on usage. I'm recommending using F2KO utility to convert your batch file into an .exe file format.
It's very simple to use and no installations required, do give it a try and there's others of cool stuff to in his website.
Jun 22, 2015
Batch - Join Domain Batch File
- To avoid typography error in domain name.
- To avoid mismatch username and password when joining to domain.
netdom join %COMPUTERNAME% /domain:[domain name] /userd:[domain\username]
/passwordd:[password]
|
- %COMPUTERNAME% = Computer's Name, a variables.
- [domain name] = The actual domain name (eg. google.com)
- [domain\username] = The actual domain's username (eg. google.com\administrator)
- [password] = The username's password.
Note that the "netdom" command is NOT AVAILABLE in standard Windows 7 OS, it must be installed separately. Download & install Microsoft Remote Server Administration Tools (RSAT).
Once installed you need to enable the "AD DS Command-Line Utility" before you can start using the "netdom" command.
Jun 1, 2015
Batch - Verify Model & Install Drivers
Subsequent batch command is to call the HP SSM built-in command to install the respective drivers automatically.
REM Check
for valid model & proceed to install.
SET
INPUT=Model
for /f
"tokens=1,* delims==" %%i IN ('wmic computersystem get %INPUT%
/VALUE ^| FIND /I "%INPUT%="') do set Model=%%j
ECHO Found the following model : %Model%
IF
"%Model%" EQU "HP Compaq 6200 Pro SFF PC" GOTO valid
IF
"%Model%" EQU "HP Compaq Pro 6300 SFF" GOTO valid
IF
"%Model%" EQU "HP Elite 8300 USDT" GOTO valid
IF
"%Model%" EQU "HP ProDesk 600 G1 SFF" GOTO valid
IF
"%Model%" EQU "HP EliteDesk 800 G1 SFF" GOTO valid
IF
"%Model%" EQU "HP EliteBook 2560p" GOTO valid
IF
"%Model%" EQU "HP ProBook 6470b" GOTO valid
IF
"%Model%" EQU "HP EliteBook 2570p" GOTO valid
IF
"%Model%" EQU "HP EliteBook Folio 9470m" GOTO valid
IF
"%Model%" EQU "HP ProBook 640 G1" GOTO valid
IF
"%Model%" EQU "HP EliteBook 820 G1" GOTO valid
IF
"%Model%" EQU "HP EliteBook 840 G1" GOTO valid
IF
"%Model%" EQU "HP EliteBook 1040 G1" GOTO valid
IF
"%Model%" EQU "HP Z230 SFF Workstation" GOTO valid
|
May 29, 2015
Batch - Consistent Operating Environment
To my understanding, COE means that all computers must be running on a same OS, same applications/programs, same interface and same settings/configurations.
It is very hard achieve and yet simple to implement, the most troublesome thing is to make it compatible with all kind of models. Put it simple (using HP's model series and ranges), a single image to cater for almost all types of models yet the ability to install it's own drivers, applications etc. and make it function/working.
Luckily HP (Hewlett-Packard) does have a tools to help us in this tasks, but drawback would be custom scripting/batch file(s) have to be created & tested to ensure the workability of it.
It is called the SSM (Softpaq System Manager), what this tools does is to ensure the reliability of the downloaded drivers and the ability to differentiate the models being install and subsequently install the relevant drivers for the system.
I'm in the midst of compiling a "Universal Master Image" capable of installing the drivers base on the models detected and of course the customised settings required for the specific corporate environment.
Although I can't disclose much details of it, but I will post the scripts and hopefully might be usefull to someone.
May 26, 2015
MS-DOS - Batch File Color Codes
Colour attributes are specified by 2 of the following digits, each digit can be any value as below :-
0 = Black
8 = Gray
1 = Blue
9 = Light Blue
2 = Green
A = Light Green
3 = Aqua
B = Light Aqua
4 = Red
C = Light Red
5 = Purple
D = Light Purple
6 = Yellow
E = Light Yellow
7 = White
F = Bright White
Example : COLOR 0B
* A black background colour with Light Aqua text.