Solved

Sending multiple "net send" commands

Posted on 2003-10-28
16
366 Views
Last Modified: 2008-02-01
I need to build a simple broadcasting tool to send net send messages to a specific group of computers (based on username).  No this isn't for spamming poor internet users but i would imagine that the application would work similarly to those advertising spams.

I have about 1000 internal users to send the messages to, some will be online and some will be offline.  I have a vbscript right now that will do the net sends but going through the list of names sequentially would take too much time.  I need to be able to send all these messages as quickly as possible as it is being used as an outage notification system.  I am a newbie to vbscript so i'm not sure if theres a way to do this in Vbscript besides creating different shells to perform the net sends?  This seems very messy and memory intensive though.

Perhaps there's a better way to do this in VB instead?  Perhaps using NetMessageBufferSend fucntion in the  Netapi32 api?  But I am stuck at the same situation in that i need to find a way in VB to send these messages all at once and not one at a time to each user.  Is multi-threading a possbility?

0
Comment
Question by:deuces
  • 8
  • 4
  • 2
  • +2
16 Comments
 
LVL 1

Assisted Solution

by:osp70
osp70 earned 75 total points
ID: 9636828
It's been a while since I've played with net send but in an office I did some work I did play with this a bit.  I remember that I could send a message to the entire domain by doing > net send * <message>.  I'm assuming that with 1000 users you have more than one domain, but I wonder if > net send domainName.* <message> would work?  That way you would just have to iterate through a list of domain names.  

Hope this helps a bit
osp70
0
 
LVL 15

Expert Comment

by:SRigney
ID: 9637769
What I have done when needing to send a lot is I wrote a single batch file that included all of the desired user and used shell to call the one batch file.  It runs much faster than using shell for each message.
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 9638012
0
 

Author Comment

by:deuces
ID: 9639218
osp70: using the domain names won't work in this situation because i need to send to a subset of users.   Currently i am able to pull this list out from our active directory using a script.  

SRigney: just making sure i understand.... so my one batch file would contain the 1000 net send commands (1 net send for each 1000 user)?  This would still take awhile to run though wouldn't it?  Thinking that it would run iteratively thus if it was 1-3 seconds for each net send then 1000 users would take up nearly 50 mins to process?
0
 

Author Comment

by:deuces
ID: 9639269
Mikal613:  Sorry i don't quite understand the linking question.  It tells me how to run net time command without stopping for user prompt and about the sleep command?  I don't really see how i can uses these commands here?
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9641003
Yes, you can send using NetMessageBufferSend:
Private Declare Function NetMessageBufferSend Lib _
  "NETAPI32.DLL" (yServer As Any, yToName As Byte, _
  yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
Private Const NERR_Success As Long = 0&
Public Function SendMessage(RcptToUser As String, _
   FromUser As String, BodyMessage As String) As Boolean

   Dim RcptTo() As Byte
   Dim From() As Byte
   Dim Body() As Byte

   RcptTo = RcptToUser & vbNullChar
   From = FromUser & vbNullChar
   Body = BodyMessage & vbNullChar

   If NetMessageBufferSend(ByVal 0&, RcptTo(0), ByVal 0&, _
        Body(0), UBound(Body)) = NERR_Success Then
     SendMessage = True
   End If

End Function
Private Sub Command1_Click()
    Dim RetVal As Boolean
    'use a loop to send to 1000 user
    RetVal = SendMessage("Utente", "FromUser", "BodyText")
End Sub

OR, you can just use shell.
thanks & cheers
0
 

Author Comment

by:deuces
ID: 9644581
fantasy1001:  yes I've tried using the API like that to send messages and it works except that when net send encounters a user that doesn't exist on the network, it hangs for like 30 seconds.  Any ideas how i can make it timeout for users that aren't connected to the network (because my list pulls out group memebers but not all will be logged on)?  

I think that's probably the more pressing issue.  I may have been wrong about the speed of sending net sends (thinking each take at least 1-3 seconds) so i'm gonna do a bit more testing on that first.
0
 

Author Comment

by:deuces
ID: 9645912
Ok after some testing it seems maybe the net sends are fast enough but there is still an issue on how to deal with net sends to non-online clients.

When using shell commands to send each message, a user who is not online will cause the shell process to sit for a long while.  The good thing though is that VB6 doesn't wait for this hung process to finish and continues to send the other messages/processes.  But i am worried that creating these extra "hanging" processes will take up memory (even if it is only temporary), especially since looking through task manager each shell takes up 1K (which could add up if my list contains lots of disonnected users).

Curious if anyone knows how to make the shell command timeout?  I think .net has this command but i'm using vb6.   or any other suggestions?  When using the win API to send the "net send" it would wait for each process to finish which isn't something that will work here.

shellstr = "net send " & names1(lngIndex) & " Sending you a message"
RetVal = Shell(shellstr, vbHide)

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Expert Comment

by:SRigney
ID: 9645938
I wonder if you could work around that by attempting a ping on the user.  If the ping fails then don't send the message.
0
 

Author Comment

by:deuces
ID: 9646051
i'm using netbios user names.  anyway to ping this?  i only know of doing it through computer names
0
 

Author Comment

by:deuces
ID: 9649509
Found this:

http://www-tcsn.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20741927.html

I'm curious about the making an .exe do to the netsend then have a timer control to release (act like a timeout?).  I don't quite get how to create the timer callback.  Am i putting the net send in the actual timer sub routine?

0
 
LVL 15

Expert Comment

by:SRigney
ID: 9650075
I'm not a networking person.  Does Active directory give you a list of who is logged in?
0
 
LVL 5

Expert Comment

by:fantasy1001
ID: 9654753
Try this with timer
Use a public seed for looping each user in an array

Private Declare Function NetMessageBufferSend Lib _
  "NETAPI32.DLL" (yServer As Any, yToName As Byte, _
  yFromName As Any, yMsg As Byte, ByVal lSize As Long) As Long
Private Const NERR_Success As Long = 0&
Public seed as integer
Public myUser() as string

Public Function SendMessage(RcptToUser As String, _
   FromUser As String, BodyMessage As String) As Boolean

   Dim RcptTo() As Byte
   Dim From() As Byte
   Dim Body() As Byte

   RcptTo = RcptToUser & vbNullChar
   From = FromUser & vbNullChar
   Body = BodyMessage & vbNullChar

   If NetMessageBufferSend(ByVal 0&, RcptTo(0), ByVal 0&, _
        Body(0), UBound(Body)) = NERR_Success Then
     SendMessage = True
   End If
End Function

Private Sub Command1_Click()
    timer1.enabled = true
End Sub

Private sub Form_Load()
    timer1.enabled = false
    timer1.interval = 500   'give 0.5 second

    ' set your username in array myUser()
    myUser() = ("john", "google"....)
    seed = 0
End Sub

Private Sub Timer1_Timer()
    Dim RetVal As Boolean
    RetVal = SendMessage(myUser(seed), "FromUser", "BodyText")
    seed = seed + 1
End Sub


Thanks
~ fantasy ~
0
 

Author Comment

by:deuces
ID: 9659543
SRigney:
There isn't a way that i know of to check if a username is online unfortunately.

Fantasy:
Interesting concept....  only problem is this is still sequential.  if possible i would only want the timing out to happen only to net sends that do not find a user.  I will tinker with this idea though and see if it can be used
0
 
LVL 15

Accepted Solution

by:
SRigney earned 175 total points
ID: 9670476
Well, you could use activeX exe and create 1 session for each.  But as you have stated with thousands that will eat up a ton of memory.   Maybe you could cut the list down and create 10 sessions so you break the list up but aren't using too much memory.

Another alternative is to use 10 sessions and have each one get the next available somehow.   You could put all of the names in a database and mark them as attempted as you go.  Therefore you would have 10 sessions that are each grabbing the next one and a timeout won't slow the entire process down as much.  However, if there are a lot of people that are not logged on you would still have a problem with it going slow.

This may be an instance that it is better for you to write a completely custom application.  Something that comes on when a rep logs in and can push a message out to everyone.  At my job we use Jabber(tm) and do something similar.  I was not the developer for it, but something like that may work for you.
0
 

Author Comment

by:deuces
ID: 9808680
It looks like there isn't going to be a straight forward way of making this work the way i want it to (for using the net send command).  I'm going to have to explore other alternatives.  The best method was to actually blast through with shell commands for each net send.  For some reason it ran the fastest versus any Win API calls.  Using a pool could work in a custom app but exploring other possibilities is probably the way to go.

So I'm going to split some points up osp70 and SRigney. Thanks guys for giving it a shot

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

13 Experts available now in Live!

Get 1:1 Help Now