Generic USB Drive Letter
Moderator: DosItHelp
Generic USB Drive Letter
Hi anyone tried not to assign any specific drive letter to your USB using a script
sample code I am making
robocopy "%%\CTI\*.pptx" "%AppData%\Microsoft\Signatures"
start %APPDATA%\Microsoft\Signatures
::start outlook.exe
pause
I want on the first line after the command robocopy a code or keyword for a generic USB drive letter assignment is that possible? Because it is not always drive E: and etc its random depending upon the computer you are connected to right
sample code I am making
robocopy "%%\CTI\*.pptx" "%AppData%\Microsoft\Signatures"
start %APPDATA%\Microsoft\Signatures
::start outlook.exe
pause
I want on the first line after the command robocopy a code or keyword for a generic USB drive letter assignment is that possible? Because it is not always drive E: and etc its random depending upon the computer you are connected to right
Re: Generic USB Drive Letter
First things first…your RoboCopy command is incorrect. Please open a Command Prompt window, type %SystemRoot%\System32\Robocopy.exe /? and press the [ENTER] key to find out its basic syntax.
Code: Select all
ROBOCOPY source destination [file]
Re: Generic USB Drive Letter
Compo wrote: ↑06 Mar 2023 15:02First things first…your RoboCopy command is incorrect. Please open a Command Prompt window, type %SystemRoot%\System32\Robocopy.exe /? and press the [ENTER] key to find out its basic syntax.
robocopy "E:\CTI\" "%AppData%\Microsoft\Signatures"Code: Select all
ROBOCOPY source destination [file]
Here I have modified it for clarity I was just wondering how to make E: as generic not all PC say your USB is E: right how to make it detected by the computer as any drive letter that is available but still could also deploy the script?
I have tried %% and a lot of combinations do not work or I still just don't get the right combination any assistance will be much appreciated
Re: Generic USB Drive Letter
I know what you're trying to do, but until you have the basic code correct, I'm not going to add more to it.
You have now submitted a modified RoboCopy command line, which is still invalid/incorrect.
The source and destination should not end with trailing backward slashes. In your case above you need to use "E:\CTI", because the trailing backward slash in "E:\CTI\" is escaping the adjacent doublequote.
You have now submitted a modified RoboCopy command line, which is still invalid/incorrect.
The source and destination should not end with trailing backward slashes. In your case above you need to use "E:\CTI", because the trailing backward slash in "E:\CTI\" is escaping the adjacent doublequote.
Re: Generic USB Drive Letter
robocopy "E:\CTI" "%AppData%\Microsoft\Signatures" here the corrected commandCompo wrote: ↑07 Mar 2023 11:37I know what you're trying to do, but until you have the basic code correct, I'm not going to add more to it.
You have now submitted a modified RoboCopy command line, which is still invalid/incorrect.
The source and destination should not end with trailing backward slashes. In your case above you need to use "E:\CTI", because the trailing backward slash in "E:\CTI\" is escaping the adjacent doublequote.
Cool you also give tips and explanations of how things are done. Now I have made the code corrected as you can now see thanks to your info.
Please what is lacking from the script for the USB generic drive letter part
Re: Generic USB Drive Letter
You can just find what drive letter matches the USB.
Code: Select all
for %u in (D E F G H I J K L) do (for /F "tokens=3" %a in ('fsutil fsinfo drivetype %u:') do (if "%a"=="Removable" (set _USBDRIVELETTER=%u&echo %u is an USB)))
Re: Generic USB Drive Letter
If your system has access to WMIC, you can define the USB drive letter as a variable rather easily like this:
Subsequently, you can use 'if defined usbDrive' to perform some action on that drive, like:
Code: Select all
for /f "skip=2 tokens=2 delims=," %%g in ('%__APPDIR__%wbem\WMIC.exe logicaldisk where "drivetype=2" get DeviceID 2^>nul /format:csv') do set "usbDrive=%%g"
Code: Select all
if defined usbDrive (cd /d %usbDrive%) else (echo There is no attached USB Drive.)
Re: Generic USB Drive Letter
atfon wrote: ↑09 Mar 2023 09:10If your system has access to WMIC, you can define the USB drive letter as a variable rather easily like this:
Subsequently, you can use 'if defined usbDrive' to perform some action on that drive, like:Code: Select all
for /f "skip=2 tokens=2 delims=," %%g in ('%__APPDIR__%wbem\WMIC.exe logicaldisk where "drivetype=2" get DeviceID 2^>nul /format:csv') do set "usbDrive=%%g"
Code: Select all
if defined usbDrive (cd /d %usbDrive%) else (echo There is no attached USB Drive.)
I will try and play with the code thanks...............
Re: Generic USB Drive Letter
Thanks for this I used the first one the second what do you mean by define USB drive thing? But I have already make a walk around for it thank you so much palatfon wrote: ↑09 Mar 2023 09:10If your system has access to WMIC, you can define the USB drive letter as a variable rather easily like this:
Subsequently, you can use 'if defined usbDrive' to perform some action on that drive, like:Code: Select all
for /f "skip=2 tokens=2 delims=," %%g in ('%__APPDIR__%wbem\WMIC.exe logicaldisk where "drivetype=2" get DeviceID 2^>nul /format:csv') do set "usbDrive=%%g"
Code: Select all
if defined usbDrive (cd /d %usbDrive%) else (echo There is no attached USB Drive.)
-
- Expert
- Posts: 1166
- Joined: 06 Sep 2013 21:28
- Location: Virginia, United States
Re: Generic USB Drive Letter
if defined usbDrive means that there is a variable called usbDrive that has some value. It's effectively the same code as if not "%usbDrive%"=="" but with less typing.xiro wrote: ↑10 Mar 2023 01:26Thanks for this I used the first one the second what do you mean by define USB drive thing? But I have already make a walk around for it thank you so much palatfon wrote: ↑09 Mar 2023 09:10If your system has access to WMIC, you can define the USB drive letter as a variable rather easily like this:
Subsequently, you can use 'if defined usbDrive' to perform some action on that drive, like:Code: Select all
for /f "skip=2 tokens=2 delims=," %%g in ('%__APPDIR__%wbem\WMIC.exe logicaldisk where "drivetype=2" get DeviceID 2^>nul /format:csv') do set "usbDrive=%%g"
Code: Select all
if defined usbDrive (cd /d %usbDrive%) else (echo There is no attached USB Drive.)
Re: Generic USB Drive Letter
Thanks for thisShadowThief wrote: ↑12 Mar 2023 19:02if defined usbDrive means that there is a variable called usbDrive that has some value. It's effectively the same code as if not "%usbDrive%"=="" but with less typing.xiro wrote: ↑10 Mar 2023 01:26Thanks for this I used the first one the second what do you mean by define USB drive thing? But I have already make a walk around for it thank you so much palatfon wrote: ↑09 Mar 2023 09:10If your system has access to WMIC, you can define the USB drive letter as a variable rather easily like this:
Subsequently, you can use 'if defined usbDrive' to perform some action on that drive, like:Code: Select all
for /f "skip=2 tokens=2 delims=," %%g in ('%__APPDIR__%wbem\WMIC.exe logicaldisk where "drivetype=2" get DeviceID 2^>nul /format:csv') do set "usbDrive=%%g"
Code: Select all
if defined usbDrive (cd /d %usbDrive%) else (echo There is no attached USB Drive.)