vbscript不适用于hta

时间:2013-03-20 18:06:43

标签: vbscript hta

请帮助我尝试在我们的网络上的另一台计算机上显示一条消息我们无法使用网络发送,因为Windows 7上不存在我们因为禁用而无法使用MSG,如果禁用,GPO将禁用它我们启用它。所以我在用户的计算机上有一个显示消息的vbscript,另一个用于发送要显示的消息的vbscript。当我使用此代码将消息作为常规vbscript发送时,它可以正常工作

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

但是在hta上放了相同的代码,它尝试在用户计算机上打开脚本,但它在显示消息之前就已经死了

<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>

请帮帮忙?

1 个答案:

答案 0 :(得分:1)

首先:全球On Error Resume Next是万恶之源。 使用此功能,除非您知道完全您正在做什么以及如何处理可能发生的任何错误。

那就是说,你的脚本可能会死掉,因为HTA中的VBScript代码无效。如果您想使用续行,则下划线必须位于您要继续的行的结束,而不是开头续行:

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

此外,您不能在字符串

中使用 行继续

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