人们已经在批处理文件中嵌入和执行VBScript很长一段时间了.但是我所看到的所有已发布的解决方案(在此问题最初提出时)都涉及编写临时VBS文件.例如:在Windows批处理文件中嵌入VBScript.
是否可以在批处理中执行嵌入式VBScript而无需编写临时文件?
当我尝试从Windows 7中的命令提示符运行以下vbs代码时,出现编译错误.
Option Explicit
Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3
Dim strDriveLetter1, strDriveLetter2, strDriveLetter3, strUserName
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName
strDriveLetter1 = "H:"
strDriveLetter2 = "P:"
strDriveLetter3 = "S:"
strRemotePath1 = "\\test\public\users\" & strUserName & "\"
strRemotePath2 = "\\test\public\groups\"
strRemotePath3 = "\\test\scans\"
'Section which maps two drives, M: and P: and S:
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
'Extra code just to add a message box
WScript.Echo "Map drives " & strDriveLetter1 & " & " …Run Code Online (Sandbox Code Playgroud)