Computer Hope

Microsoft => Microsoft DOS => Topic started by: jik on February 04, 2009, 03:17:25 AM

Title: How to Control USB POrt (on/off) using batch file?
Post by: jik on February 04, 2009, 03:17:25 AM
Is this possible to make a batch file(MSDOS) that will turn off and on the USB port?

Ex.
Unpluging a USB device = OFF
PLUG = ON

Thanks!
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Dias de verano on February 04, 2009, 03:22:06 AM
You can with a free software utility called Usbdeview. Or Microsoft Devcon. Either of of which you would have to download and install.


Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: jik on February 04, 2009, 04:36:06 AM
Thanks A LOT... I Got DEVCON... and it works.....
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Dias de verano on February 04, 2009, 04:38:43 AM
Thanks A LOT... I Got DEVCON... and it works.....


 :)

Yay!!!
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 05, 2009, 08:31:57 AM
Consider changing your way of thinking on how to resolve your problem and use the MS DOS command "MOUNTVOL" as follows. In this example certain commands have been "remmed" out for safety.

rem By using the "MOUNTVOL" command USB drives used as backup-to-disk targets
rem can be either removed or plugged back in.
rem By using the "NET SHARE" command USB drives may be shared out to users.

c:
cd C:\windows\system32\

cls
@echo.
@echo.

rem This command displays both the details of the corresponding Volume Names and Paths
@echo on
call mountvol.exe
@echo off

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.

rem These commands removes the "volume mount point" from the "specified directory"
@echo on
rem This commands removes the drive letter F: from the USB device name
rem mountvol.exe F: /D
rem This commands removes the drive letter G: from the USB device name
rem mountvol.exe G: /D
@echo off

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.

rem This command displays both the details of the corresponding Volume Names and Paths
@echo on
call mountvol.exe
@echo off

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.

rem These commands assign the "volume mount point" to the "individual directory"
rem Should you be required to use the "volume mount point" for different USB Drives
rem You can mountvol different "individual directory" so long as there is only 1
rem USB drive plugged in at once.
@echo on
rem mountvol.exe F: \\?\Volume{f90aec0d-a238-11dd-8bd4-001c23d69c2e}\
rem mountvol.exe F: \\?\Volume{10badd33-a9b2-11dd-a3fc-001c23d69c2e}\
rem
rem mountvol.exe G: \\?\Volume{10badd33-a9b2-11dd-a3fc-001c23d69c2e}\
@echo off

rem F:\ = \\?\Volume{f90aec0d-a238-11dd-8bd4-001c23d69c2e}\
rem G:\ = \\?\Volume{10badd33-a9b2-11dd-a3fc-001c23d69c2e}\

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.

rem This command displays both the details of the corresponding Volume Names and Paths
@echo on
call mountvol.exe
@echo off

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.

rem This command displays the available "shares"
@echo on
net share
@echo off

@echo.
@echo.
pause


rem ***************
cls
@echo.
@echo.

rem This command stops sharing the available "shares"
@echo on
net share F /delete
net share G /delete
@echo off

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.
 
rem This command shares out the USB directory drive with an assigned shared name
@echo on
net share F=F:
net share G=G:
@echo off

@echo.
@echo.
pause

rem ***************
cls
@echo.
@echo.

rem This command displays the available "shares"
@echo on
net share
@echo off

@echo.
@echo. 
 
 
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: jik on February 10, 2009, 02:36:51 AM
Thanks  ;D... But I'm reseting USB MODEM.... Thanks for the reply!!!
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: BatchFileCommand on February 10, 2009, 06:07:31 AM
Hey Biker Steve,

Why do you have all those


@echo or @echo. then cls.

You just type @echo off and you don't need to have all those @'ts. Then you Just do @echo on to turn it back on again.
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Carbon Dudeoxide on February 10, 2009, 06:26:51 AM
And what will this file be used for?
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 11, 2009, 04:51:36 AM
In answer to the question “And what will this file be used for?”,

I am currently working on a solution to resolve the following issue. We have remote customers whom use USB hard drives to backup both their main file server and terminal server too. The terminal server is backed up to a USB hard drive which is attached too and shared out from the main file server. From time to time as the user rotates and exchanges the USB backup hard drives that are attached to the main file server the terminal server does not see the main file server newly attached shared out USB backup hard drive. It is our intention that each time a USB backup hard drive is attached to the main file server that it is both mounted and shared out by means of a MS DOS batch file that uses both the “mountvol”  and “net share” commands. The process is instigated from an “autorun.inf” file located on the root of each USB hard drive which in turn calls a MS DOS batch file which in turn calls the previously given example MS DOS batch file located on the main file server. I gave an example of a lengthy MS DOS batch file as I found no definitive answer to my issue when searching the Internet and others had not so dissimilar questions regarding mounting USB devices. My hope is that others may gain knowledge by way of my example. The additional 2 files mentioned are as follows;

Autorun.inf file contents
[autorun]
open=MountRUN.bat

MountRUN.bat file contents
@echo off
break on
c:
call c:\software\MountVol\MountUSB.bat
exit
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 13, 2009, 06:08:13 AM
In answer to the question "Why do you have all those @echo or @echo. then cls. You just type @echo off and you don't need to have all those @'ts. Then you Just do @echo on to turn it back on again.".

They are placed within the MS DOS batch file to aid in both the reading and the understanding of how the MS DOS commands execute within any given MSDOS command window.

Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Dias de verano on February 13, 2009, 02:48:39 PM
Biker Steve, he wants to know why you use all those @ signs in your code.

So do I.
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 18, 2009, 05:28:39 AM
In answer to “Dias de verano” following statement and question “Biker Steve, he wants to know whay you use all those @ signs in your code. So do I.”.

I already know why I used all those signs within my code as I am “Biker Steve” and for the benefit of answering “Dias de verano” question
here is my answer once again; “They are placed within the MS DOS batch file to aid in both the reading and the understanding of how the MS DOS commands execute within any given MSDOS command window.”.
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Dias de verano on February 18, 2009, 10:13:32 AM
It seems, Biker Steve, that you have failed to understand the question. Also, your use of all those @ signs proves that you do not understand batch code properly. And your answer begins to suggest that you are a troll.

Batchfilecommand, I expect he cannot answer the question because he copied the code and has no idea why the @ signs are there.



Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 18, 2009, 02:18:20 PM

You may wish to know that I have written thousands of MS-DOS batch files over many years.

The batch file uses some fundamental MS-DOS batch file commands.

The "@echo." command displays a blank line within an MS-DOS command Window.

The "@echo off" command turns off the display of MS-DOS commands within the MS-DOS command Window.

The "@echo on" command turns on the display of  MS-DOS commands within the MS-DOS command Window.

I do hope that I have  now answered your question.
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Dias de verano on February 18, 2009, 02:45:39 PM

You may wish to know that I have written thousands of MS-DOS batch files over many years.

The batch file uses some fundamental MS-DOS batch file commands.

The "@echo." command displays a blank line within an MS-DOS command Window.

The "@echo off" command turns off the display of MS-DOS commands within the MS-DOS command Window.

The "@echo on" command turns on the display of  MS-DOS commands within the MS-DOS command Window.

I do hope that I have  now answered your question.


We know about @echo off. We know what @echo does. We want to know why you have a zillion lines starting @echo when you could just put @echo off at the start. And use echo. instead of @echo.


Code: [Select]
rem This command displays the available "shares"
@echo on
net share
@echo off

And why you do this
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 18, 2009, 03:17:32 PM

The batch file uses some fundamental MS-DOS batch file commands.

The "rem" command is used in this instance to document the following procedure.

The "Net Share" command displays the current status of any active "share(s)".

The "@echo on" switches on the display of the "Net Share" command and when the command is completed the "@echo off" command switches the display of any further following command to "off" until such time as may be another "@echo on" command is executed.

I do hope that I have answered your question once again.

At this rate before I know it I will be a "Guru" on this site by just answering all your questions.

Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Dias de verano on February 18, 2009, 03:46:40 PM
But echo off / on merely suppresses the echoing of internal commands. You really don't understand batch, do you? All that your @echo on does is force a prompt to be displayed. And you still haven't answered the question. Because you can't, maybe?

v1.bat

Code: [Select]
@echo off
@echo Now running net share
@echo.
@echo on
net share
@echo off

v2.bat
Code: [Select]
@echo off
echo Now running net share
echo.
net share

The results...

Code: [Select]
S:\>v1.bat
Now running net share


S:\>net share

Share name   Resource                        Remark

-------------------------------------------------------------------------------
IPC$                                         Remote IPC
The command completed successfully.

Code: [Select]
S:\>v2.bat
Now running net share


Share name   Resource                        Remark

-------------------------------------------------------------------------------
IPC$                                         Remote IPC
The command completed successfully.

Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 18, 2009, 04:03:21 PM

 :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(

@echo off
break on
@echo.
@echo.
@echo.
@echo This has just become a futile discussion with your added sarcasms.
@echo.
@echo Therefore I am being mature about this and ending it here and now!
@echo.
@echo.
pause
exit

 :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: GuruGary on February 18, 2009, 08:27:29 PM
Poor Steve.  He was just trying to help. 

His code was long with a lot of extra statements and not very efficient, but I didn't see any obvious logic or syntax errors.  Looking at his code, I just assumed he worked for the government.
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: BatchRocks on February 19, 2009, 09:58:17 AM
@echo off
echo Dias is right.
echo.
pause>nul
exit.
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: BC_Programmer on February 19, 2009, 04:13:51 PM

 :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(

@echo off
break on


@echo.
@echo.
@echo.
@echo This has just become a futile discussion with your added sarcasms.
@echo.
@echo Therefore I am being mature about this and ending it here and now!
@echo.
@echo.
pause
exit

 :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'( :'(

why the "BREAK"?

according to the output from "help break"

Quote
This is present for Compatibility with DOS systems. It has no effect
under Windows XP
.

If Command Extensions are enabled, and running on the Windows XP
platform, then the BREAK command will enter a hard coded breakpoint
if being debugged by a debugger.

And even with a DOS targeted batch the "Break" command at least as far as I know is only a Config.sys command.

LOL I just had to keep the prodding up  ;)
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: Biker Steve on February 20, 2009, 06:18:08 PM

When under taking the MS DOS "Help Break" command you have failed to mention that the command also displays the line "Sets or Clears Extended Ctrl+C checking on DOS systems".

In simple terms what this means is that when executing this fundamental "Break On" command from within a MS-DOS batch file a user can terminate the operation of the MS-DOS file prematurely by pressing both the "Ctrl and C" keyboard keys together. You will then be asked "Terminate batch job (Y/N)".


Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: macdad- on February 20, 2009, 06:49:15 PM
lets just say to the OP, get MS's Devcon.....

end of story....bye bye...see you later
Title: Re: How to Control USB POrt (on/off) using batch file?
Post by: BC_Programmer on February 20, 2009, 08:46:06 PM

When under taking the MS DOS "Help Break" command you have failed to mention that the command also displays the line "Sets or Clears Extended Ctrl+C checking on DOS systems".

In simple terms what this means is that when executing this fundamental "Break On" command from within a MS-DOS batch file a user can terminate the operation of the MS-DOS file prematurely by pressing both the "Ctrl and C" keyboard keys together. You will then be asked "Terminate batch job (Y/N)".





True, but considering there is no MOUNTVOL or a few other commands used in that batch, it's a bit silly to add something that only works on Pure DOS.