2015-12-02 173 views
1

我一直面臨着剛過,我開始我的劇本此對話框內存不足錯誤的VBS腳本

Script: C:\konica.vbs 
Line: 14 
Char: 1 
Error: Out of Memory: 'GetObject' 
Code: 800A0007 
Source: Microsoft VBScript runtime error 

這是我的腳本:

Set wshShell = CreateObject("WScript.Shell") 
strCurrDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 


'### Konica ### 

strIPAddress = "192.168.110.168" 
strComputer = "." 
strPrinterName = "Konica" 
strDriverName = "KONICA MINOLTA C353 Series PS" 
strLocation = "Konica" 
strInfFile = "\\stp\HHard\Printers\KONICA MINOLTA\XP(x86)\BHC353PSWinx86_6500RU\BHC353PSWinx86_6500RU\KOAZXA__.INF" 

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(LoadDriver)}!\\" & strComputer & "\root\cimv2") 
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer Where PortName = 'IP_" & strIPAddress & "' ") 
For Each objPrinter in colPrinters 
    MsgBox "Unable to install printer, printer already found on port 'IP_" & strIPAddress & "'." & VbCrlf & VbCrlf & "Found: " & objPrinter.DeviceID, vbExclamation + vbSystemModal, "Printer Port already assigned" 
    WSCript.Quit 114001 
Next 
'MsgBox(strIPAddress) 
Set objNewPort = objWMIService.Get("Win32_TCPIPPrinterPort").SpawnInstance_ 
objNewPort.Name = "IP_" & strIPAddress 
objNewPort.Protocol = 1 
objNewPort.HostAddress = strIPAddress 
objNewPort.PortNumber = "9100" 
objNewPort.SNMPEnabled = False 
objNewPort.Put_ 

wshShell.Run "rundll32 printui.dll,PrintUIEntry /if /b """ & strPrinterName & """ /f """ & strInfFile & """ /r ""IP_" & strIPAddress & """ /m """ & strDriverName & """", 1, True 

Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer Where DeviceID = '" & strPrinterName & "' ") 
For Each objPrinter in colPrinters 
    objPrinter.Location = strLocation 
    objPrinter.Put_ 
Next 

你可以看到,它的腳本用於安裝在我的系統打印機'Konica'中。在其他系統中,它的腳本工作正常。哪裏錯了?請幫忙 ?

回答

0

我可能在這裏錯誤的切線,但嘗試給MsgBox一個變量,然後使用不做任何事情的代碼。 例如:

MsgBox "Unable to install printer, printer already found on port 'IP_" & strIPAddress & "'." & VbCrlf & VbCrlf & "Found: " & objPrinter.DeviceID, vbExclamation + vbSystemModal, "Printer Port already assigned" 

成爲

x = MsgBox "Unable to install printer, printer already found on port 'IP_" & strIPAddress & "'." & VbCrlf & VbCrlf & "Found: " & objPrinter.DeviceID, vbExclamation + vbSystemModal, "Printer Port already assigned" 

然後,你可以寫

If x Then 
Else 
End If 

這將運行,什麼也不做,因爲X總是X,但沒有什麼if語句內運行。

+0

好的,謝謝。但這不解決我的問題與getobject – Valeriu

+0

嗯,好的,我會再看看。 – SamJakob

0

該錯誤表示您的系統內存不足。行號在你的文章中是有問題的,但我會猜測打印機驅動程序的大小非常大。