|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
WMI - Default printer query will not return true.
I run a hospital IT Desktop Inventory database/asp front end, sql server backend. I am developing a page to present dynamic WMI based info for the selected workstation. I am trying to query the default printer with the following code that runs entirely fine in vbs but fails to return true for the default printer when the asp runs on the server. Every other WMI function works flawlessly so I know that the service is running fine. This does return a numbered list of printers and the default should return true once on a test machine but doesn't:
'Authentication for wmi not included here. Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer") strPrnName = "" n = 1 For Each objPrinter in colInstalledPrinters default = "" If objPrinter.Default Then default = "Default:" End if strPrnName = strPrnName & CStr(n) & ". " & default & objPrinter.Name & "<br>" n = n + 1 Next Response.Write strPrnName 'Within a <td> definition. Any hint would be appreciated. Thanks |
|
#2
|
||||
|
||||
|
--moved to the ASP forum.
what do you get? error? blank screen? please give more details. |
|
#3
|
||||
|
||||
|
Make sure you are connecting to the WMI Service properly. In VBS, you are probably accustomed to seeing this:This is fine, but in ASP you must use the SWbem object instead:
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
|
#4
|
|||
|
|||
|
Quote:
The query returns false when it should return true. I did a little more testing with the vbs version. It seems that the problem is apparent only in remote pc's. So, if instead of ".", I use a remote pc as the target, I get back the names of the printers but each objPrinter.Default returns false when one should return true. strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer") For Each objPrinter in colInstalledPrinters Wscript.Echo "Name: " & objPrinter.Name Wscript.Echo "Default: " & objPrinter.Default Next Thanks Mark |
|
#5
|
|||
|
|||
|
I am using objswbemlocator
I did not include the authentication string previously but I was using what you suggested.
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objWMIService = objSWbemLocator.ConnectServer(strEpic, "root\CIMV2", strUser, strPassword) objWMIService.Security_.impersonationlevel=3 I am trying to figure out what is different about that particular attribute that is sensitive to the source of the query. |
|
#6
|
||||
|
||||
|
Using objWMIService.Security_.impersonationlevel=3 with the SWbem object is the same as using {impersonationLevel=impersonate}!
Impersonate is a DCOM Impersonation level that instructs WMI to use your own user credentials to perform tasks. This may provide unusual results when used remotely as your user credentials may not carry high enough user privileges on the remote machine. Locally, however, this is generally quite sufficient. (And it's the recommended level to use.) |
|
#7
|
||||
|
||||
|
Quote:
To find the default printer for a remote machine you should create a script on that machine and monitor its results. |
![]() |
| Viewing: ASP Free Forums > Programming > ASP Development > WMI - Default printer query will not return true. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
![]() |
|