?
Solved

Kixstart setting up default printer

Posted on 2011-10-03
16
Medium Priority
?
374 Views
Last Modified: 2012-05-12
I'm new to Kixstart and would like to see if I can set the script to do a "setdefaultprinter" to a domain group BUT exclude a user (who is part of the domain group) if he or she has a local default printer installed. Is this possible? Please advise.


IF INGROUP("DomainGroups")
AddPrinterConnection("\\server\printer")
SetDefaultPrinter("\\server\printer")

thank you.
Collin
0
Comment
Question by:CollinMendoza
  • 9
  • 5
14 Comments
 
LVL 29

Assisted Solution

by:Michael Pfister
Michael Pfister earned 2000 total points
ID: 36909936
Try the follwoing UDF in you code, like

IF INGROUP("DomainGroups")
AddPrinterConnection("\\server\printer")
If Not LocalPrinterExists()
SetDefaultPrinter("\\server\printer")

The function checks if a local printer, set as default printer, exists. I haven't checked the code so there might be one or two typos...

HTH
Function LocalPrinterExist()
  dim $service,$printer,$printers
  $LocalPrinterExist=0
  $Service=GetObject("winmgmts:{impersonationLevel=impersonate}!" + @wksta +"\root\cimv2")
  if not @error=0
    exit @error
  endif
  $Printers=$service.execquery ("select * from Win32_Printer where Default = 'True' And Local = 'True'")
  for each $printer in $printers
      $LocalPrinterExist=1
   next
endfunction

Open in new window

0
 

Author Comment

by:CollinMendoza
ID: 36911125
I will search, check the code and try this. Let you know how this goes...

thank you.
0
 

Author Comment

by:CollinMendoza
ID: 36911354
Cannot find information about the function you specified. Do I need to change some line?

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 29

Expert Comment

by:Michael Pfister
ID: 36915199
Did you copy and paste the attched code snippet to your code? I just saw in my post I've mistyped the function name, its LocalPrinterExist not LocalPrinterExists.
Did you get an error code when running it?
0
 
LVL 29

Expert Comment

by:Michael Pfister
ID: 36915782
Please use the corrected UDF below
Function LocalPrinterExist()
  dim $service,$printer,$printers
  $LocalPrinterExist=0
  $Service=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + @wksta +"\root\cimv2")
  if not @error=0
    exit @error
  endif
  $Printers=$service.execquery ("select * from Win32_Printer where Default = 'True' And Local = 'True'")
  for each $printer in $printers
      $LocalPrinterExist=1
   next
endfunction

Open in new window

0
 

Author Comment

by:CollinMendoza
ID: 36920054
Will this work even if the machine has PDF Document (printer)? I applied the script but the default printer stayed in PDF printer. did not get me any error.
0
 
LVL 29

Assisted Solution

by:Michael Pfister
Michael Pfister earned 2000 total points
ID: 36922831
Probably yes, a PDF printer is usually a local printer.

Add

? $printer.DeviceID

in the for-loop. This will dump the DeviceID of the PDF printer
With the DeviceID you can filter out the PDF printer:

  for each $printer in $printers
    If $printer.DeviceID <> "Your PDF printer name goes here"
      $LocalPrinterExist=1
   endif
   next

HTH
0
 

Author Comment

by:CollinMendoza
ID: 36925199
is this the script will look like?


Function LocalPrinterExist()
  dim $service,$printer,$printers
  $LocalPrinterExist=0
  $Service=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + @wksta +"\root\cimv2")
  if not @error=0
    exit @error
  endif
  $Printers=$service.execquery ("select * from Win32_Printer where Default = 'True' And Local = 'True'")
  for each $printer in $printers
      If $printer.DeviceID <> "Your PDF printer name goes here"
      $LocalPrinterExist=1
      endif
   next
endfunction
0
 
LVL 29

Expert Comment

by:Michael Pfister
ID: 36929043
Yes, this would filter out the PDF printer, meaning the UDF will return 0, even if there is a local default printer, but only when the name corresponds,
0
 

Author Comment

by:CollinMendoza
ID: 36932255
That seem to work. thank you.
0
 

Author Comment

by:CollinMendoza
ID: 36933369
I've requested that this question be closed as follows:

Accepted answer: 0 points for CollinMendoza's comment http:/Q_27378109.html#36925199

for the following reason:

Resolved
0
 

Accepted Solution

by:
CollinMendoza earned 0 total points
ID: 36932288
cancel request. click on the wrong bottum. Im suppose to award the tech who help me. Thanks you
0
 

Author Closing Comment

by:CollinMendoza
ID: 36954312
resolved
0
 

Author Comment

by:CollinMendoza
ID: 36934039
Award "mpfister" for the points.

Thank you
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question