I am trying to get the computer name from the registry and write it to a file. At this point, my function call for obtaining the computer name from registry isn’t working. Any advice would be appreciated.
Option Explicit
On Error Resume Next
Dim regComputerName, ComputerName
Set objShell = WScript.CreateObject("WScript.Shell")
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
regComputerName = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\Computername"
ComputerName = obj.shell.RegRead(regComputerName)
oWrite.WriteLine(ComputerName,C:\text)
Reading registry values is error prone and may require elevated privileges in Windows 7. There’s another way of getting the computer name, very similar to what you are doing right now:
Also, the last line in your script:
oWrite.WriteLine(ComputerName,C:\text)will not work for 2 reasons:C:\texthas to be in quotes, like this:"C:\text.txt"WriteLinelike this instead:oWrite.WriteLine ComputerName, "C:\text.txt"Finally, are you sure you are not referring to VBScript instead of VB in your question?