Solved

Kix - Printer Removal

Posted on 2010-11-29
3
3,733 Views
Last Modified: 2012-05-10
Dear all,

I need to remove any printers that are attached to a certain server when a user logs in.

DelPrinterConnection("\\servername\printer")

Is there a way of putting a wildcard into it so that any printers that are picked up get dropped?

Or basically is there a Kix command that i can use to remove all printers?
As they are being recreated later on in the script.

Thanks,

Lyon
0
Comment
Question by:LyonJay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:ipajones
ID: 34229952
I don't think you'll be able to remove all existing printer connections just using Kixtart.  Also I think DelPrinterConnection() is only supported on Windows NT and Windows 2000.

However, you could call a shell command from within your Kix script, so something like:

shell "%comspec% /c con2prt /f"

Open in new window


You may need to put con2prt.exe (depends on client OS) where it can be accessed by the login script - I would just save it in the nelogon shares root folder.

Hope this helps.
--IJ
0
 
LVL 3

Accepted Solution

by:
Isorg earned 500 total points
ID: 34235781
here is a bit of code that i have used to remove printers from retired print servers..

;this function will delete all maped printers from a named server
Function DelprinterConnections($server)
    $Rootkey = "HKEY_CURRENT_USER\Printers\Connections"
    for each $key in getkeys($Rootkey)
        if instr($key,$server)
            $ = delkey($rootkey+"\"+$key)
        endif
    next
endfunction



;this function will return an array of key names in a given reg path
function getkeys($path)
    dim $c
    dim $a[0]
    $a[$c] = enumkey($path,$c)
    while @error =0
        $c = $c + 1
        redim preserve $a[$c]
        $a[$c] = enumkey($path,$c)
    loop
    if $c
        redim preserve $a[$c-1]
    endif
    $getkeys = $a
endfunction

Open in new window



Put the UDF's into your kix script, and call the udf

delprinterconnections('OldPrintServer')

any printer with OldPrintServer in it's UNC will be deleted
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

687 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