Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB 6 Net Send question 1

Status
Not open for further replies.

knighthawke

IS-IT--Management
Mar 22, 2005
9
US
Greetings all,

I have just searched the site and did not see a solution that worked for me concerning this issue.

I am trying to use the Net Send command in VB6 without any success. I am a rookie so it's OK to laugh at my code but I found this here somewhere but it did not work and I was wondering what I am doing wrong.

Scenario: I have 18 laptops that get checked out and used in a very large Library building. They are supposed to be turned in at midnight but lots of times we have problems finding all the patrons who forget and just keep working. I have set up a batchfile where the Librarians can edit the batch file to include the name of the laptop and the batchfile works just fine. It looks like this:

net send Laptop1 Please return this laptop to the Reference Desk!
net send Laptop2 Please return this laptop to the Reference Desk!

The box pops up and they bring the laptops in.

I want to simplify life for the more technophobic among the Library staff. So I thought I might be able to use check boxes for the Librarians to select which laptops are still out and then click the Go button. The button would check to see which checkboxes are returning a boolean true and Net Send the message to those Laptops.

Of course this is rocket science for me so I decided to work out the individual pieces first. I am simply, at this point trying to get the net send command to send a message to my machine when I click the Go button. I put this code in the button:

Private Sub btnGo_Click()

Call Shell("Net Send " & MyPCName & " Blah Blah Blah")
End

End Sub

The end result, when I run this, is that a command window opens minimized on my PC and the program ends without ever sending me the message. The command window never closes.

Any thoughts?

Thanks,
KH


 
You could try using the API

Code:
'Return vals for NetMessageBufferSend
Private Const NERR_Success As Long = 0&
Private Const NERR_BASE = 2100
Private Const NERR_NameNotFound = NERR_BASE + 173
Private Const NERR_NetworkError = NERR_BASE + 36
Private Const ERROR_ACCESS_DENIED = 5
Private Const ERROR_INVALID_PARAMETER = 87
Private Const ERROR_NOT_SUPPORTED = 50


Private Declare Function NetMessageBufferSend Lib "Netapi32" _
        (ByVal sServerName$, _
        ByVal sMsgName$, _
        ByVal sFromName$, _
        ByVal sMessageText$, _
        ByVal lBufferLength&) As Long
 
Sheco,

Thanks very much for your time. I saw similar code but I did not know what to put for the 2 lines below:

(ByVal sServerName$, _
ByVal sMsgName$, _
ByVal sFromName$, MyPCName
ByVal sMessageText$, Here is my message.

What would the sMsgName$ and sServeName$ lines contain?

Thanks,

KH
 
Well you can either send a popup to a particular machine or to a particular user.

If you send it to a machine then set sServerName to the name of the machine and sMsgName to an empty string.

If you want to do the opposite then do the reverse!

Oh, one more thing, make sure you are sending UniCode strings. To do this explicitly use the StrConv() function.
Example: StrConv(strMyValue, vbUnicode)

Also be aware those code snippets are just used to declare the API function and the return values.

To actually call the function, you need somethng like this: (example shows sending popup to user)
Code:
'Send the popup:
lRet = NetMessageBufferSend("", _
                            StrConv(strToUserName, vbUnicode), _
                            StrConv(strFromName, vbUnicode), _
                            StrConv(strMessage, vbUnicode), _
                            Len(StrConv(strMessage, vbUnicode)))

'check return value
Select Case lRet
    Case NERR_Success
        'MsgBox "Popup sent."
    Case NERR_NameNotFound
        MsgBox "Error sending popup.  [Name not found]"
    Case NERR_NetworkError
        MsgBox "Error sending popup.  [Network error]"
    Case ERROR_ACCESS_DENIED
        MsgBox "Error sending popup.  [Access Denied]"
    Case ERROR_INVALID_PARAMETER
        MsgBox "Error sending popup.  [Invalid Parameter]"
    Case ERROR_NOT_SUPPORTED
        MsgBox "Error sending popup.  [Not Supported]"
    Case Else
        MsgBox "Error sending popup.  [Unexpected error]"
End Select


Also be aware that it can take a few seconds to time out and fail. This is not important if you are making a standard app but you need to be aware of it in case you are making a service.
 
Thanks again for your suggestions.

I am still experiencing a problem however when I fill in the _ areas with the names. For instance when I take the line you gave me and change it as below

StrConv(strToUserName, vbUnicode), username

I immediately get a compile error stating: expected: list separator or )

Thanks again.

KH
 
Oh what I meant for you to try was to replace the string variables with your own.

Hmmm, it is hard to put into words so I will highlight them in red:
Code:
[red]lRet[/red] = NetMessageBufferSend("", _
                            StrConv([red]strToUserName[/red], vbUnicode), _
                            StrConv([red]strFromName[/red], vbUnicode), _
                            StrConv([red]strMessage[/red], vbUnicode), _
                            Len(StrConv([red]strMessage[/red], vbUnicode)))

Oh, and lRet is my variable to hold the return value... yours can be named whatever you like but make sure it is declared As Long.
 
Sheco,

I know how busy you must be. I will continue to work on figuring this out. I'm just doing something wrong. I am going to buy a book.

Thanks again for your help.

KH
 
Dan Appleman writes an excellent book on using the Win32 API from Visual Basic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top