A way to delete all printer except %name1% and %name2% with batch script - batch-file

I'm searching A way to delete all printer except %name1% and %name2% with batch script on client computer.
Powershell scripts doesn't work for me cause there is old non-updated windows 7 computers on my network.
I tried :
#echo off
wmic printer where "NOT name like '%PDF24%' AND NOT name like '%Microsoft Print to PDF%'" delete
exit
It doesn't work. All printers are deleted.
Can you give me a hand?
:-)

Related

Printing ZPL file using Batch File Issue

We run NetSuite for our shipping software and use Zebra ZP450 printer to print the thermal label.
The software downloads a .zpl file which I have assigned to run with a batch file, script here:
Net use LPT2: \\%ComputerName%\ZebraFedex
Copy %1 LPT2
Net use LPT2: /Delete
I have installed this on probably 20 or more computers without an issue. But the last two will initiate the batch file but not print.
I was able to hit pause on the batch file and here is what I got:
C:\users\noah\downloads\net use LPT2: \(ComputerName)\ZebraFedex
The command completed successfully
C:\Users\Noah\Downloads\Copy LPT2
The system cannot find the file specified. 0 files copied
C:\Users\Noah\Downloads>Net use LPT2: /Delete
I've checked my file association, which seems correct since I see the command prompt flash on the screen. I have no idea here...
Working successfully on another computer
Problem on puzzling computer
Here's my batch to transfer file to my venerable TLP2844:
#ECHO OFF
SETLOCAL
FOR %%a IN (%*) DO (
IF EXIST "%%a" (COPY /b "%%~a" \\%computername%\TLP2844
) ELSE (
IF EXIST "%%a.txt" (
COPY /b "%%~a.txt" \\%computername%\TLP2844
) else (
ECHO Neither "%%a" nor "%%a.txt" appears to EXIST
)
)
)
where I have a printer called TLP2844 installed as a ZDesigner TLP 2844 device on USB003.
The problem, as shown by the graphics I've included in your question (saves running off chasing links) is that the label file C:\users\melan\downloads\UPSSHIPPINGLABEL1700448.zpl is being provided to the batch as %1 (first parameter). On the problem installation, no filename (presumably C:\users\Noah\downloads\UPSSHIPPINGLABEL???????.zpl is being provided to the batch as %1.
Therefore it's not a batch problem, but a problem with Netsuite.
From your .pdf, on page 26 :
To install a thermal printer driver on a Windows PC:
...
5. In the Share Name field, enter the name of the printer. For example, LP 2844.
The printer name cannot contain spaces.
So you're told the printer name cannot contain spaces, but the example printer name contains a space....Excellent! (shows my level of confidence in the product, but not actually directly relevant to the problem) :(
Personally, I'd change your batch file to
Copy %1 \\%ComputerName%\ZebraFedex
Perhaps you'd try that after fixing the problem where Netsuite fails to deliver the filename to the batch. Perhaps it's set up to produce .pdfs on the computer in question (That's a wild guess)
In response to reply:
Please change your batch file (temporarily for test purposes) to this:
Echo File to print : "%1"
Net use LPT2: \\%ComputerName%\ZebraFedex
Copy %1 LPT2
Net use LPT2: /Delete
PAUSE
which will report the filename supplied by Netsuite to the batch file on the console window, then keep the window open at the end of the batch until the open window receives a keystroke.
Please report results for both a "working" and a "buggy" installation.
Change .bat file like below, replacing the printer share name with your own. Happened on one of our critical computers that is also the host for FedEx/UPS.
C:\WINDOWS\system32\net.exe use LPT2: \\%ComputerName%\Zebra_ZP500_Shipping_FedEx1
Copy %1 LPT2
C:\WINDOWS\system32\net.exe use LPT2: /Delete
Thank you Noah Schultz for the Pause suggestion for batch file, and to QWERTY for article on Net command issue
Reference

bat file to prompt for user to input computer name

As I have to install multiple computers.....is there any way to use:
WMIC ComputerSystem where Name=COMPUTERNAME call Rename Name=NewName
but instead of "NewName" to prompt an input name....
the reason I ask, is I don't want to give same computer name to all computers, and I dont want to edit the bat file for each computer.
I'm also using:
net user username password /ADD
for this one, can I also get a prompt to insert desired user and password so I don't need to give same username and password or to edit the bat file
is there any what to automate this with users's input interaction?
Since it appears you want an automated way to change your PC name, this script should help you. Keep in mind you will have to reboot your PC for the effects to take place.
For the computer name, we can automate that using a dirty method of %computername%
#ECHO OFF
SET NEWNAME=
SET /P NEWNAME= Select a new PC name:
::Change PC Name
WMIC ComputerSystem where Name='%computername%' call Rename Name=%NEWNAME%
CLS
Echo Process Complete..
Pause.
Keep in mind that you can edit a remote PC on the same network using the script bellow. You can throw this in a batch file and change multiple PC's at once.
WMIC /node:"Jon-Laptop" /user:Admin /password:password123 computersystem call rename "Jon-Tech"

cacls only works intermittently

I am using cacls to set permissions on files and folders in a batch file.
Cacls c:\program1 /e /g joebloggs:f >>c:\users\desktop\script-log.txt 2>&1
Crazy thing is it works sometimes and not others.
The output of the command is redirected to a text file and it shows "processed c:\program1"
But when I go to double check the result, the user joebloggs is not in the acls list (Security tab).
I have tried this on an identical machine with the same image and then it works sometimes!
It has to work every time.
Anyone know why this occurs?

My batch script keeps writing something in CMD though I only use ping command

My problem is that i have created a .bat file which is looking like this
#echo off
ping google.com -n 2
if not errorlevel 1 echo %date% %time% We did get a response from Google >> C:\CMD\ping.log
if errorlevel 1 echo %date% %time% We didn't get a response from Google >> C:\CMD\ping.log
It's simple and all it does is try ping google.com two times, and if we get a response log "We did get a response from google" else log "we didn't get a response from Google", both with a timestamp to the file ping.log, which is just a text file.
The Batch Script is working when i am using it on my own pc (windows 7), but when i move it the the server then when i click run on the script, it opens up CMD and just keeps writing something over and over again. I don't know exactly what it is writing, but as far as I could spot (because it keeps write in the CMD very fast), is somehting that #echo off was not reckognized. When i run the script it doesn't create or write to the files as it's supposed to.
Please anyone who can help me.
It sounds like the file encoding is set to something other than ANSI.
Open your .bat file in Notepad on the server and select File->Save As.
Save it as the same name, but make sure the encoding is set to ANSI.

Variables in Batch FTP script

In C you can use %username% as a variable for the current user's name for directory listings and such: c:\documents and settings\%username%\
Is there something like this for a batch script?
Using just %username% doesn't seem to help.
I wrote a script that accesses my FTP server so I can load files to the server.
I want my friends to be able to use this script, but I don't want to have to write several different scripts.
Here is what I have so far:
#echo off
#ftp -s:"%~f0" &GOTO: EOF
open FTP.server.com
user
pass
cd /home/ftp
bin
lcd "c:\documents and settings\%username%\my documents\FTP"
mput *txt
pause
bye
There's gotta be a way
This can be done if you change the batch file so that it creates a script file every time the batch file runs. You can do this by using the echo command to write the script lines to script file, which you can then pass to the ftp command. The reason this works is that echo will expand the %username% variable before writing it to the script file:
#echo off
del script.txt
echo open FTP.server.com>>script.txt
.
[echo rest of script lines to file]
.
echo lcd "c:\documents and settings\%username%\my documents\FTP">>script.txt
echo echo mput *txt>>script.txt
#ftp -s:script.txt
I believe i found a better way, although it's a bit more code.
set "rootdir=%userprofile%\my documents"
set "destdir=c:\
for /f "delims=" %%a in ('dir /b /s "%rootdir%*.txt"') do copy "%%~a" "%destdir%"
And then the usual FTP stuff, including lcd c:\
Ive tested this and it works, although I would like to find a simpler way.
I tried using xcopy but for some reason it doesn't work on my system, the cmd screen just hangs.
Also tried just using copy, but that gave me "can't find file" errors.
Instead of using lcd, a better idea might be to change the working directory in the outer batch file.
#echo off
#pushd "c:\documents and settings\%username%\my documents\FTP"
#ftp -s:"%~f0" &GOTO: EOF
open FTP.server.com
user
pass
cd /home/ftp
bin
mput *txt
#pause
The only problem with this solution, is that the script itself is no longer in the working directory, and so you need to add a path for that. (Or, put it in the FTP folder ;)
Also, minor pedantry, but this is not actually a correct way to find My documents. In particular, on Vista or Windows 7, User profiles are stored in C:\Users. And, it's possible for users to move My Documents (on my computer, My Documents is located in D:\Mike's Documents)
However, there doesn't appear to be an environment variable that points directly at My Documents, so you will have to make do with this:
"%userprofile%\my documents\FTP"
If the people running this script are running XP and haven't moved their My Documents, then this doesn't really matter.

Resources