【问题标题】:Attempting to extract printers from users machine and then outputting to a text fill.尝试从用户机器中提取打印机,然后输出到文本填充。
【发布时间】:2014-09-17 22:41:46
【问题描述】:

我正在尝试从用户机器中提取打印机,然后输出到文本文件,但是当我运行测试时,我得到了针对该特定代码行的无效过程调用或参数。

Set objOutputFile = objFSO.OpenTextFile(outFile, ForAppending, True)

我试图将OpenTextFile更改为CreateTextFile,但我需要将这些行附加到文件中,因为它将作为登录脚本运行。

我进行了一些研究并使用 Microsoft 开发人员文章来帮助我调试代码中的问题,但我在 Visual Basic 方面没有太多经验。

我已经添加了整个脚本来为正在发生的事情提供上下文。

dim objComputerName, ObjNetwork , strText , objfile, StrComputer
dim wshnetwork 



Set wshnetwork = CreateObject ("Wscript.network")
StrComputer = WshNetwork.ComputerName 
If IsEmpty(StrComputer) Then Wscript.Quit





Set WshNetwork = CreateObject("WScript.Network") 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer") 
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) 
Set WshShell = WScript.CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 


 outFile = "C:\scripts\Printers" & StrComputer




Set objOutputFile = objFSO.OpenTextFile(outFile, ForAppending, True)
For Each objPrinter in colInstalledPrinters 
strTest = Left(objPrinter.Name, 2) 
objOutputFile.WriteLine(objPrinter.Name) 
objfile.close
Next 

Set objPrinter = WshNetwork.EnumPrinterConnections
'Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True) 
If objPrinter.Count = 0 Then
WScript.Echo "No Printers Mapped "
else
For intDrive = 0 To (objPrinter.Count -1) Step 2
intNetLetter = IntNetLetter +1
printer = "UNC Path " & objPrinter.Item(intDrive) & " = " & objPrinter.Item(intDrive +1) & " Printer : " & intDrive
objOutputFile.WriteLine(printer)
Next
end if
objOutputFile.Close``*

【问题讨论】:

    标签: vbscript printers


    【解决方案1】:
    Invalid procedure call or argument  
    
    You passed an invalid parameter in your procedure call. This could be because the parameter was out of range, or contained invalid data. Alternately, you may have invoked a procedure at an unexpected time.
    
    To correct this error
    
    Verify that the parameters being passed to the procedure are valid.
    
    Verify that you are calling the function at an appropriate time.
    

    我的猜测是这一行是一个非法的文件名。

    outFile = "C:\scripts\Printers" & StrComputer
    

    在我的计算机上,这是c:\scripts\PrintersSerenity,您的文本文件名为 PrintersSerenity 而没有扩展名可能是不对的。

    【讨论】:

    • 查看 objPrinters = object.EnumPrinterConnections Arguments object WshNetwork object. objPrinters Variable that holds the network printer mapping information. 了解内置 vbs/wsh 打印机命令。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-22
    • 2012-11-01
    • 1970-01-01
    • 2013-06-15
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    相关资源
    最近更新 更多