If you read the first part of the title “Delete printer without log off” you would probably say it must be an easy thing to do. The truth? It’s not so simple. Why?

First thing, let me say that you can try with a few programs, features or scripts like psexec or wmic or even runas, but it’s a bit more complicated to delete printer for user running as administrator.

Let’s shortly take them one by one and keep in mind that if you have other ideas, I am always willing to learn more and I would like to exchange info with any of you, so poke around.

WMIC: You can use it, but it won’t help much by its own, because even if you could use runas and get administrator rights, in some cases it will affect all users or it won’t affect the targeted user at all, and it will only modify it for administrator.

Second thing to keep in mind, WMIC will fail you if you try psexec with it, due to some restrictions or compatibility issues that I will cover in a later article.

PSEXEC: Won’t help you either in this case because if it runs on the current user that doesn’t have rights, it won’t delete printer. If he is an administrator we wouldn’t talk about this anymore since for an admin this is just a simple command or a right click. If runas admin with another account it will work for all or for all except the intended user.

RUNAS: Same as for the 2 above: you run it with another admin account, it won’t work on the current, or it will on all.

If what I am trying to explain is not clear by now, I will try to describe both the problem and solution through a scenario.

Let’s take a user and let’s call it “A USER” WITHOUT administrative rights. He has a printer in printers and faxes and when trying to delete it he will get a message with access denied or something similar. This means either the printer, the port or the driver of the printer is in use, or something went wrong and the user lacks even those basic privileges to delete his own printers.

When this happens, you will have to get the user to have administrative privileges, it’s faster this way. To do this, you can use an older script that travelled all over the Web but I wouldn’t know who first designed it to thank him.

Just copy/paste below code into a .cmd file and call it MakeMeAdmin.cmd while copying it to the computer where you are trying to delete printer for that user, in c:\windows\system32:

@echo off

setlocal

set _Admin_=%COMPUTERNAME%\Administrator

set _Group_=Administrators

set _Prog_=”cmd.exe /k Title *** %* as Local Administrator *** && cd c:\ && color 4F”

set _User_=%USERDOMAIN%\%USERNAME%

if “%1″==”” (

runas /u:%_Admin_% “%~s0 %_User_%”

if ERRORLEVEL 1 echo. && pause

) else (

echo Adding user %* to group %_Group_%…

net localgroup %_Group_% “%*” /ADD

if ERRORLEVEL 1 echo. && pause

echo.

echo Starting program in new logon session…

runas /u:”%*” %_Prog_%

if ERRORLEVEL 1 echo. && pause

echo.

echo Removing user %* from group %_Group_%…

net localgroup %_Group_% “%*” /DELETE

if ERRORLEVEL 1 echo. && pause

)

endlocal

Keep in mind that if you don’t use Administrator as local admin account, you will have to change it here: set _Admin_=%COMPUTERNAME%\Administrator

Now you will have to connect to that computer using whatever software you like. The thing is that I don’t know how much it will help those of you using RDP or other remote connection software. It will be best to find a way or software to connect and interact also with the user, as the settings should be done from his account. For example, I’m using a script with VNC that helps me pop a question to the user if he will allow me to connect and then, using VNC, we can both control the computer and he can see what I am doing, unlike RDP. This will be impossible for some of you but I have no doubts somehow the info here will help you find a way to reach your final goal.

After you are connected to his PC, you will have to type at run the name of the above script: MakeMeAdmin and it will open up the prompt from the script asking you for administrator password. After you put that, you will have to tell the user to put his password too. A red window with administrative rights for the user will open.

In here you will have to type the following line:

wmic printer where portname=”The name of the port” DELETE

You will have to replace the “The name of the port” at portname with the name of the port as you see it in print properties at PORTS, usually with a name like IP_10.0.0.3.

You will see a confirmation message that the printer was deleted.

A few more things that I should mention, among them that this was available for a network printer added using local port configuration through network. You can change the portname with name and you will have to consult “wmic printer list” to see names or other parameters.

I know for some of you it is somehow hard to follow, due to a high level of trust with the user if you are not using some shared control connection program like VNC or DameWare. Also for those of you in companies that work with specific software for such things like RDP that doesn’t provide shared control and you would have to use the user’s password which in many cases is not acceptable. The other way is to be physically at the user’s computer but it would possibly imply more work.

However, if for any reasons you would need something like this, a way to delete a printer from a user’s profile without using LOG OFF for the user, MakeMeAdmin script along with WMIC and its features will help you a lot.

I would be glad to help any of you with answers for different situations regarding a similar problem, just pop a question and I will answer it ASAP. Keep in mind I am also willing to add any extra info or take in consideration your comments regarding new or different ways to do similar things.

To delete printer without log off for user running as administrator was a problem for me in the past but with the help of the script and WMIC I managed to complete my tasks without any extra action from the user.

VN:F [1.9.22_1171]
Rating: 5.0/5 (2 votes cast)
Delete printer without log off for user running as administrator, 5.0 out of 5 based on 2 ratings