Enviromental Variables
I have been trying to come up with a way to check if a user is logged on to a Vista computer on the domain via the %USERNAME% environment variable. In XP when a user is not logged on no name is returned. In vista if no one is logged into the machine it returns the username of the person running the script. The script is supposed to check for a logged on users, and if no username is found, shut the computer down, the problem is with Vista, a username is always returned, even if no one is logged on. The Environment variable does not clear at log off. I am running this script on the Vista OS. it works fine on older versions of OS. Any suggestions? Here is the script:option ExplicitDim objWMIService, objComputer, colComputer, strComputer, strUser, myFSO, WriteStuffstrComputer = "."Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!\\" _& strComputer & "\root\cimv2")Set colComputer = objWMIService.ExecQuery _("Select * from Win32_ComputerSystem")set myFSO = CreateObject("Scripting.FileSystemObject")set WriteStuff = myFSO.OpenTextFile("test.txt",8,True)For Each objComputer in colComputer'Wscript.Echo objComputer.UserName & " is logged on"strUser = objComputer.UsernameWritestuff.Writeline(strUser)NextWritestuff.Close
June 9th, 2008 5:00pm

Hi, Regarding the programming issues, I suggest submitting them to MSDN Forum. The support professionals there are better qualified to assist you. For you convenience, Ive listed the website of MSDN Forum: MSDN Forumhttp://forums.microsoft.com/msdn/default.aspx?siteid=1 Thank you for your understanding.
Free Windows Admin Tool Kit Click here and download it now
June 12th, 2008 5:22am

Thank You, I will post on there and see if anyone has any suggestions.
June 12th, 2008 5:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics