Solved

Kix - Printer Removal

Posted on 2010-11-29
3
3,701 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 12

Expert Comment

by:Craig Bowman
ID: 34229865
0
 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
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 …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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