ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsProgrammingASP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
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  
Old February 18th, 2008, 09:03 AM
oldfart oldfart is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 3 oldfart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 10 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old February 19th, 2008, 01:04 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is online now
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,397 Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 5th Grade (Above 100000 Reputation Level)  Folding Points: 313769 Folding Title: Super Ultimate Folder - Level 1Folding Points: 313769 Folding Title: Super Ultimate Folder - Level 1Folding Points: 313769 Folding Title: Super Ultimate Folder - Level 1Folding Points: 313769 Folding Title: Super Ultimate Folder - Level 1Folding Points: 313769 Folding Title: Super Ultimate Folder - Level 1Folding Points: 313769 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 3 Days 22 h 32 m 47 sec
Reputation Power: 1311
--moved to the ASP forum.

what do you get? error? blank screen? please give more details.

Reply With Quote
  #3  
Old February 20th, 2008, 12:15 AM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Make sure you are connecting to the WMI Service properly. In VBS, you are probably accustomed to seeing this:
vb Code:
Original - vb Code
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  3. Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
This is fine, but in ASP you must use the SWbem object instead:
asp Code:
Original - asp Code
  1. strComputer = "."
  2. Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
  3. Set objSWbemServices = objSWbemLocator.ConnectServer(strComputer, "root\cimv2")
  4. Set colInstalledPrinters = objSWbemServices.ExecQuery("Select * from Win32_Printer")
Comments on this post
Shadow Wizard agrees: looking nice!
__________________
Click the image if at any point you don't like my decision.

Scripting problems? Windows questions? Ask the Windows Guru!


Reply With Quote
  #4  
Old February 20th, 2008, 03:01 PM
oldfart oldfart is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 3 oldfart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by Shadow Wizard
--moved to the ASP forum.

what do you get? error? blank screen? please give more details.


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

Reply With Quote
  #5  
Old February 20th, 2008, 04:29 PM
oldfart oldfart is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 3 oldfart User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 40 m 10 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old February 20th, 2008, 11:51 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
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.)
Comments on this post
micky agrees!

Reply With Quote
  #7  
Old May 15th, 2008, 12:43 PM
Nilpo's Avatar
Nilpo Nilpo is offline
ASP Free Novice (500 - 999 posts)
 
Join Date: Jun 2006
Location: Salem, OH
Posts: 675 Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)Nilpo User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1Folding Points: 156663 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Days 18 h 35 m 6 sec
Reputation Power: 308
Send a message via ICQ to Nilpo Send a message via AIM to Nilpo Send a message via MSN to Nilpo Send a message via Yahoo to Nilpo Send a message via Google Talk to Nilpo Send a message via Skype to Nilpo
MySpace
Quote:
Originally Posted by oldfart
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.
Hey, Mark. I just happened to look back through this thread. The default property WILL always return false on a remote machine because none of those printers are default to the machine running the script.

To find the default printer for a remote machine you should create a script on that machine and monitor its results.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingASP Development > WMI - Default printer query will not return true.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway