MSFN Forum: Find printer registry [solved] - MSFN Forum

Jump to content


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Find printer registry [solved] Rate Topic: -----

#1 User is offline   JFMichaud 

  • Group: Members
  • Posts: 9
  • Joined: 20-February 12
  • OS:none specified
  • Country: Country Flag

Posted 20 February 2012 - 12:13 PM

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

This post has been edited by JFMichaud: 20 February 2012 - 04:26 PM



#2 User is offline   allen2 

  • Not really Newbie
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,751
  • Joined: 13-January 06

Posted 20 February 2012 - 01:16 PM

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

#3 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 20 February 2012 - 01:38 PM

View Postallen2, on 20 February 2012 - 01:16 PM, said:

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:):

Quote

@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

This post has been edited by jaclaz: 20 February 2012 - 02:03 PM


#4 User is offline   JFMichaud 

  • Group: Members
  • Posts: 9
  • Joined: 20-February 12
  • OS:none specified
  • Country: Country Flag

Posted 20 February 2012 - 02:21 PM

View Postjaclaz, on 20 February 2012 - 01:38 PM, said:

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

#5 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 20 February 2012 - 02:38 PM

View PostJFMichaud, on 20 February 2012 - 02:21 PM, said:

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).

Quote

@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):

Quote

"Found"
"NOT Found"
0
1


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

jaclaz

#6 User is offline   JFMichaud 

  • Group: Members
  • Posts: 9
  • Joined: 20-February 12
  • OS:none specified
  • Country: Country Flag

Posted 20 February 2012 - 02:46 PM

@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

This post has been edited by JFMichaud: 20 February 2012 - 02:53 PM


#7 User is offline   JFMichaud 

  • Group: Members
  • Posts: 9
  • Joined: 20-February 12
  • OS:none specified
  • Country: Country Flag

Posted 20 February 2012 - 03:43 PM

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

#8 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 20 February 2012 - 04:39 PM

View PostJFMichaud, on 20 February 2012 - 02:21 PM, said:

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.

#9 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 21 February 2012 - 03:06 AM

View PostYzöwl, on 20 February 2012 - 04:39 PM, said:

and jaclaz added to the confusion by mimicking that in their example.


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

jaclaz

#10 User is offline   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,369
  • Joined: 13-October 04
  • OS:Windows 7 x64

Posted 21 February 2012 - 04:05 AM

View Postjaclaz, on 21 February 2012 - 03:06 AM, said:

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.

View Postjaclaz, on 20 February 2012 - 01:38 PM, said:

Quote

|find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOF

View PostJFMichaud, on 20 February 2012 - 12:13 PM, said:

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


#11 User is online   bphlpt 

  • MSFN Expert
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,117
  • Joined: 12-May 07

Posted 21 February 2012 - 04:32 AM

Yep, the first post as it is currently revised will not work. Need to change && to || - again. LOL

Cheers and Regards

This post has been edited by bphlpt: 21 February 2012 - 04:33 AM


#12 User is offline   jaclaz 

  • The Finder
  • Group: Developers
  • Posts: 11,578
  • Joined: 23-July 04
  • OS:none specified
  • Country: Country Flag

Posted 21 February 2012 - 05:12 AM

View PostYzöwl, on 21 February 2012 - 04:05 AM, said:

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2013 msfn.org
Privacy Policy