INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Batch Script or VB Script Help  (Read 2011 times)

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Batch Script or VB Script Help
« on: November 27, 2011, 10:17:40 pm »

Is anybody any good at these types of scripts.. (Batch Script or VB Script) I think the latter will only work for this

What I wan't to do is make a script that will change the drive letter of the hard drive in which the script file is located to Z:

The reason I want to do this is because I want to backup my library on to an external hard drive but on this hard drive I also want a portable installation of MC.. I wish to set the directory to Z so that is never conflicts with anything on any other computer system.. This would allow me to take my library and use it on other peoples computers when I am away... Having this script would make it painless to change to drive letter of my external hard drive when I plug it into different computers. I wouldn't have to waffle thought the computer management console every time, just a nice double click on my script file and away I go... Hopefully..

After some Goolgling, I've found some code that shoud do the trick, I just need some help to alter it

Changing the Drive Letter of a Volume


Changes the drive letter of volume D to Q. If you modify this script to change the drive letter of a volume other than D, note that the volume name in the WQL query must include both the colon ( : ) and two forward slashes (\\). Thus drive C would look like this: C:\\. When specifying the new drive letter, however, you only have to include the colon (in the sample script, Q:).
Code: [Select]
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colVolumes = objWMIService.ExecQuery _
    ("Select * from Win32_Volume Where Name = 'D:\\'")
For Each objVolume in colVolumes
    objVolume.DriveLetter = "Q:"
    objVolume.Put_
Next

I think the above code just needs altered.. How do you use Vbscript to call  on the currect drive letter in which the file is excecuted?? If that can be placed in a variable in the top.. I can then just replace the D:\\ in
Quote
    ("Select * from Win32_Volume Where Name = 'D:\\'")
with the variable that calls on the current drive letter..

Thanks
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Batch Script or VB Script Help
« Reply #1 on: November 27, 2011, 10:51:54 pm »

It might be easier to just use SUBST.  You know about it?
Logged
The opinions I express represent my own folly.

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Batch Script or VB Script Help
« Reply #2 on: November 27, 2011, 11:29:39 pm »

No, I don't but will look into it.. It looks a lot safer.. I've already nearly messed up one drive.. Most of my programs are installed on my d drive and I changed the drive letter to z lol..

It isn't letting me change it back.. Although I don't understand why it did it in the first place, because I have lots of open programs from my D drive. I think I'll have to do a safe boot to change it back, maybe the files are locked in memory somehow.. I'm amazed my computer hasn't crashed yet..

Yeah I suppose I can use the code that calls on the drive letter from where the file is executed and merge it with this command somehow

Thanks..
Logged

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Batch Script or VB Script Help
« Reply #3 on: November 28, 2011, 02:12:39 am »

Thanks again MrC

Found a script that does the trick

Code: [Select]
Dim Act :Set Act = CreateObject("Wscript.Shell")
 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
 Dim Target
 Dim D1, D2, D3
'/-> Set The Target Folder Path Without The Drive Letter
  Target = "Virtual Folder"
   For Each D1 In Fso.Drives
        If D1.IsReady Then
'/-> Add The Drive Letter To Target
         D2 = D1.DriveLetter & ":\"
         D3 = D2 & Target
'/-> If Folder Found Run The Subst
          If Fso.FolderExists(D3) Then
           Act.Run(_
           "%Comspec% /C @ECHO OFF && CLS && COLOR F9 && MODE 55,7 && " &_
           "TITLE SUBST && Echo. && Echo Processing  SUBST cmd && " &_
           "SUBST Z: " & Chr(34) & D3 & Chr(34) & " && Z:\Music\Readme.txt && " &_
           "SUBST Z: /D && Exit"),1,True
          End If
        End If
   Next

Just need to test it & seeif MC can recognise the files... I have two hard drive on my main pc c & d, and my external drive letter is e.. So I'll have to test it on a pc where the external shows up as d...

Even though the files have a virtual path  in the script beginning with the root of Z, I'll have test if it works when the absolute path changes.. from E to D..

Hope so

Thanks
Logged

Mr ChriZ

  • Citizen of the Universe
  • *****
  • Posts: 4375
  • :-D
Re: Batch Script or VB Script Help
« Reply #4 on: November 28, 2011, 02:17:40 am »

You're aware that MC finds files using the drive location "(Install Drive):\\"
Which works no matter what drive letter the drive partition takes?

locust

  • Citizen of the Universe
  • *****
  • Posts: 699
Re: Batch Script or VB Script Help
« Reply #5 on: November 28, 2011, 03:05:30 am »

No I wasn't aware of that.... I just presumed I would have to do this for MC to find the files.. Thanks..
Logged
Pages: [1]   Go Up