ser*_*dar -6 windows vbscript cmd.exe
我希望这个 vbs 代码能在远程机器上执行 oShell.run 方法。情况似乎并非如此,但此脚本执行时没有显示错误。
on error resume next
dim oShell, strComputer, intProcessID
strComputer = InputBox("IP or Host Name:", "DELETER - serdaruzun@outlook.com")
set oShell = WScript.CreateObject("Wscript.shell") & strComputer
oShell.run "cmd.exe /C rd \\%PC%\Users\1*.* /s /q", null, null, intProcessID
oShell.run "cmd.exe /C rd \\%PC%\Users\2*.* /s /q", null, null, intProcessID
oShell.run "cmd.exe /C rd \\%PC%\Users\3*.* /s /q", null, null, intProcessID
set oShell = nothing
Run Code Online (Sandbox Code Playgroud)
在远程计算机上执行这些命令的正确方法是什么?
首先 - 如果您删除“下一个错误恢复”,您会立即看到此错误。
接下来,我建议您尝试在远程 PC 上使用文件夹删除方法,而不是运行 cmd。
之后,您无法针对 C:\ 运行 cmd.exe 并以某种方式使其在远程 PC 上运行,除非您使用 psexec 或类似工具启动 VBS 并以远程 PC 为目标。
我认为这更接近你所追求的:
'First, we get the host name
strComputerName = InputBox ("Enter Hostname or IP to delete from")
'Next, we check the user actually entered a name or IP - you missed this!
if len(strComputerName) < 1 then
WScript.Echo "No Computer Name Entered - Quitting"
WScript.Quit
end if
'next, we check it exists - you missed this bit too! no point in trying to remove folders from a non existant PC
If Reachable(strComputerName) Then
DeleteAFolder("\\" & strComputerName & "\c$\users\me\desktop\test")
DeleteAFolder("\\" & strComputerName & "\C$\folder\folder2")
Else
WScript.Echo "Computer is Unreachable! - Quitting!"
End If
'This function is the one called to check if the computer is reachable in line 11!
Function Reachable(strComputerName)
Dim wmiQuery, objWMIService, objPing, objStatus
wmiQuery = "Select * From Win32_PingStatus Where Address = '" & strComputerName & "'"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
Reachable = False 'if computer is unreacable, return false
Else
Reachable = True 'if computer is reachable, return true
End If
Next
End Function
'This function takes the name of the folders (lines 12 and 13) and deletes them
Sub DeleteAFolder(filespec)
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'True in the line below includes read only folders
fso.DeleteFolder(filespec, true)
End Sub
Run Code Online (Sandbox Code Playgroud)
只是一个简短的说明..如果这不起作用 - 它可能是一个权限问题,但我无意扩展这个脚本 - 所以你从这里开始。
| 归档时间: |
|
| 查看次数: |
835 次 |
| 最近记录: |