Solved

Kix - Printer Removal

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Last week, our Skyport webinar on “How to secure your Active Directory” (https://www.experts-exchange.com/videos/5810/Webinar-Is-Your-Active-Directory-as-Secure-as-You-Think.html?cid=Gene_Skyport) provided 218 attendees with a step-by-step guide for…
In-place Upgrading Dirsync to Azure AD Connect
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

808 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