Remove drive letters via batch or vbs scripting - batch-file

I am searching for a little batch or vbs script that does the following:
Find the drives in a list of valid drive letters, e.g. ['c','d','e','f'], that have a specific drive name, e.g. 'BackupDrive'
Remove the drive letters of the found drives so that they are no more displayed in Windows Explorer
Any suggestion is very appreciated.

You can do this using the command line tool "diskpart". As stated in the official technet documentation if you know the volume name you can remove it with:
select volume <volume number>
remove letter=<Letter>
You can automate this either using a script file (as documented here) with the exact commands, or by calling the exe with objShell.Exec on the shell object in vbscript and manipulating the stdin and stdout accordingly. An example for that can be found here. In your case this would probably be the better approach because you could do a "list volume" there and then parse the result for description and label and act accordingly. Afaik this is sadly the only way to get to the volume number, because it is not present in wmi or somewhere easier queryable.
Please keep in mind that diskpart is a VERY powerful tool, that can wipe whole partitions, so use it with caution.
Also note:
You cannot remove the drive letters on system, boot, or paging
volumes. In addition, you cannot remove the drive letter for an OEM
partition, any GPT partition with an unrecognized GUID, or any of the
special, non-data, GPT partitions such as the EFI system partition.

Related

FOR /f in DOS alternative

As it appears there is no version of DOS (6.22 to WinME "DOS") or FreeDOS that allows you to take part of a text file and make it a variable, I'm going to just keep collecting the data I get in DOS mode into one very large file but I can't think of a way to get each asset and UUID and add them together in a third file... Here is what I get at the moment:
SMBIOS.TXT
~~~~~~~(usually 27 lines of stuff I don't need)~~~~~~~
Asset Number: ABC12345
~~~~~~~(usually 37 lines of stuff I don't need)~~~~~~~
UUID: ABCDEF12345678901234567890
~~~~~~~(usually 4 lines of stuff I don't need, complicated by a # symbol in there too)~~~~~~~
^Repeated many times
I need to add both the Asset Number and the UUID together in a CSV format so I was previously hoping (before I exhausted all attempts at doing for /F in DOS) just echoing the two variables I was creating as follows:
ECHO !Asset!,!UUID!>>Results.CSV
Which again works in Windows command prompt just not DOS, the script I'm using however only gets the first variable of each so I need to do them in order and keep repeating through the file in the manner?
Alternatively is there any other way I could use DOS to get the info I need out of the two text files on the fly? It's all running from a USB stick so I don't have any size constraints at least.
Aaron
You may be able to get it done with the DOS command line text stream editor EDLIN.
I am assuming this has to be done in DOS and Windows is not an option.
PDGREPPE is an MS DOS command line GREP search and replace utility.
Maybe you can find a DOS Text Editor with Macros
Lotus 123?
DBase?
Write an app in DOS BASIC.

Making Bootable USB From DVD using Command line

Is there any way to create a boot-able USB from a windows DVD via command line?
It is accepted using third party application which accepts command line arguments.
I searched internet but did not found any way.
You can do this using the program diskpart which is included in windows.
You need the following steps:
SELECT DISK <DRIVE NUMBER>
CLEAN
CREATE PARTITION PRIMARY
SELECT PARTITION 1
ACTIVE
FORMAT FS=NTFS QUICK
ASSIGN
EXIT
save them in a txt file. Find out the drive number using "LIST DISK"
You can then call diskpart with the /s parameter and give the saved textfile as a script.
Afterwards you can copy the content of the dvd over.
Now as to really do this programmatically:
The main difficulty would be selecting the correct drive number in case it may vary.
The main problem however is that this is a pretty dangerous operation. If you select the wrong disk (as stated those drives are selected by number not even by their drive letter) instead of your usb drive you might format a partition of your harddrive. I would personally not really fully automate the task but rather do it by hand.

Find multiple files from the command line

Description:
I am searching a very large server for files that is on a different server. right now I open command prompt and type
DIR [FILE NAME] /S/4
This returns the server location of the file with some other stuff that is not really needed.
Question:
I have a lot of files to search and one by one input into the above command could take forever. Is there a way I could input all of the names of all the files and only search once and the search results would only need to show file name and location?
First, I hope you don't mean DOS, but rather Windows cmd or batch.
You can certainly write a script that will run your DIR command once per file being sought.
But what you most likely want instead is to search once and print the path of each file found. For this you can use PowerShell's FindChildItem or the improved one posted here: http://windows-powershell-scripts.blogspot.in/2009/08/unix-linux-find-equivalent-in.html
It will be something like:
Find-ChildItem -Name "firstfile.txt|secondfile.txt|..."
Another approach is to install msys or cygwin or another Linux tools environment for Windows and use the Linux find command.

How do I view or rename a file with missing extension?

I have a strange file in my file system without the extension part. The filename is "15.". The weird thing is that it is not one of those without the dot part (like just "15"), but the one with the dot but no extension ("15.") -- it is literally an illegal filename in windows, and not sure how did it get created in the first place.
I know it is a text file and it is about 15KB in size; however, due to the weirdness in name, I can't open it with any application -- I've tried to open in notepad, wordpad, etc., have tried the 'type' command to spit it out on commans shell, tried to shell-open enclosing filename in quotes, and so on -- all methods result in a 'file not found' error except the notepad, which says '15.txt' is not found.
Due to the nature of the issue and the way search engines optimize the search, it is extemely hard to search for an answer in any of the search engines online. So, I just wanted to put this question out there and see if anybody had to deal with a similar issue and have found any way to rename the file or even to change the extension.
Filenames that are valid in NTFS but cannot be used from Windows can be created when accesing disks or shares from other operating systems like Linux.
If you don't have a Linux installation at hand, then get hold of a "live" CD, boot Linux, and change the filename.
That may sound like a hassle, but Windows-only solutions (moving stuff around, deleting the directory) are even worse.
Use REN: http://ss64.com/nt/ren.html
It is a command prompt command (run > cmd > cd wherever > ren 15. 15.txt )

Filesystem links on a FAT32 formatted storage

I know FAT32, as well as FAT16/12 neither support symbolic links nor hard-links. However I came up with this idea:
The FAT specification describes that every file is associated with a directory-entry. In my understanding, one could say that a file-entry in a directory somehow or other points to the file's content.
So, how can I define two directory-entries which point to the same file-content? Or, what could prevent me from doing so?
Use case: I have a USB mass storage device for my car radio, and I want to use directories as playlists since the radio software doesn't support playlists. So it isn't important to me how Windows behaves when doing this.
This should work for simple issues. I.e. it works as a hack / workaround and I don't know what happens if you rename / move / remove files. So, you should not do this on your main hdd.
I edited the directory-entries manually using a hex editor. I modified clusters as well as file-sizes and successfully faked hardlinks. My car-radio and even Windows (7, 64Bit) have no problems with playing back the original and "hard-linked" mp3-Files I used.
When I'm opening the device again in the hex-editor none of my modifications are changed back (See chkdsk issue in answer #1 - but as far as I know chkdsk has to be started manually, anyways.
What you are talking about ("two directory-entries which are pointing to the same file-content") are hard links. chkdsk will report them as cross-links and break them, "repairing" the files (in fact making the copies).
MichaelPh posted instructions on SuperUser:
https://superuser.com/a/486829/51237
It's possible to use Disk Probe (on XP only, I've yet to get it to write the changes on Win7) to modify the cluster a FAT Directory references. This method can be used to redirect the DCIM folder (or a subfolder) to point to the folder used by a different scan device.
Whether this is a good idea or not is a different matter and you use this at your own risk.
Insert the Eye-Fi card either in it's USB Card Reader or directly into an SSD slot and note the drive letter it's installed as (assumed to be F:\ for simplicity)
Ensure all Windows Explorer windows for the card and sub-directories are closed.
Run Disk Probe
Select Drives->Logical Volume
In the Open Logical Volume dialog double-click F:\ in the Logical Volumes list
Click the Set Active button for the Handle F: has been selected as. You can leave the handle as read-only for now.
Select Tools->Search Sectors...
Check Exhaustive Search, enter DCIM in Enter characters to search for and Search
You should find a match (mine is at 8192). Select No on the "Found match..." dialog to cancel the rest of the search.
Select Sectors->Read and increase Number of Sectors to at least two so that the whole directory table is included.
Find DCIM in the ASCII on the right of the Disk Probe screen, this is the start of the FAT entry for the directory. Make a note of the hex value of the 27th byte of the record (each entry is 32bytes), this is the directory cluster reference. This value is require to revert the DCIM directory back to normal use if required.
Find the entry for the directory you want to redirect DCIM to and again make a note of the 27th byte in the record.
Go back to the 27th byte of the DCIM record and change it to the value noted in step 11.
Select Sectors->Write and then click Write it on the Write Sector dialog. A warning will come up if you opened the sectors as read-only. Yes to overwrite if you're happy to make the change.
Opening the DCIM directory in Windows Explorer will now show the contents of the target directory.

Resources