|
Answer» Hello everyone! I have a good one this time that i need a bit of assistance with. I am looking to create a VBS or BAT file that will ask me for the computer name. Then once the computer name is entered it will return the boot time. Has anyone created this file yet? I WOULD modify the VBS i use to find out the logged in user i just dont have time as i am slammed with other projects here at work, and i am not too familiar with VBS. Below are some examples...
Return remote boot time via command prompt ... simply change "PCNAME" to the correct computer name. Code: [Select]Systeminfo /S PCNAME| find "System Up Time"
This VBS will ask you for the PC name, then tell you who is logged in Code: [Select]strComputer = InputBox("What is your computer name? ie WSCI320CXXX:") Wscript.Echo "The name you entered was " & strComputer 'WScript.echo "The user name will appear in seconds!" On Error Resume Next 'continue when an error occurs Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") If Err.Number <> 0 Then Wscript.Echo "There was a problem locating the computer." Wscript.quit End If On Error GoTo 0 Set colComputer = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem") For Each objComputer In colComputer Wscript.Echo "Logged-on user: " & objComputer.UserName Next As always, your help is greatly appreciated.
-HoFL Actually theres a built-in Batch variable for the computer name
Code: [Select]Systeminfo /S %COMPUTERNAME% find "System Up Time" Hope this helps ,Nick(macdad-)That does help a bit, but that would mean i would have to run it on the local PC. Unfortunately that wouldn't be an option in this case. We are finding our users are waiting over 1 and 2 months to restart their computer. This is causing issues with their daily operations. We want to be able to check how long it's been in between boots to confirm what they are telling us before running around the campus to restart a computer. Is there a way i can create a prompt in a BAT file that will allow me to input the computer name, then have it insert in a variable field of the code?Download the uptime utility from microsoft:
http://support.microsoft.com/kb/232243
You can pass this utiility a computer name.
()d:\>uptime /?
UPTIME, Version 1.01 (C) Copyright 1999, Microsoft Corporation
Uptime [server] [/s ] [/a] [/d:mm/dd/yyyy | /p:n] [/heartbeat] [/? | /help] server Name or IP address of remote server to process. /s Display key system events and statistics. /a Display application failure events (ASSUMES /s). /d: Only calculate for events after mm/dd/yyyy. /p: Only calculate for events in the previous n days. /heartbeat Turn on/off the system's heartbeat /? Basic usage. /help Additional usage information. I appreciate your post. The line below will remotely GET the boot time for me just fine. I just want a way i only have to doubleclick the VBS or BAT and enter the name of the computer i want to know about. I was just trying to make it so i don't have to type or copy and paste the line each time i want to get a PCs boot time.
Code: [Select]Systeminfo /S PCNAME| find "System Up Time"I have done some more research and found what i was looking for... I hope you GUYS ENJOY this...just save it as a VBS file.
Code: [Select]Set objSWbemDateTime = CreateObject("WbemScripting.SWbemDateTime")
strComputer = InputBox ("Enter Machine Name") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems objSWbemDateTime.Value = objOperatingSystem.LastBootUpTime MsgBox "Last Boot Time For " & UCase(strComputer) & " Was: " & objSWbemDateTime.GetVarDate(False) Next
|