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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA for Netsend - - New guy needs help! 1

Status
Not open for further replies.

CBOIT

IS-IT--Management
Jul 9, 2010
22
US
Hello everyone!
Okay . . . here is the scenario:
My company has a receptionist that needs to be able to send a message to an active user via NET SEND. I am trying to create an HTA so it is a little more "user friendly" for her. Here is what I have so far:

Fair Warning: I borrowed most of the code from someone else, so I have absolutely no idea what some of it does! :)


------------------------------------------------------------

<html>
<head>
<hta:application id = "netsend"
/>
<title>CBO Inner-Office Communicator</title>
<meta http-equiv = "content-script-type" content = "text/vbscript"/>
<script language = "VBScript"
type = "text/vbscript"
>
'<![CDATA[

''= sends mleMSG.value to all checked lbxCOMPUTERS.options[].value
' ============================================================================
Sub doSend()
' MsgBox "action doSend()"

Dim oOpt

For Each oOpt In document.all.lbxCOMPUTERS.options
If oOpt.selected Then
fakeSend oOpt.value, document.all.mleMSG.value
End If
Next
End Sub

''= fakes sending message sMsg to computer sName
' ============================================================================
Sub fakeSend( sName, sMsg )
MsgBox "About to send: " + vbCrLf _
+ sMsg + vbCrLf _
+ "to:" + vbCrLf _
+ sName
End Sub

''= refreshes the HTA page, which includes re-running any Windows_Onload code
' ============================================================================
Sub reloadHTA()
location.reload( True )
End Sub

']]>
</script>
</head>
<body>
<input type = "BUTTON" value = "Clear Form" onclick = "reloadHTA()">
<br>
<br>
Select User:<br>
<select size="1" id = "lbxCOMPUTERS">
<option value = "username1">User One
<option value = "username2">User Two
<option value = "username3">User Three
</select> <br>
<br>
Enter Message:<br>
<textarea id = "mleMSG"></textarea>
<br>
<br>

<input type = "BUTTON" value = "Send" onclick = "doSend()">


</body>
</html>

------------------------------------------------------------

Any help would be greatly appreciated!


[&infin;]MP
 
what is your issue at the moment? what is your current HTA not doing which it should? which parts of the code you you not understand?

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Mr. Movie -
Well, the HTA isn't actually performing the action of Netsending. :(

[&infin;]MP
 
can you see this subroutine?

''= fakes sending message sMsg to computer sName
' ============================================================================
Sub fakeSend( sName, sMsg )
MsgBox "About to send: " + vbCrLf _
+ sMsg + vbCrLf _
+ "to:" + vbCrLf _
+ sName
End Sub

this is being called when the user clicks on the button

<input type = "BUTTON" value = "Send" onclick = "doSend()">

because the doSend() subroutine calls, in turn, the fakeSend() subroutine.

The fakeSend() subroutine takes two parameters, one is the message text, the other is the target machine.
At the moment the fakeSend() subroutine just displays a message saying it is thinking about doing the send.

I could suggest that you update the fakeSend() subroutine so that it actually calls the NetSend command. You could do this by using the WshShell "Wscript.Shell" objects 'Run' method.

Set WshShell = CreateObject("Wscript.Shell")
intReturn = WshShell.Run("%comspec% /c NET SEND " & sName & " " & sMessage)
Msgbox "return code = " & CStr(intReturn)
Set WshShell = Nothing


I have, of course, not got the shell syntax for NET SEND in the correct format?

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Thank you very much, Mr. Movie! I will try my absolute hardest to figure out the implementation, and post the results! :)

[&infin;]MP
 
Okay, upon implementation I receive this:

Line: 30
Char: 2
Error: Type Mismatch
Code: 0

Character 2 on line 30 is:
------------------------------------------------------------
intReturn = WshShell.Run("%comspec% /c NET SEND " & lbxCOMPUTERS & " " & mleMSG)
------------------------------------------------------------


Here is my full code, with your last suggestion implemented:

------------------------------------------------------------
<html>
<head>
<hta:application id = "netsend"
/>
<title>CBO Inner-Office Communicator</title>
<meta http-equiv = "content-script-type" content = "text/vbscript"/>
<script language = "VBScript"
type = "text/vbscript"
>
'<![CDATA[

''= sends mleMSG.value to all checked lbxCOMPUTERS.options[].value
' ============================================================================
Sub doSend()
' MsgBox "action doSend()"

Dim oOpt

For Each oOpt In document.all.lbxCOMPUTERS.options
If oOpt.selected Then
fakeSend oOpt.value, document.all.mleMSG.value
End If
Next
End Sub

''= fakes sending message sMsg to computer sName
' ============================================================================
Sub fakeSend( sName, sMsg )
Set WshShell = CreateObject("Wscript.Shell")
intReturn = WshShell.Run("%comspec% /c NET SEND " & lbxCOMPUTERS & " " & mleMSG)
Msgbox "return code = " & CStr(intReturn)
Set WshShell = Nothing
End Sub

''= refreshes the HTA page, which includes re-running any Windows_Onload code
' ============================================================================
Sub reloadHTA()
location.reload( True )
End Sub

']]>
</script>
</head>
<body>
<input type = "BUTTON" value = "Clear Form" onclick = "reloadHTA()">
<br>
<br>
Select User:<br>
<select size="1" id = "lbxCOMPUTERS">
<option value = "matthew">M. Pearon
<option value = "robin">R. Galle
<option value = "amanda">S. Twyman
</select> <br>
<br>
Enter Message:<br>
<textarea id = "mleMSG">

[&infin;]MP
 
Oh! I'm soooo sorry! I forgot to switch out the dim part of it! It's working beautifully! Thank you soooo very much, Mr. Movie! You are an absolute genius! :)

[&infin;]MP
 
Okay . . . Mr. Movie -
I'm trying to add a logging capability to it. I would like the information to be "echo"ed to a text file that is stored in a shared folder. Here is the line that is throwing a fit:

------------------------------------------------------------
WshShell.Run("%compspec% /c echo " & mleREM & "¶" & mleTEL & "¶" & mleMSG & "¶¶¶ >> " SERVERNAME\" & lbxCOMPUTER & "$\Messages\telMSG.txt")
------------------------------------------------------------

Any Ideas?

[&infin;]MP
 
try and get the line to work from a command prompt manually first, then just copy / transfer it into the script. you need to watch out for white space and wrap it in Chr(34) or "".

at first glance the " SERVERNAME\" cant be right? you will need " \\SERVERNAME\"???

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
One word of (future) warning. XP is the last desktop OS that Net Send works on. It was removed, purportedly for security reasons, from Vista onwards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top