Jump to content

Find printer registry [solved]


Recommended Posts

Hi i'm looking for a way to search in the registry a certain printer if it finds that printer, exit the rest of the batch file else continu the batch file. Here is what i've got


@echo off
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul && (
net use P: \\10.10.10.46\partage\PS555 /persistent:No
xcopy /Q /h /Y P:\*.* c:\temp\
c:\temp\PrintDBGSP.vbs
c:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=F
net use P: /delete /y
del c:\temp /F /Q
)

If it finds the name TOSHIBA e-STUDIO555Series PS3 Printer in the registry hive...exit the batch file...but for some reason it still operate...

thanks for the help

Edited by JFMichaud
Link to comment
Share on other sites


As i don't see any "IF" statement in your batch, it's obvious that it will always do all the steps.

Hmmm.

Try entering this on command line (NO IF's):

type qwertymnbvcxz >nul 2>&1 &&ECHO You won't see this

Then:

type qwertymnbvcxz >nul 2>&1 ||ECHO You will see this

;)

@JFMichaud

TRY this (your original one should work, though :unsure:):

@echo off

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOF

net use P: \\10.10.10.46\partage\PS555 /persistent:No

xcopy /Q /h /Y P:\*.* c:\temp\

c:\temp\PrintDBGSP.vbs

c:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=F

net use P: /delete /y

del c:\temp /F /Q

Post the output of

 reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"

maybe there is a typo somewhere....

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

Post the output of

 reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"

maybe there is a typo somewhere....

jaclaz

Hi thanks for the help...I've changed the registry key...to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers and made the change to the batch command line....


Microsoft Windows XP [version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

U:\>REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\P
rint\Printers"

! REG.EXE VERSION 3.0

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers
DefaultSpoolDirectory REG_SZ C:\WINDOWS\System32\spool\PRINTERS

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\H
P LaserJet 4050 Series PS LabDS

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\M
icrosoft XPS Document Writer

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO4520CSeries PS3 Photocopieur Secrétariat

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO455Series PS3 3ième étage

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO455Series PS3 Local 1er Étage

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO455Series PS3 Local RdC

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO455Series PS3 Photocopieur RdC

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO555Series PS3 Photocopieur 2ieme Étage

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO555Series PS3 Photocopieur L2-11

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO555Series PS3 Photocopieur L262

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\T
OSHIBA e-STUDIO855Series PS3 Photocopieur RdC

U:\>

my code is


@echo off
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOF
net use P: \\10.10.10.46\partage\PS555 /persistent:No
xcopy /Q /h /Y P:\*.* c:\temp\
c:\temp\PrintDBGSP.vbs
c:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=F
net use P: /delete /y
del c:\temp /F /Q

In the list there is no TOSHIBA e-STUDIO555Series PS3 Printer so the batch file should execute....but i won't

Thanks

Link to comment
Share on other sites

In the list there is no TOSHIBA e-STUDIO555Series PS3 Printer so the batch file should execute....but i won't

It's strange as it works here (of course with another printer name).

Can you try running this simplified version (change "PDFill" with that TOSHIBA printer, but try also with another one).

@echo off

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "PDFill" >nul &&ECHO "Found"

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "nodevice" >nul ||ECHO "NOT Found"

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "PDFill" >nul

ECHO %ERRORLEVEL%

reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "nodevice" >nul

ECHO %ERRORLEVEL%

THe output here is (correctly):

"Found"

"NOT Found"

0

1

Could it be that accented characters make an issue? Like é, è, etc?

jaclaz

Link to comment
Share on other sites


@echo off
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf" >nul &&ECHO "Found"
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf" >nul ||ECHO "NOT Found"

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf" >nul
ECHO %ERRORLEVEL%

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf" >nul
ECHO %ERRORLEVEL%
pause

output (the TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf) is not installed

"NOT Found"

1

1

If i test with a printer that is installed the output is

"Found"

0

0

even if i use a name witch É..accented characters and the printer is installed...the output is

"Found"

0

0

Edited by JFMichaud
Link to comment
Share on other sites

Yes i've managed to write it down and now it's working....


@echo off
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul"
if errorlevel 1 goto install
if errorlevel 0 goto end
goto end
:install
net use P: \\10.10.10.46\Partage\PS555 /persistent:No
xcopy /Q /h /Y P:\*.* c:\temp\
c:\temp\PrintDBGSP.vbs
c:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=F
net use P: /delete /y
del c:\temp /F /Q
exit
:end

Thanks to Jaclaz for helping me out, i appreciate the help

Link to comment
Share on other sites

my code is


@echo off
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOF
net use …

In the list there is no TOSHIBA e-STUDIO555Series PS3 Printer so the batch file should execute....but i won't

You appear to have misunderstood the use of || and &&. What your script does is state that if the TOSHIBA search string is unsuccessful goto end of file whereas you wanted the reverse.

Basically || means 'if the last command was unsuccessful' whereas && means 'if the last command succeeded'.

Simply replacing || with && should prevent the continuation error.

You actually made the same mistake in your opening script too and jaclaz added to the confusion by mimicking that in their example.

In your working script the fourth line is completely redundant and can be removed.

Link to comment
Share on other sites

I am sorry :( if I added to the confusion, I simply posted two examples with "direct" and "inverse" logic. :unsure:

What you ended up doing was reversing the logic and the command thus achieving the same result.

|find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOF
 |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul && (
net use…

Link to comment
Share on other sites

What you ended up doing was reversing the logic and the command thus achieving the same result.

Yes, I was not sure having understood what was actually asked, so I posted an example with both logics in post #5.

In any case the problem - one way or the other - is solved. :)

jaclaz

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...