user1766952
user1766952

Reputation: 173

vbscript doesn't work on hta

please help i am trying to display a message on another computer on our network we can not use net send since doesn't exist on windows 7 and we can not use MSG because is disable, and GPO will disable it if we enable it. so i have a vbscript on the user's computer that display the message, and another vbscript that sends the message to be display. when i use this code to send the message as a regular vbscript it works

Dim strMessage, strComputer, strLocalPath, strFile, objShell 
Dim strRemotePath, objShellApp, strTest, sPSEXEC
strComputer = InputBox("enter computer Name", "create File")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & 
strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
Set objShell = CreateObject("WScript.Shell")
Set objShellApp = CreateObject("Shell.Application")
currentpath = objShell.CurrentDirectory & "\"
sPSEXEC = currentPath & "psexec.exe"
strFile = """c:\windows\notification.vbs"""
strMessage = InputBox("enter Message", "create File")
strTest = "\\"&strComputer&" " &"cscript.exe"&" "&strFile&" 
"&"/message:"&Chr(34)&strMessage&Chr(34)
WScript.Echo strTest
objShellApp.ShellExecute "cmd.exe","/k "&sPSEXEC&" -s -i -d "&" "&strTest, "","runas",1

but put the same code on hta it try to open the script on the user computer but it dies before it can display the message

<script Language = VBScript>
On Error Resume Next
Sub WindowsLoad
Dim strMessage, strComputer, strLocalPath, strFile, objShell
Dim strRemotePath, objShellApp, strTest, sPSEXEC    
strComputer = computerName.Value
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & 
_strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
Set objShell = CreateObject("WScript.Shell")
Set objShellAPP = CreateObject("Shell.Application")
currentpath = objShell.CurrentDirectory & "\"
sPSEXEC = currentPath & "psexec.exe"
strFile = """c:\windows\notification.vbs"""
strTest = "\\"&strComputer&" " &"cscript.exe"&" "&strFile&"   
_"&"/message:"&Chr(34)&strMessage&Chr(34)
objShellApp.ShellExecute "cmd.exe","/k "&sPSEXEC&" -s -i -d "&" "&strTest, "", 
_"runas", 1
End Sub
</script>
<Body>
<div>
</div>

Computer Name: <Input align="right" Type = "Text" Name = "computerName">
</br>
</br>
Message: 
</br>
<TEXTAREA NAME="Message" COLS=30 ROWS=6>

</TEXTAREA>
</br>
</br>
<Input Type = "Button" Value = "Send Message" Name = "Run_Button" onClick = "WindowsLoad"><P>

Please help?

Upvotes: 0

Views: 839

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200563

First and foremost: a global On Error Resume Next is the root of all evil. Do not use this unless you know exactly what you're doing and how to handle any error that may occur.

That said, your script probably dies, because the VBScript code in the HTA is invalid. If you want to use line continuation, the underscore must be at the end of the line you want to continue, not at the beginning of the continued line:

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & 
_strComputer & "\root\cimv2")

Also you cannot use line continuation inside a string:

strTest = "\\"&strComputer&" " &"cscript.exe"&" "&strFile&"   
_"&"/message:"&Chr(34)&strMessage&Chr(34)

Upvotes: 1

Related Questions