0

I have a vbscript to get some informations about the system printing of a remote computer. I can get all the drivers installed, the default network printer name and all my results are send in a outputfile. I want to get informations about my default network printer by the prncnfg.vbs from the printer server (driver, location, etc.) and send these informations in my outputfile. Maybe there is an other way to do that ?

Thanks for any suggestions

brs65
  • 1
  • 1
  • Is this something that you are looking for: http://www.computerperformance.co.uk/vbscript/wmi_printer.htm – user5612655 Jan 12 '16 at 05:45
  • Thanks. But there is 2 problems. The first one is that I can't get any network printer for a remote computer because there is a default printer for each windows profiles. I can get this only for the computer on which I'm logged. The second is that your link don't explain how to get information about a network printer. How to use prncnfg inside a vbscript.. – brs65 Jan 12 '16 at 07:27
  • do you know how to use prncnfg outside vbscript to find the information you need??. If yes then we need to find a way to run the commands you need in vbs, which I don't think should be that difficult. If this is the case then lemme know – user5612655 Jan 12 '16 at 09:38
  • The way outside is to use cmd and cscript. By exemple : Cscript Prncnfg.vbs -g -S HRServer -P ColorPrinter_2. But prncnfg.vbs is a vbscript included in Windows – brs65 Jan 12 '16 at 12:42
  • well to run a vbs inside a vbs you can use this http://stackoverflow.com/questions/5690134/running-command-line-silently-with-vbscript-and-getting-output so if you know the commands that will work on cmd on remote machine, just create vbs running those commands, I am able to use prncnfg.vbs to find info of printer on my local machine, not able to find a way to get default printer yet, not getting time to do much research as well. – user5612655 Jan 13 '16 at 06:29

1 Answers1

0

So, I start to understand the way to do that. But something doesn't work.

First I need to read a file and remove 10 caracters to create my variable, this process works very well:

'Read C:\Temp\DefaultPrinter Dim shortDefaultPrinter If objFSO.FileExists("\"& strComputer &"\c$\Temp\DefaultPrinter.txt") then Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("\"& strComputer &"\c$\Temp\DefaultPrinter.txt",1) DefaultPrinter = objFileToRead.ReadAll() 'remove text \vangogh\ shortDefaultPrinter = Right(DefaultPrinter, Len(DefaultPrinter) - 10) 'MsgBox(shortDefaultPrinter) objFileToRead.Close Set objFileToRead = Nothing

Second I want to use my variable shortDefaultPrinter for my query to find the location of my printer:

'Select DefaultPrinter and show location Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName, Location from " _     
    & " 'LDAP://DC=huge,DC=ad,DC=hcuge,DC=ch'  where objectClass='printQueue' and printerName='" & shortDefaultPrinter & "' " 

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    PrinterLocation = objRecordSet.Fields("Location").Value
    MsgBox(PrinterLocation)
    objRecordSet.MoveNext

Loop

MsgBox doesn't open, but if I write the name of the printer in place of " & shortDefaultPrinter & ", ex dmed-i714, the process works.

Here I am. If anyone has a suggestion it would be appreciate.

brs65
  • 1
  • 1