Solved

script to netsend or email disk name daily

Posted on 2006-11-15
6
444 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
withoutTen challenge 14 88
copyEndy  challenge 15 55
Installed softare without GUID 6 54
how to update exe applicatio from internet ? 6 39
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is about my first experience with programming Arduino.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now