简体   繁体   English

VBS脚本中的内存不足错误

[英]Out of memory error in vbs scripts

I've been facing this dialogue box just after I start my script 启动脚本后,我一直在面对这个对话框

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

This is my script: 这是我的脚本:

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

You can see, that it script for installing in my system printer 'Konica'. 您可以看到,该脚本可以在我的系统打印机“ Konica”中安装。 In other system, it script works fine. 在其他系统中,它的脚本工作正常。 Where mistake? 哪里有错? Please help ? 请帮忙 ?

I'm probably on a wrong tangent here but try giving the MsgBox a variable and then using code that doesn't do anything. 我可能在这里切线有误,但尝试给MsgBox变量,然后使用不做任何事情的代码。 For example: 例如:

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

becomes

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

Then you could write 那你可以写

If x Then
Else
End If

Which would run and do nothing because x is always x but there's nothing to run inside the If statement. 它将运行且不执行任何操作,因为x始终为x,但是If语句内无任何运行。

That error means that your system is low on memory. 该错误意味着您的系统内存不足。 The line numbering is questionable in your post, but I would venture a guess that the size of the printer driver is pretty large. 行号在您的帖子中是有疑问的,但是我敢猜测打印机驱动程序的大小非常大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM