It doesn't directly answer your question but an Alexander McWilliam from Inverness enlisted into the Royal Artillery in 1864. The transcript may be behind a paywall on findmypast but here are the details. On balance I think it is him.
First name Alexander
Last name McWilliam
Birth year 1845
Birth parish Inverness
Birth town Inverness
Birth county Invernessshire
Birth country Scotland
Service number 54
Regiment Royal Artillery
Year 1864
Attestation date 07 Nov 1864
Attestation age years 19
Attestation service number 54
Attestation corps Royal Artillery
Discharge corps Royal Artillery
Document type Attestation
Archive reference WO 97
Series Wo 97 - Chelsea Pensioners British Army Service Records 1760-1913
Box 3403
Box record number 43
Archive The National Archives
Country Scotland
Record set British Army Service Records
Category Military, armed forces & conflict
Subcategory Regimental & Service Records
Collections from Great Britain, Scotland
https://www.findmypast.co.uk/transcript?id=GBM/WO97/3403/157871