hi all, i have opened a new topic because this problem is different form others i have had in the past. i need 3 batch files:
1: set a printer as default
my business runs a lot of different printers and some batch printing software along with some automation software. i need a batch file that can set a specific printer as default. i will have about 5 copy's of this batch file each setting a particular printer as default. for example:
epson.bat
hp 120.bat
hp 900.bat
brother.bat...
2: disable power to a specific USB port (or just disabling it all together) and another batch file that enables it again
this is a harder one and i have looked for other solutions but a batch file would be the easiest way to integrate it with my automation software. this is probably the last major step in completely automating my business and all my machinery and would be incredibly invaluable to my work. if its easier, a batch file that disables all usb ports would work aswell. since i only control my computer over network, i dont have to worry about disabling the keyboard and mouse
if it helps in any way there's batch files will be running on windows xp
kind regards
josh
disable/enable USB power & set printer as default
Moderator: DosItHelp
Re: disable/enable USB power & set printer as default
You will have to provide the exact name of your printers as they appear, run this code and it should save the printer names in a file on your desktop, then post the names here.
Leave Empty Line at the end of this batch file
Also, disabling the USB will require a 3rd party tool "devcon.exe", you can find it in Microsoft website.
it can be written inside the batch using carlos BHX tool and all will be in a single batch file, is that ok?
Code: Select all
@Echo OFF
rem Create the VBScript, if not exist
(
FOR /F "tokens=1*" %%a IN ('findstr "^:printer: " ^< "%~F0"') DO Echo.%%b
)>"printer.vbs"
Cscript //nologo "printer.vbs" >> "%userprofile%\Desktop\PrinterList.txt"
pause
:printer: strComputer = "."
:printer: Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
:printer: Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
:printer: num=1
:printer: For Each objPrinter in colInstalledPrinters
:printer: Wscript.Echo num & ") " & objPrinter.Name
:printer: num = num + 1
:printer: Next
REM Leave Empty Line After This One
Also, disabling the USB will require a 3rd party tool "devcon.exe", you can find it in Microsoft website.
it can be written inside the batch using carlos BHX tool and all will be in a single batch file, is that ok?
Re: disable/enable USB power & set printer as default
This Should install the printer you want to install.
SET The Printer name in 2nd line.
About the Devcon.exe, couldn't make it inside the batch, so you will need to download it from
Microsoft website, "it's a single exe file" place it in "C:\Windows\System32" then you can run this
two batch files to enable or disable all USB ports.
Disable USB Ports
Enable USB Ports
You might need to restart your pc, to make USB ports work
set the USBRootHub Variable with the USB ID like "USB\ROOT_HUB\4&10C3B2A4&0", or leave it
with usb\* to disable all or enable all.
To Find all Your USB IDs do this in your cmd window
Code: Select all
@Echo OFF
SET "PrinterName=HP 200"
Rem Install Printer
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%PrinterName%"
About the Devcon.exe, couldn't make it inside the batch, so you will need to download it from
Microsoft website, "it's a single exe file" place it in "C:\Windows\System32" then you can run this
two batch files to enable or disable all USB ports.
Disable USB Ports
Code: Select all
@Echo OFF
Rem You can either set the USB Root Hub Name like "USB\ROOT_HUB\4&10C3B2A4&0" or place
"usb\*" to disable all
SET "USBRootHub=USB\*"
Rem Enable The USB
devcon.exe disable "%USBRootHub%"
Pause
Enable USB Ports
Code: Select all
@Echo OFF
Rem You can eather set the USB Root Hub Name like "USB\ROOT_HUB\4&10C3B2A4&0" or place
USB\* to disable all
SET "USBRootHub=USB\*"
Rem Enable The USB
devcon.exe enable "%USBRootHub%"
devcon.exe restart "%USBRootHub%"
Pause
set the USBRootHub Variable with the USB ID like "USB\ROOT_HUB\4&10C3B2A4&0", or leave it
with usb\* to disable all or enable all.
To Find all Your USB IDs do this in your cmd window
Code: Select all
devcon find "USB\*"
Re: disable/enable USB power & set printer as default
hi,thank you so much! they both work perfectly!