"Mario - Roma" <mario@newsgroup> wrote in message
news:eQZT8kf7KHA.5412@newsgroup
> We use the following VBscript code to get the username of the user:
>
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set colItems = objWMIService.ExecQuery("Select * from
> Win32_ComputerSystem")
> For Each objItem In colItems
> strNomeUtente = objItem.UserName
> If strNomeUtente = "" or IsNull (strNomeUtente) Then
> Wscript.Echo "INVALID User Name"
> Else
> Wscript.Echo "The User Name is: " & strNomeUtente
> End If
> Next
>
> The script works fine in Windows XP and Windows Server 2003.
> In Windows 7 many times the script fails an reports a null value.
> Is there any relevant change in the way VBscript works in windows 7?
> Is there any alternate solution to get the username in Windows 7?
> Regards
> Marius The VB Script Shell gives you a much simpler solution, one that relies on
predefined environmental variables:
Set oWshShell = CreateObject("WScript.Shell")
WScript.Echo oWshShell.ExpandEnvironmentStrings("The User Name is:
%ComputerName%\%UserName%")