Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
' Purpose: Allows you to enter the drive letter of an external drive with a copy of Windows on it, returns computer name
' Requirements: Windows 7 (may support older OSes), Administrator (maybe)
' Written by: Alex Yancey
' Date: December 8, 2016
const HKEY_LOCAL_MACHINE = &H80000002
set objshell = CreateObject("")
computer_name = InputBox("OS drive letter: ", "HDD Computer Name")
' Load hive
objshell.Run "reg.exe load HKLM\tempdefault " & computer_name & ":\Windows\System32\config\SYSTEM", 0, True
' Get registry value for computer name
Set objReg = GetObject("winmgmts:" & _
"{impersonationLevel=Impersonate}!\\" & _
"." & "\root\default:StdRegProv")
objReg.GetStringValue HKEY_LOCAL_MACHINE,"tempdefault\ControlSet001\Control\ComputerName\ComputerName", "ComputerName", cname
' Output
' Unload hive
objshell.Run "reg.exe unload HKLM\tempdefault", 0, True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment