disable/enable USB power & set printer as default

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jjlyon
Posts: 18
Joined: 11 Oct 2012 20:43

disable/enable USB power & set printer as default

#1 Post by jjlyon » 22 Apr 2013 09:48

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

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: disable/enable USB power & set printer as default

#2 Post by abc0502 » 22 Apr 2013 10:52

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.

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


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?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: disable/enable USB power & set printer as default

#3 Post by abc0502 » 22 Apr 2013 12:06

This Should install the printer you want to install.

Code: Select all

@Echo OFF
SET "PrinterName=HP 200"
Rem Install Printer
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%PrinterName%"

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

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

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

devcon find "USB\*"

jjlyon
Posts: 18
Joined: 11 Oct 2012 20:43

Re: disable/enable USB power & set printer as default

#4 Post by jjlyon » 24 Apr 2013 14:55

hi,thank you so much! they both work perfectly! :D

Post Reply