【问题标题】:vbscript doesn't work on htavbscript 在 hta 上不起作用
【发布时间】:2013-03-20 18:06:43
【问题描述】:

请帮助我正在尝试在我们网络上的另一台计算机上显示消息我们无法使用网络发送,因为在 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>

请帮忙?

【问题讨论】:

    标签: vbscript hta


    【解决方案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)
    

    【讨论】:

    • 感谢您的建议,我删除了 on error resume next,并且这两个地方的行继续,但脚本仍然执行相同的操作。
    • 您的 HTA 在 3 个地方有续行。如果修复后仍然出现错误,请使用更正后的代码和实际错误消息更新您的问题。
    • 很抱歉无法回复,但是是的,我删除了所有续行,问题是我没有收到任何类型的错误它只是打开 cmd 并显示脚本部分在工具栏上停留几秒钟,然后它就死了,谢谢
    • 如果我没记错的话,我要求您使用更正后的 HTA 代码更新您的问题,即您正在使用的代码现在
    猜你喜欢
    • 2015-05-15
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多