簡體   English   中英

VBS腳本中的內存不足錯誤

[英]Out of memory error in vbs scripts

啟動腳本后,我一直在面對這個對話框

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”中安裝。 在其他系統中,它的腳本工作正常。 哪里有錯? 請幫忙 ?

我可能在這里切線有誤,但嘗試給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語句內無任何運行。

該錯誤意味着您的系統內存不足。 行號在您的帖子中是有疑問的,但是我敢猜測打印機驅動程序的大小非常大。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM