2013-03-20 26 views
0

请帮助我试图在我们的网络上的另一台计算机上显示消息我们不能使用网络发送,因为在Windows 7上不存在,我们不能使用MSG,因为是禁用,并且如果我们启用它,GPO将禁用它。所以我在用户的计算机上显示消息的vbscript,以及另一个发送要显示的消息的vbscript。当我使用此代码来发送消息作为一个普通的VBScript它的工作原理vbscript不能在hta上工作

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

首先是:全球性的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) 
+0

谢谢你的建议,我删除了旁边的错误恢复,并在两地行延续,但脚本仍然这样做。 – user1766952 2013-03-21 11:53:35

+0

您的HTA在3个地方有续行。如果在解决该问题后仍然出现错误,请使用更正的代码和实际的错误消息来更新您的问题。 – 2013-03-21 11:59:51

+0

我很抱歉无法回答,但是我删除了所有行延续,问题是我没有得到任何类型的错误,它只是打开cmd,并显示在工具栏上的脚本部分几秒钟然后它死了谢谢 – user1766952 2013-03-26 18:37:29

相关问题