Solved

Kix - Printer Removal

Posted on 2010-11-29
3
3,519 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:cbowman92
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now