Jump to content

Can someone please help me with if exist command


Sull

Recommended Posts

I would like to change My Documents to D:\ but only if D:\ exists, I don't know what command would do this. I found this in another thread which changes My Documents to D:\

;Change location of my documents
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
"Personal" ="D:\\"

I would like for it to look if D:\ exists and if it does then apply the reg entry..

Thank you

Sull

Link to comment
Share on other sites


Here is a VBS script that checks

1:\ It a hard drive

2:\ Checks For D Drive

3:\ Checks To Make Sure The Reg File Exists

You will have to supply the path to the reg file

Save As CheckDrv.vbs

 Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Drv, Reg
Reg = "Your\Path\To\Reg.reg"
For Each Drv In Fso.Drives
If Drv.DriveType = 2 Then '-> Make Sure It A Hard Drive
If InStr(Drv.DriveLetter,"D") Then '-> Checks The Drive Letter
If Fso.FileExists(Reg) Then '-> Make Sure The Reg File Exists
Act.Run("regedit /S " & Reg),0,True
End If
End If
End If
Next

Link to comment
Share on other sites

Thank you, would the location below be ok ?

 Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Drv, Reg
Reg = "%SYSTEMDRIVE%\Install\DS.reg"
For Each Drv In Fso.Drives
If Drv.DriveType = 2 Then '-> Make Sure It A Hard Drive
If InStr(Drv.DriveLetter,"D") Then '-> Checks The Drive Letter
If Fso.FileExists(Reg) Then '-> Make Sure The Reg File Exists
Act.Run("regedit /S " & Reg),0,True
End If
End If
End If
Next

Now can I just run this script from my cleanup.cmd ?

Link to comment
Share on other sites

Thank you, would the location below be ok ?

No Change It To This

 Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Drv, Reg
Reg = Act.ExpandEnvironmentStrings("%SYSTEMDRIVE%\Install\DS.reg")
For Each Drv In Fso.Drives
If Drv.DriveType = 2 Then '-> Make Sure It A Hard Drive
If InStr(Drv.DriveLetter,"D") Then '-> Checks The Drive Letter
If Fso.FileExists(Reg) Then '-> Make Sure The Reg File Exists
Act.Run("regedit /S " & Reg),0,True
End If
End If
End If
Next

Now can I just run this script from my cleanup.cmd ?

Yes you can

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...