VBscript无法运行Shell命令

时间:2022-08-23 08:58:09

I have set up the following Sub to run shell commands quickly and easily. This script works for the login scripts at my company without fail. I am currently developing a script to add a large batch of users to our domain. When I used this Sub in my new script I receive an error saying that the file cannot be found. I have tried using the fix in this * post, but I recieve the same error even with this code. VBScript WScript.Shell Run() - The system cannot find the file specified

我已经设置了下面的子命令来快速、轻松地运行shell命令。这个脚本适用于我公司的登录脚本。我目前正在开发一个脚本,以便向我们的域添加大量用户。当我在我的新脚本中使用这个子文件时,我收到一个错误,说找不到这个文件。我已经尝试在这个*帖子中使用修复,但是我也遇到了同样的错误,即使是这个代码。VBScript WScript。Shell Run()——系统无法找到指定的文件

The part I find puzzling is that this sub works just fine when run from the netlogon folder of our domain controller. What am I doing wrong?

让我感到困惑的是,当从我们的域控制器的netlogon文件夹运行时,这个子程序运行得很好。我做错了什么?

Thanks,

谢谢,

Sub runcommand(strCommand)
Dim objWshShell, intRC
set objWshShell = WScript.CreateObject("WScript.Shell")
intRC = objWshShell.Run(strCommand, 0, TRUE)
call reportError(intRC,strCommand)
set objWshShell = nothing 
end Sub

function reportError(intRC, command)
if intRC <> 0 then 
 WScript.Echo "Error Code: " & intRC 
 WScript.Echo "Command: " & command 
end if
end function

1 个解决方案

#1


1  

The previous values for strCommand had no spaces and were very straightforward. Your new script is passing more complex variables to your Sub so you need additional conditional handling, as Alex K. pointed out in his Collusion (i.e., "Comment/Solution") above. Alex K.'s sample above is perfect, so, being a Point Pimp tonight, will post it as the solution:

strCommand之前的值没有空格,而且非常简单。您的新脚本正在将更复杂的变量传递给您的子脚本,因此您需要额外的条件处理,正如Alex K.在他的合谋中指出的(例如)。上面,“评论/解决方案”)。亚历克斯·K。上面的样本是完美的,所以,今晚作为一个点皮条客,将把它作为解决方案:

objWshShell.Run("cmd /k echo Hello World", 1, TRUE)

#1


1  

The previous values for strCommand had no spaces and were very straightforward. Your new script is passing more complex variables to your Sub so you need additional conditional handling, as Alex K. pointed out in his Collusion (i.e., "Comment/Solution") above. Alex K.'s sample above is perfect, so, being a Point Pimp tonight, will post it as the solution:

strCommand之前的值没有空格,而且非常简单。您的新脚本正在将更复杂的变量传递给您的子脚本,因此您需要额外的条件处理,正如Alex K.在他的合谋中指出的(例如)。上面,“评论/解决方案”)。亚历克斯·K。上面的样本是完美的,所以,今晚作为一个点皮条客,将把它作为解决方案:

objWshShell.Run("cmd /k echo Hello World", 1, TRUE)