Solved

script to netsend or email disk name daily

Posted on 2006-11-15
6
446 Views
Last Modified: 2012-06-22
Hi,

I need a script that can be set to run daily with task manager that will net send (1st preference) or email (least preferable) the volume name of an attached USB drive.

WHY= I have 12 servers that use USB drive for backups. Usually G: drive.
The drives are named Monday, Tuesday, Wednesday etc. etc.

At 4.00PM I want all the servers to notify our backup admin which drive is attached so that if one site forgot to change the drive over, he can contact them in advance to the backup job failing later in the evening.

THanks a lot.
0
Comment
Question by:viperacom
  • 3
  • 2
6 Comments
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 17947816
Write a VBScript that does the job, then schedule it using Scheduled Tasks.

The FileSystemObject provides objects and methods for you to use to get the volume name.
0
 
LVL 7

Expert Comment

by:yotamsher
ID: 17950733
here is a script similar to what you need:
it sneds through netsend (to * which you have to change) the labels of all removable drives on the computer.
if you need assistance with running it through scheduled tasks, please post here
be sure to run it, with cscript

'-----------------------------------------
'              drives.vbs
'-----------------------------------------

dim filesys, filetxt, getname, path, compname
Set filesys = CreateObject("Scripting.FileSystemObject")
Set Drives = filesys.Drives
Set WshNetwork = WScript.CreateObject("WScript.Network")
compname = WshNetwork.ComputerName
for each DiskDrive in Drives
      if DiskDrive.IsReady then
            DriveLetter = DiskDrive.DriveLetter
            DT = DiskDrive.DriveType
            Volume = DiskDrive.VolumeName
            Select Case DT
                  Case "0" DriveType = "Unknown type of drive"
                  Case "1" DriveType = "Removable drive"
                  Case "2" DriveType = "Fixed drive"
                  Case "3" DriveType = "Network drive"
                  Case "4" DriveType = "CD-ROM drive"
                  Case "5" DriveType = "RAM Disk"
            End Select


            WScript.echo DriveLetter  & ": type=" & DriveType
            if DT = 1 then
                  Dim shell
                  dim command
                  command ="net send * " & Chr(34) &"[" & compname & "] "& DriveLetter  & ": (" & Volume & ") type=" & DriveType & Chr(34)  
                  WScript.echo command
                  Set shell = CreateObject("WScript.Shell")
                  shell.Run command , 1, false
                  Set shell = Nothing
            end if
      end if

next
set WshNetwork = nothing
Set Drives = nothing
set filesys = nothing      
0
 
LVL 1

Author Comment

by:viperacom
ID: 17951823
awesome that works really well.

PS: Can I make it net send "no removable drive" if one is not found?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Author Comment

by:viperacom
ID: 17953093
ahh... problem... the USB hard drives show up as fixed disk.
Tell you what, I know that they are usually G: Drive so can you please show how to make it just send the volumename of G: Drive?

thank you.
0
 
LVL 1

Author Comment

by:viperacom
ID: 17953099
oh sorry, and can it send the amount of free space and filenames contained (there are only ever around 10 files in total).
I am happy to award more pionts
0
 
LVL 7

Accepted Solution

by:
yotamsher earned 500 total points
ID: 17959393
Hey

here is what you asked for
the files part, is looking for files in g:\, not in sub directories

'-----------------------------------------
'              drives-2.vbs
'-----------------------------------------

dim filesys, filetxt, getname, path, compname
Set filesys = CreateObject("Scripting.FileSystemObject")
Set Drives = filesys.Drives
Set WshNetwork = WScript.CreateObject("WScript.Network")
compname = WshNetwork.ComputerName
Set DiskDrive = filesys.Drives("G")
if DiskDrive.IsReady then
      DriveLetter = DiskDrive.DriveLetter
      DT = DiskDrive.DriveType
      Select Case DT
            Case "0" DriveType = "Unknown type of drive"
            Case "1" DriveType = "Removable drive"
            Case "2" DriveType = "Fixed drive"
            Case "3" DriveType = "Network drive"
            Case "4" DriveType = "CD-ROM drive"
            Case "5" DriveType = "RAM Disk"
       End Select


      WScript.echo DriveLetter  & ": type=" & DriveType
      Volume = DiskDrive.VolumeName
      FreeSpace=DiskDrive.AvailableSpace
      dim files
      files = "files: "
      Set objFolder = filesys.GetFolder("g:\")
      Set colFiles = objFolder.Files
      For Each objFile in colFiles
            files = files & objFile.Name & " ,"
      Next

      Dim shell
      dim command
      command ="net send * " & Chr(34) &"[" & compname & "] "& DriveLetter  & ": (" & Volume & ") type=" & DriveType & " ["& FreeSpace & "] free " & files & Chr(34)
      WScript.echo command
      Set shell = CreateObject("WScript.Shell")
      shell.Run command , 1, false
      Set shell = Nothing
end if

set WshNetwork = nothing
Set Drives = nothing
set filesys = nothing    
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question