2012-10-25 106 views
0

我已經設置了以下Sub來快速輕鬆地運行shell命令。 此腳本適用於我公司的登錄腳本。 我目前正在開發一個腳本,將大量用戶添加到我們的域中。 當我在我的新腳本中使用這個Sub時,我收到一個錯誤,提示找不到該文件。 我已經嘗試使用此修補程序在此stackoverflow後,但我收到甚至與此代碼相同的錯誤。 VBScript WScript.Shell Run() - The system cannot find the file specifiedVBscript無法運行Shell命令

我覺得令人費解的部分是,從我們的域控制器的netlogon文件夾運行時,這個子工作得很好。 我在做什麼錯?

感謝,

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 
+0

由於您沒有指定...嘗試在命令中運行strCommand的值提示成功,對嗎? –

+0

是從命令行運行這個不會返回任何錯誤 – Talon06

+0

什麼是strCommand的值 –

回答

1

爲strCommand以前的值沒有空格,是很簡單的。您的新腳本將更復雜的變量傳遞給您的Sub,因此您需要額外的條件處理,正如Alex K.在他的Collision(即「評論/解決方案」)中指出的那樣。上面的示例是完美的,因此,作爲今晚的Point Pimp,將作爲解決方案發布它:

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