Kixstart setting up default printer

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
CollinMendozaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael PfisterCommented:
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
CollinMendozaAuthor Commented:
I will search, check the code and try this. Let you know how this goes...

thank you.
0
CollinMendozaAuthor Commented:
Cannot find information about the function you specified. Do I need to change some line?

0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Michael PfisterCommented:
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
Michael PfisterCommented:
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
CollinMendozaAuthor Commented:
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
Michael PfisterCommented:
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
CollinMendozaAuthor Commented:
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
Michael PfisterCommented:
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
CollinMendozaAuthor Commented:
That seem to work. thank you.
0
CollinMendozaAuthor Commented:
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
CollinMendozaAuthor Commented:
cancel request. click on the wrong bottum. Im suppose to award the tech who help me. Thanks you
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CollinMendozaAuthor Commented:
resolved
0
CollinMendozaAuthor Commented:
Award "mpfister" for the points.

Thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.