JFMichaud Posted February 20, 2012 Share Posted February 20, 2012 (edited) 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 offreg 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:Noxcopy /Q /h /Y P:\*.* c:\temp\c:\temp\PrintDBGSP.vbsc:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=Fnet use P: /delete /ydel 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 February 20, 2012 by JFMichaud Link to comment Share on other sites More sharing options...
allen2 Posted February 20, 2012 Share Posted February 20, 2012 As i don't see any "IF" statement in your batch, it's obvious that it will always do all the steps. Link to comment Share on other sites More sharing options...
jaclaz Posted February 20, 2012 Share Posted February 20, 2012 (edited) 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 thisThen:type qwertymnbvcxz >nul 2>&1 ||ECHO You will see this@JFMichaudTRY this (your original one should work, though ):@echo offreg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOFnet use P: \\10.10.10.46\partage\PS555 /persistent:Noxcopy /Q /h /Y P:\*.* c:\temp\c:\temp\PrintDBGSP.vbsc:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=Fnet use P: /delete /ydel c:\temp /F /QPost the output of reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"maybe there is a typo somewhere....jaclaz Edited February 20, 2012 by jaclaz Link to comment Share on other sites More sharing options...
JFMichaud Posted February 20, 2012 Author Share Posted February 20, 2012 Post the output of reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices"maybe there is a typo somewhere....jaclazHi 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\Print\Printers"! REG.EXE VERSION 3.0HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers DefaultSpoolDirectory REG_SZ C:\WINDOWS\System32\spool\PRINTERSHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\HP LaserJet 4050 Series PS LabDSHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\Microsoft XPS Document WriterHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO4520CSeries PS3 Photocopieur SecrétariatHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO455Series PS3 3ième étageHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO455Series PS3 Local 1er ÉtageHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO455Series PS3 Local RdCHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO455Series PS3 Photocopieur RdCHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO555Series PS3 Photocopieur 2ieme ÉtageHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO555Series PS3 Photocopieur L2-11HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO555Series PS3 Photocopieur L262HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\TOSHIBA e-STUDIO855Series PS3 Photocopieur RdCU:\>my code is@echo offreg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOFnet use P: \\10.10.10.46\partage\PS555 /persistent:Noxcopy /Q /h /Y P:\*.* c:\temp\c:\temp\PrintDBGSP.vbsc:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=Fnet use P: /delete /ydel c:\temp /F /QIn the list there is no TOSHIBA e-STUDIO555Series PS3 Printer so the batch file should execute....but i won'tThanks Link to comment Share on other sites More sharing options...
jaclaz Posted February 20, 2012 Share Posted February 20, 2012 In the list there is no TOSHIBA e-STUDIO555Series PS3 Printer so the batch file should execute....but i won'tIt'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 offreg 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" >nulECHO %ERRORLEVEL%reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Devices" |find /I "nodevice" >nulECHO %ERRORLEVEL%THe output here is (correctly):"Found""NOT Found"01Could it be that accented characters make an issue? Like é, è, etc?jaclaz Link to comment Share on other sites More sharing options...
JFMichaud Posted February 20, 2012 Author Share Posted February 20, 2012 (edited) @echo offreg 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" >nulECHO %ERRORLEVEL%reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf" >nulECHO %ERRORLEVEL%pauseoutput (the TOSHIBA e-STUDIO555Series PS3 Photocopieur SProf) is not installed"NOT Found"11If i test with a printer that is installed the output is"Found"00even if i use a name witch É..accented characters and the printer is installed...the output is"Found"00 Edited February 20, 2012 by JFMichaud Link to comment Share on other sites More sharing options...
JFMichaud Posted February 20, 2012 Author Share Posted February 20, 2012 Yes i've managed to write it down and now it's working....@echo offreg 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 endgoto end :install net use P: \\10.10.10.46\Partage\PS555 /persistent:Noxcopy /Q /h /Y P:\*.* c:\temp\c:\temp\PrintDBGSP.vbsc:\temp\SUBINACL /verbose=1 /printer "TOSHIBA e-STUDIO555Series PS3 Printer" /grant="Everyone"=Fnet use P: /delete /ydel c:\temp /F /Qexit:endThanks to Jaclaz for helping me out, i appreciate the help Link to comment Share on other sites More sharing options...
Yzöwl Posted February 20, 2012 Share Posted February 20, 2012 my code is@echo offreg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers" |find /I "TOSHIBA e-STUDIO555Series PS3 Printer" >nul ||GOTO :EOFnet use …In the list there is no TOSHIBA e-STUDIO555Series PS3 Printer so the batch file should execute....but i won'tYou 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 More sharing options...
jaclaz Posted February 21, 2012 Share Posted February 21, 2012 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. jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted February 21, 2012 Share Posted February 21, 2012 I am sorry if I added to the confusion, I simply posted two examples with "direct" and "inverse" logic. 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 More sharing options...
bphlpt Posted February 21, 2012 Share Posted February 21, 2012 (edited) Yep, the first post as it is currently revised will not work. Need to change && to || - again. LOLCheers and Regards Edited February 21, 2012 by bphlpt Link to comment Share on other sites More sharing options...
jaclaz Posted February 21, 2012 Share Posted February 21, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now