0

I'm trying to make a VBS script that can say your username on your computer by using TTS.

Dim ttsbot
set sapi = wscript.createobject("SAPI.Spvoice")
Sapi.speak "*username here*"

Can someone help me on how to get the user's name and assign it as a variable, so it can be pronounced from the TTS bot?

Thanks.

P1tus
  • 11

2 Answers2

0

As asked... Speak UserName:

Set Sapi = WScript.CreateObject("SAPI.Spvoice")
Set oWSH = CreateObject("Wscript.Shell")
UserName = oWSH.RegRead("HKCU\Volatile Environment\UserName")
Sapi.Speak UserName

Alternative... Speak DisplayName:

Set Sapi = WScript.CreateObject("SAPI.Spvoice")
Set oWSH = CreateObject("Wscript.Shell")
LoggedOnDisplayName = oWSH.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\SessionData\1\LoggedOnDisplayName")
Sapi.Speak LoggedOnDisplayName
LesFerch
  • 1,540
  • 2
  • 5
  • 21
0

Refer to this How to get username with vbs. You can write like this code :

UserName = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%USERNAME%")
createobject("SAPI.Spvoice").Speak UserName

Or like this example too :

UserName = CreateObject("WScript.Network").UserName
createobject("SAPI.Spvoice").Speak UserName
Hackoo
  • 18,337
  • 3
  • 40
  • 70