• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Writing a .bat file to install, execute, and uninstall antimalware/virus software

JM Aggie08

Diamond Member
I've written a .bat file to install mbam, spybot and mse from my flash drive. In addition, it updates, runs and uninstalls (-mse) the programs.

My only issue is that the drive letter will change varying from machine to machine.

How can I write it to point at my flash drive if the drive letter is going to be different on most machines?


For example, on my machine it is H: \, and on a buddy's, it's F: \

I hope i've given enough enough to get a solution.
 
If the .bat file is giong to be stored on the flash drive and run from there, you can just capture the .bat file from the %0 argument which is the path and filename of the script.

Code:
REM Capture the drive letter from the %0 variable
set my_drive=%~d0
REM Change the drive letter
%my_drive%

If there are some dependencies you have to validate or things you need to find, you can search for them and once you find them you can capture the output from the CD command which will display the current path.

Code:
REM For loop to parse the output of cd
FOR /F "tokens=1-4 delims=*" %%A IN ('cd') DO SET my_drive=%%A
 
I've never heard of that command before, but thanks!

Would that be put directly into the beginning of the code as written?
 
The code as written should be syntactically correct. It may not do everything you need, but it should get you started.

Where you put it in your code is pretty much up to you depending on your coding/formatting style and how you will use it. Batch scripts have a very limited use of scope in that most variables just end up being global, so you can access them from any point in the script.
 
Back
Top