Jump to content

Recommended Posts

Posted

just written a little vbs to parse the dhcp logfile for renews after 8pm (i run a short lease)

 

It works very well but am i going about it in the wrong way...

 

how do you do it?

Posted
We use Nightwatchman http://www.1e.com/softwareproducts/nightwatchman/index.aspx

 

which works well if you are running a standard Windows AD network.

 

I thought i would parse the DHCP logfile because that seemed like a good way of not having to tie into AD (we have 3 domains) and people bring in their own laptops etc.

 

Also did'nt go down the route of ping sweeps incase the device (because it may not even be a computer) may not reply to echo requests.

Posted
Deja vu... search the forum for remote shutdown/psshutdown.. :)

 

my aim was not to shutdown the pc's but to identify the serial offenders and stick my foot up their arse ;)

 

I could have just batched a psshutdown for the portion of my subnet outside the fixed ip range but being a control freak i like the idea of knowing whats going on.

 

The Netsh command can be scheduled to export the DHCP list.

 

the script parses it at source, no exporting

Posted
Oh right, sorry... I misunderstood your original post. I can't think of another way to do this as we have ours shut down and automatically woken up - we urge people not to turn them off as we may need to do maintenance between after-school and shutdown time.
  • 1 month later...
Posted

I have used the Sysinternals psshutdown program (free) and a series of batch files (never got around to sorting scripts) and a scheduler program.

 

We do have a couple of machines that need to be on or staff who work late so I can't have a blanket shutdown.

Posted

I don't know if this is what you're looking for, but I have a script, that you set to run at a given time. This checks which computers are still switched on.

 

It then emails me the details of any that have infringed my script.

Posted

lanview anybody?

we use this to shutdown any pc that is left switched on.

we also use this to monitor pc usage in terms of what pupils are doing whilst logged on.

Another benefit is remote support! we can assist staff where ever they are on site. I have just helped a member of the office staff troubleshoot and application error message. Our new office is thehighest point in the school so you can imagine the time we save visiting staff situated across the other side of the school!

Posted

we use lanview too, i have set all computers to shutdown but this will only shutdown the ones that are not logged on, then later on in the night i have a forced shutdown set which will shutdown even a logged on machine.

we told the staff that if they dont shutdown they could loose there work.

The machines are woke every morning before i come in, plus they have a uptime so i can see how long each machines has been on.

I once found a machine had been on for 21 days.

Posted

ive got a couple of scripts that runs as scheduled tasks that uses down from LS Tools Freeware

at 4pm

 

del loggedin.txt
for /f %%a in ('type comp.log') do (
 	for /f  %%b in ('net view ^| find "\\%%a" /I ') do (
	if exist %%b\c$ (
		pslist %%b | find "explorer" /I && echo %%b >> loggedin.txt
		if errorlevel 1 down %%b /P /Q)))

 

run and shutsdown any machine not logged on. comp.log is a list of computername prefixes we use

 

at 6pm

 

for /f %%a in ('type loggedin.txt') do (
down %%a /P /F /Q )
blat loggedin.txt -to andy@domain -server exchange -f academic\administrator -q -s "forced these computers to shutdown at 6pm"

 

runs and forces any machines that were previously logged on off and emails me the list

Posted

I run a simple AD network and am able to just run a series of .bat files from my dns server via Task Scheduler.

 

example

shutdown -s -m \\midlab01 -t 200 -c "Nightly Shutdown in Progress."

shutdown -s -m \\midlab02 -t 200 -c "Nightly Shutdown in Progress."

shutdown -s -m \\midlab03 -t 200 -c "Nightly Shutdown in Progress."

etc etc.

 

If the machine is on, it pops up a windows with a countdown and a message. If the machine is off, the script delays a few seconds, then skips to the next line of the scipt.

Free and easy for my situation.

Posted

I've scheduled all my machines to call a batch file from the netlogon share at 9:00pm, which in turn calls the shutdown command. It would be very easy to include a small command in the batch file which logs which machines it's turned off into a simple text file.

 

I added this scheduled task automatically by using the AT command in a startup script, that way we can easily change the time, or stop it being called alltogether, or change what happens by changing the batch file. It works 100% reliably, I check the rooms most mornings and never find any PCs on now.

 

Best bit about this solution is it's very easy, and free!

 

Mike.

Posted
I have used the Sysinternals psshutdown program (free) and a series of batch files (never got around to sorting scripts) and a scheduler program.

 

We do have a couple of machines that need to be on or staff who work late so I can't have a blanket shutdown.

 

Ditto - its dead easy

Posted

'deviceStatus_v2-9.vbs.

'A script to check the availability of computers specified in a file, on the network.

'Created 01/05/2007

'By Stewart Knight

 

'Option Explicit is used to prevent the script from running if it comes across an error.

 

 

Option Explicit

 

 

'This is where the variables are declared.

 

Dim objShell, objExec, strTarget, strPingResults, objFSO, objFile

Dim objCreate, strDevice, strComputer, objWMIService, colPings

Dim objPing, objResult, objEmail, objReadFile,inpAddress,inpFileName

Dim objCheckFileExists, objFileSystemObject, objMailAddress, objDictionary

Dim objPersistant, objReadAllErrors, objCompareError, objCheckErrors

Dim strCheck2, strCheck1, strCheck3, strCompare1, strCompare2, strCompare

Dim varLoop

 

 

 

'This is the main section of the script, where all the functions are called.

 

createDictionary

checkFile

checkErrors

compareLogs

mailSend

 

 

 

'This is where the functions are defined.

 

Function execPing

 

'This is the routine that pathpings the computers from the file strTarget.

 

Set objShell = CreateObject("WScript.Shell")

Set objExec = objShell.Exec("pathping " & strTarget)

 

strPingResults = LCase(objExec.StdOut.ReadAll)

If InStr(strPingResults, "reply from") Then

ExecPing = True

Else

ExecPing = False

End If

 

End Function

 

 

 

Function checkFile

 

'This checks that the file for the list of computers exists.

 

 

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")

 

If (objFileSystemObject.FileExists("CS.txt")) Then

objCheckFileExists = True

Else

objCheckFileExists = False

End If

 

'This outputs an error message if the file does not exists, then terminates the script.

 

On Error Resume Next

If objCheckFileExists = False Then

WScript.Echo "Unable to find file"

WScript.Quit

End If

 

'This collect the names of the computers from the file and uses the Function

'execPing to check if they are available.

 

set objFSO = CreateObject("Scripting.FileSystemObject")

set objFile = objFSO.OpenTextFile(inpFileName, 1)

set objCreate = objFSO.CreateTextFile("c:\results.txt", 2)

 

 

 

Do While Not objFile.AtEndOfStream

 

strDevice = objFile.ReadLine

strComputer = "."

 

Set objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

 

Set colPings = objWMIService.ExecQuery _

("Select * From Win32_PingStatus where Address = '" & strDevice & "'")

If Err = 0 Then

Err.Clear

For Each objPing in colPings

If objPing.StatusCode = 0 Then

objResult = strDevice & " available." & "IP Address: " & objPing.ProtocolAddress

Else

objResult = strDevice & " not available."

End If

 

Next

 

Else

Err.Clear

If ExecPing = True Then

GetName

End If

End If

 

objCreate.WriteLine(objResult & ": " & Now)

 

Loop

 

objFile.Close

objCreate.Close

 

'Confirms that pathping has run successfully.

 

wscript.echo "The output has been saved into the file 'results.txt'."

 

End Function

 

 

 

Function checkErrors

 

'This opens a log file of all the computers that have been checked.

'It then checks to see which were unavailable, and stores that information

'in an error file and a dictionary file.

 

set objFSO = CreateObject("Scripting.FileSystemObject")

set objFile = objFSO.OpenTextFile("c:\results.txt", 1)

set objCreate = objFSO.CreateTextFile("c:\errors.txt", 2)

set objDictionary = objFSO.OpenTextFile("c:\Persistant.txt", 8)

 

 

Do While Not objFile.AtEndOfStream

 

strDevice = objFile.ReadLine

If InStr(strDevice, "not") Then objCreate.WriteLine strDevice

If InStr(strDevice, "not") Then objDictionary.WriteLine strDevice

 

Loop

 

objFile.Close

objCreate.Close

objDictionary.Close

 

'Confirms that the procedure has completed, and that the data has been output.

 

wscript.echo "The unavailable computers are listed in the file 'errors.txt.'"

 

End Function

 

 

 

 

Function mailSend

 

'This Checks that there is an email address to email the file to.

 

inpAddress = inputbox("Enter the email address")

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")

 

If inpAddress <> "" Then

objMailAddress = True

Else

objMailAddress = False

End If

 

'This handles the error if there is no email address.

 

On Error Resume Next

If objMailAddress = False Then

WScript.Echo "No email Address was entered, this log has not been emailed."

WScript.Quit

End If

 

'This is the email routine.

 

Set objEmail = CreateObject("CDO.Message")

 

objEmail.Subject = "Unavailable computers"

objEmail.From = "[email protected]"

objEmail.To = inpAddress

objEmail.TextBody = "The computers in the attached file were unavailable when this VB Script was run."

objEmail.AddAttachment "c:\end.txt"

objEmail.Send

 

'Confirms that the email has been sent.

 

WScript.Echo "The list of computers that are not available has been emailed to: " _

& inpAddress

 

End Function

 

 

 

Function createDictionary

 

'The purpose of this is to check if the dictionary file exists,

'if it does not, then it creates one.

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

On Error Resume Next

Set objPersistant = objFSO.OpenTextFile ("c:\persistant.txt", 8)

Set objPersistant = objFSO.CreateTextFile("c:\persistant.txt",8)

 

objPersistant.Close

 

End Function

 

 

 

Function compareLogs

 

'The error log is compare to the dictionary to see if the device has failed before.

'The output is then stored in a file to be emailed to the specified address.

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set strCheck1 = objFSO.OpenTextFile("c:\errors.txt")

Set strCheck2 = objFSO.OpenTextFile("c:\persistant.txt")

Set strCheck3 = objFSO.CreateTextFile("c:\end.txt",2)

 

 

Do While Not strCheck1.atEndOfStream

 

strCompare1 = strCheck1.ReadLine

 

Set strCheck2 = objFSO.OpenTextFile("c:\persistant.txt")

 

Do While Not strCheck2.atEndOfStream

strCompare2 = strCheck2.ReadLine

If inStr(strCompare1,10) = inStr(strCompare2,10) Then strCheck3.WriteLine strCompare2 _

& " Failed again at " & Now

Loop

strCheck2.Close

Loop

 

 

strCheck1.Close

strCheck3.Close

 

 

End Function

 

 

'End of Script

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...