bsharath
asked on
Get an error with this vbs
Hi,
I get the below error with this vbs that checks each machine for storage space.
-------------------------- -
Windows Script Host
-------------------------- -
Script: D:\Run_Via_ScheduleTask\Sc an_HDD_Ema il\Space HDD Excellent Free and total html.vbs
Line: 111
Char: 5
Error: 0x80041013
Code: 80041013
Source: (null)
-------------------------- -
OK
-------------------------- -
Can anyone help fix this issue.
regards
Raja
I get the below error with this vbs that checks each machine for storage space.
--------------------------
Windows Script Host
--------------------------
Script: D:\Run_Via_ScheduleTask\Sc
Line: 111
Char: 5
Error: 0x80041013
Code: 80041013
Source: (null)
--------------------------
OK
--------------------------
Can anyone help fix this issue.
regards
Raja
strInputFile = "D:\Run_Via_ScheduleTask\Scan_HDD_Email\pcs.txt"
strOutputFile = "D:\Run_Via_ScheduleTask\Scan_HDD_Email\hard_disk_space.csv"
Dim arrDrives
arrDrives = Array("C","D","E","F")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const adVarChar = 200
Const MaxCharacters = 255
const FREESPACE_SIZE_LIMIT = 1
Set Servers2Notify = CreateObject("Scripting.Dictionary")
Dim DataList
Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Server", adVarChar, MaxCharacters
For Each strDrive In arrDrives
DataList.Fields.Append strDrive & " Size", adVarChar, MaxCharacters
DataList.Fields.Append strDrive & " Free Space", adVarChar, MaxCharacters
DataList.Fields.Append strDrive & " Percent Free", adVarChar, MaxCharacters
Next
DataList.Open
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading)
While Not objInputFile.AtEndOfStream
strComputer = objInputFile.ReadLine
Get_Free_Space_Details(strComputer)
Wend
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
strHeader = """SERVER"""
For Each strDrive In arrDrives
strHeader = strHeader & ",""" & strDrive & " SIZE"",""" & strDrive & " FREE SPACE"",""" & strDrive & " PERCENT FREE"""
Next
objOutputFile.WriteLine strHeader
DataList.MoveFirst
While Not DataList.EOF
strLine = """" & DataList("Server") & """"
For Each strDrive In arrDrives
strLine = strLine & ",""" & DataList(strDrive & " Size") & """,""" & DataList(strDrive & " Free Space") & """,""" & DataList(strDrive & " Percent Free") & """"
Next
objOutputFile.WriteLine strLine
DataList.MoveNext
Wend
DataList.Close
objOutputFile.Close
EmailServers
sub EmailServers()
strCaption = "The following servers has less than 1 GB disk space in drive C:"
for each key in Servers2Notify.Keys
strResult = strResult + vbNewLine & key & " - " & Servers2Notify.item(key)
Next
if strResult = "" then
exit sub
end if
strResult = strCaption & strResult
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "shara@plc.com"
MessageSubject = "Disk Space Notification"
MessageBody = strResult
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "","",true,false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add(myRecipient)
newMail.Send
End If
Set ol = Nothing
end sub
'MsgBox "Done. Please see " & strOutputFile
'==============
Sub Get_Free_Space_Details(strComputer)
DataList.AddNew
DataList("Server") = strComputer
If Ping(strComputer) = True Then
On Error Resume Next
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number = 0 Then
Err.Clear
On Error GoTo 0
For Each strDrive In arrDrives
Set colDisks = objWMIService.ExecQuery("Select FreeSpace,Size From Win32_LogicalDisk Where DriveType = 3 And DeviceID = '" & strDrive & ":'")
For Each objDisk In colDisks
on error resume next
intFreeSpace = objDisk.FreeSpace
intTotalSpace = objDisk.Size
pctFreeSpace = intFreeSpace / intTotalSpace
DataList(strDrive & " Size") = Round(intTotalSpace / 1024 / 1024 / 1024, 2) & " GB"
DataList(strDrive & " Free Space") = Round(intFreeSpace / 1024 / 1024 / 1024, 2) & " GB"
DataList(strDrive & " Percent Free") = FormatPercent(pctFreeSpace)
if UCase(strDrive) = "C" then
if FREESPACE_SIZE_LIMIT > Round(intFreeSpace / 1024 / 1024 / 1024, 2) then
Servers2Notify.Add strComputer, Round(intFreeSpace / 1024 / 1024 / 1024, 2)
end if
end if
Next
Next
Set objDisk = Nothing
Set colDisks = Nothing
Set objWMIService = Nothing
Else
For Each strDrive In arrDrives
DataList(strDrive & " Size") = "WMI ERROR"
DataList(strDrive & " Free Space") = "WMI ERROR"
DataList(strDrive & " Percent Free") = "WMI ERROR"
Next
End If
Else
For Each strDrive In arrDrives
DataList(strDrive & " Size") = "OFFLINE"
DataList(strDrive & " Free Space") = "OFFLINE"
DataList(strDrive & " Percent Free") = "OFFLINE"
Next
End If
DataList.Update
End Sub
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
Try changing the colon in the where clause to a semi-colon.
should be
Where DriveType = 3 And DeviceID = '" & strDrive & ";'
should be
Where DriveType = 3 And DeviceID = '" & strDrive & ";'
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ThinkPaper
Can you add the code to the main one please
Can you add the code to the main one please
ASKER
Chris tried but still same error
jmiller1979 i get this error
-------------------------- -
Windows Script Host
-------------------------- -
Script: D:\Run_Via_ScheduleTask\Sc an_HDD_Ema il\Space.v bs
Line: 110
Char: 145
Error: Unterminated string constant
Code: 800A0409
Source: Microsoft VBScript compilation error
-------------------------- -
OK
-------------------------- -
jmiller1979 i get this error
--------------------------
Windows Script Host
--------------------------
Script: D:\Run_Via_ScheduleTask\Sc
Line: 110
Char: 145
Error: Unterminated string constant
Code: 800A0409
Source: Microsoft VBScript compilation error
--------------------------
OK
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks sorry for the delay
This is fine, (as far as I can see) so perhaps try retyping each line in full again and see if there was a control character in there, (in full including spaces at start / end):
111 as For Each strDrive In arrDrives
and
4 as arrDrives = Array("C","D","E","F")
for example.
Chris