Skip to content

Instantly share code, notes, and snippets.

@ayancey
Created December 8, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayancey/5849e53b4067991c6d132a63cb21f910 to your computer and use it in GitHub Desktop.
Save ayancey/5849e53b4067991c6d132a63cb21f910 to your computer and use it in GitHub Desktop.
'''''''''''''''''''''''''''''
' 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("Wscript.shell")
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
MsgBox(cname)
' 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