DPenfold Posted November 15, 2016 Posted November 15, 2016 (edited) Hi all, Earlier this year I’ve created a VBA (Visual Basic) script to run DVD/Audio CDs on VLC, this was to help members of staff at our school open audio cds and dvds with ease. Often we would get calls about playing discs so I tried to simplify this as best as I could so classes would not be disrupted/delayed. Now the staff selects a shortcut from the desktop (either “Play Audio CD” or “Play DVD”) and it open disc in VLC Player. The script itself does the following; Checks if you have an optical drive (an error message would display if one is not found) It stores the drive letter for later use Checks which version of VLC (x86/x64 bit) is currently installed (an error message will display if one is not found and for domain users it would ask if you wish to install VLC) It then creates the appropriate run command (using the drive letter, correct program path and which media type the disc to open audio/dvd) It the runs the created run command VLC will open the disc currently in optical drive in the correct media (depending on which shortcut selected) I will put the code below (too large for this post so I'd post it in the next post) but I have also attached a zipped [ATTACH=CONFIG]39802[/ATTACH] to make things easier for anyone, it will contain the following; X2 Shortcuts (some editing needed) x2 Icon files (optional, you can create your own at https://iconverticons.com/) x2 vba scripts (one for Audio one for DVDs - very minor editing needed) x1 read me.txt file explain what will need editing to work on your network If you have any issues or suggestions please do let me know and I’d be happy to help best as I can, I’m still learning VBA so I’d like to ask if you make any adjustments to the script (other than what is suggested) please do let me know as I’d like to see and learn from the changes you made, thanks . If I get any suggestions I'll add name and thanks here Edited November 15, 2016 by DPenfold Potential thanking list from suggestions
DPenfold Posted November 15, 2016 Author Posted November 15, 2016 (edited) Audio CD Script 'Open Audio CDs on VLC, created by David Penfold (Birmingham, UK) 2016'This Freeware scriping, you are welcome to make alterations though I'd like to ask to let me know as I am still'learning VB Scripting ([email protected])'Search/Find #InstallVLC if you need to change the installation path of VLC'Variable needed to check Drive letter for optical driveConst DriveTypeCDROM = 4Set oFS = Wscript.CreateObject("Scripting.FileSystemObject")Set oDrives = oFS.Drives 'Loop thru A-Z. If found, exit early'Paths to both x64 & x86 versioni of VLC stored into a variablePatchx64 = chr(34) & "C:\Program Files\VideoLAN\VLC\vlc.exe" & chr(34) & " dvd:///"Patchx86 = chr(34) & "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" & chr(34) & " dvd:///"'ObjectsSet fso = CreateObject("Scripting.FileSystemObject")Set shl = CreateObject("WScript.Shell")Set WshShellx64CD = CreateObject("WScript.Shell")Set WshShellx86CD = CreateObject("WScript.Shell") For Each Drive in oDrives 'Identifies Drive letter for optical drive If Drive.DriveType = DriveTypeCDROM Then ODD = Drive.DriveLetter End If Next'Checks if ODD is Blank (If there is a DVD/CD Drive)If ODD = "" Then'Gives error message if no drive foundMsgBox "No DVD/CD Drive found, please make sure it is connected or contact the ICT Technicians",16,"No DVD/CD Drive found"'If drive found continues with opening VLCElse 'Checks if path exists, depending the corresponding IF Statement will commence exists = fso.FileExists("C:\Program Files (x86)\VideoLAN\VLC\vlc.exe") 'If x86 path exists then Opens VLC in this path and open Disc as DVD if (exists) then 'Uses stored drive letter variable then stores it in VLC variable VLCX86 = Patchx86 & ODD & ":/" 'Runs command using the newly created variable (Opens VLC depending on previous commands) Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run VLCX86 Set oShell = Nothing' 'If x64 path exists then Opens VLC in this path and open Disc as DVD Else 'Checks if path exists, depending the corresponding IF Statement will commence exists = fso.FileExists("C:\Program Files\VideoLAN\VLC\vlc.exe") 'If x86 path exists then Opens VLC in this path and open Disc as DVD if (exists) then 'Uses stored drive letter variable then stores it in VLC variable VLCX64 = Patchx64 & ODD & ":/" 'Runs command using the newly created variable (Opens VLC depending on previous commands) Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run VLCX64 Set oShell = Nothing' 'If x64 nor x86 path exists then Displays Error Message Else 'Gives error message if no drive found 'MsgBox "No VLC Media Player Found, please contact the ICT Technicians",16,"No VLC Media Player found" 'Option Explicit 'Will ask user if they wish to install VLC result = MsgBox ("No VLC Media Player Found, Do you wish to install the VideoLAN Client (VLC) Media Player? Otherwise please contact the ICT Technicians", vbYesNo + 32 , "VLC Media Player not found!") 'Actions based on user result Select Case result 'Actions if User selected to install VLC Case vbYes 'Path to VLC Installation .exe (Change if needed! #InstallVLC) VLCInstallPath = "\\App1\apps$\SOFT\VLC\2.2.4\vlc-2.2.4-win32.exe" 'Path and command for silent install of VLC VLCInstall = chr(34) & VLCInstallPath & chr(34) & " /language=en_GB /S" Dim objShell,grouplistD,ADSPath,userPath,listGroup On Error Resume Next set objShell = WScript.CreateObject( "WScript.Shell" ) 'Calls the isMember function with the specified group to see if the current user is a member of that group. If isMember("Domain Admins") Then 'Test command/MsgBox if user is a memeber of Domain Admin 'MsgBox EnvString("username") & " is member of the Domain Admins on " & EnvString("userdomain"),64,"Admin User?" ' Do something here if they are a member of the group 'Displays VLC instal .exe path to Domain Admins (incase of error) and gives option to cancel result = MsgBox ("The Current VLC Installation Path is - " & VLCInstallPath & " - Do you wish to continue with the installation?",1 + 64,"VLC Install Location") 'Command to end script if cancel is selected Select Case result Case vbOk MsgBox "You have chosen to install the VLC Media Player, Please wait a few minutes as this will be done quietly in the background. Thank You!" ,64,"Installing VLC Media Player" Case vbCancel MsgBox "You have chosen to cancel the installation!",48,"Cancelled installation!" WScript.quit() End Select 'Temp install command for Domain Admins Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run VLCInstall Set oShell = Nothing WScript.quit() Else 'Test command/MsgBox if user is not a memeber of Domain Admin 'MsgBox EnvString("username") & " is not member of the Domain Admins on " & EnvString("userdomain"),48,"Admin User?" ' Do something here if they are not a member of the group 'MsgBox "You have chosen to install the VLC Media Player, Please wait a few minutes as this will be done quietly in the background. Thank You!" ,64,"Installing VLC Media Player" MsgBox EnvString("username") & " does not have Adminisistrator previlages to install VLC Media Player, Please contact the ICT Technicians for support" ,48,"Not an Admin User?" ' Do something here if they are not a member of the group WScript.quit() End If 'Following not my script, used to determin is member of domain admins on Active Directory ' ***************************************************** 'This function checks to see if the passed group name contains the current ' user as a member. Returns True or False Function IsMember(groupName) If IsEmpty(groupListD) then Set groupListD = CreateObject("Scripting.Dictionary") groupListD.CompareMode = 1 ADSPath = EnvString("userdomain") & "/" & EnvString("username") Set userPath = GetObject("WinNT://" & ADSPath & ",user") For Each listGroup in userPath.Groups groupListD.Add listGroup.Name, "-" Next End if IsMember = CBool(groupListD.Exists(groupName)) End Function ' ***************************************************** ' ***************************************************** 'This function returns a particular environment variable's value. ' for example, if you use EnvString("username"), it would return ' the value of %username%. Function EnvString(variable) variable = "%" & variable & "%" EnvString = objShell.ExpandEnvironmentStrings(variable) End Function ' ***************************************************** 'Set oShell = WScript.CreateObject ("WScript.Shell") 'oShell.run VLCInstall 'Set oShell = Nothing 'Actions if User selected not to install VLC Case vbNo MsgBox "You have chosen not to install VLC Media Player!",48,"Not to install VLC Media Player" End Select End IF End IFEnd IF[/Code] [b][u]DVD Script[/u][/b] [code]'Open Audio CDs on VLC, created by David Penfold (Birmingham, UK) 2016'This Freeware scriping, you are welcome to make alterations though I'd like to ask to let me know as I am still'learning VB Scripting ([email protected])'Search/Find #InstallVLC if you need to change the installation path of VLC'Variable needed to check Drive letter for optical driveConst DriveTypeCDROM = 4Set oFS = Wscript.CreateObject("Scripting.FileSystemObject")Set oDrives = oFS.Drives 'Loop thru A-Z. If found, exit early'Paths to both x64 & x86 versioni of VLC stored into a variablePatchx64 = chr(34) & "C:\Program Files\VideoLAN\VLC\vlc.exe" & chr(34) & " dvd:///"Patchx86 = chr(34) & "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe" & chr(34) & " dvd:///"'ObjectsSet fso = CreateObject("Scripting.FileSystemObject")Set shl = CreateObject("WScript.Shell")Set WshShellx64CD = CreateObject("WScript.Shell")Set WshShellx86CD = CreateObject("WScript.Shell") For Each Drive in oDrives 'Identifies Drive letter for optical drive If Drive.DriveType = DriveTypeCDROM Then ODD = Drive.DriveLetter End If Next'Checks if ODD is Blank (If there is a DVD/CD Drive)If ODD = "" Then'Gives error message if no drive foundMsgBox "No DVD/CD Drive found, please make sure it is connected or contact the ICT Technicians",16,"No DVD/CD Drive found"'If drive found continues with opening VLCElse 'Checks if path exists, depending the corresponding IF Statement will commence exists = fso.FileExists("C:\Program Files (x86)\VideoLAN\VLC\vlc.exe") 'If x86 path exists then Opens VLC in this path and open Disc as DVD if (exists) then 'Uses stored drive letter variable then stores it in VLC variable VLCX86 = Patchx86 & ODD & ":/" 'Runs command using the newly created variable (Opens VLC depending on previous commands) Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run VLCX86 Set oShell = Nothing' 'If x64 path exists then Opens VLC in this path and open Disc as DVD Else 'Checks if path exists, depending the corresponding IF Statement will commence exists = fso.FileExists("C:\Program Files\VideoLAN\VLC\vlc.exe") 'If x86 path exists then Opens VLC in this path and open Disc as DVD if (exists) then 'Uses stored drive letter variable then stores it in VLC variable VLCX64 = Patchx64 & ODD & ":/" 'Runs command using the newly created variable (Opens VLC depending on previous commands) Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run VLCX64 Set oShell = Nothing' 'If x64 nor x86 path exists then Displays Error Message Else 'Gives error message if no drive found 'MsgBox "No VLC Media Player Found, please contact the ICT Technicians",16,"No VLC Media Player found" 'Option Explicit 'Will ask user if they wish to install VLC result = MsgBox ("No VLC Media Player Found, Do you wish to install the VideoLAN Client (VLC) Media Player? Otherwise please contact the ICT Technicians", vbYesNo + 32 , "VLC Media Player not found!") 'Actions based on user result Select Case result 'Actions if User selected to install VLC Case vbYes 'Path to VLC Installation .exe (Change if needed! #InstallVLC) VLCInstallPath = "\\App1\apps$\SOFT\VLC\2.2.4\vlc-2.2.4-win32.exe" 'Path and command for silent install of VLC VLCInstall = chr(34) & VLCInstallPath & chr(34) & " /language=en_GB /S" Dim objShell,grouplistD,ADSPath,userPath,listGroup On Error Resume Next set objShell = WScript.CreateObject( "WScript.Shell" ) 'Calls the isMember function with the specified group to see if the current user is a member of that group. If isMember("Domain Admins") Then 'Test command/MsgBox if user is a memeber of Domain Admin 'MsgBox EnvString("username") & " is member of the Domain Admins on " & EnvString("userdomain"),64,"Admin User?" ' Do something here if they are a member of the group 'Displays VLC instal .exe path to Domain Admins (incase of error) and gives option to cancel result = MsgBox ("The Current VLC Installation Path is - " & VLCInstallPath & " - Do you wish to continue with the installation?",1 + 64,"VLC Install Location") 'Command to end script if cancel is selected Select Case result Case vbOk MsgBox "You have chosen to install the VLC Media Player, Please wait a few minutes as this will be done quietly in the background. Thank You!" ,64,"Installing VLC Media Player" Case vbCancel MsgBox "You have chosen to cancel the installation!",48,"Cancelled installation!" WScript.quit() End Select 'Temp install command for Domain Admins Set oShell = WScript.CreateObject ("WScript.Shell") oShell.run VLCInstall Set oShell = Nothing WScript.quit() Else 'Test command/MsgBox if user is not a memeber of Domain Admin 'MsgBox EnvString("username") & " is not member of the Domain Admins on " & EnvString("userdomain"),48,"Admin User?" ' Do something here if they are not a member of the group 'MsgBox "You have chosen to install the VLC Media Player, Please wait a few minutes as this will be done quietly in the background. Thank You!" ,64,"Installing VLC Media Player" MsgBox EnvString("username") & " does not have Adminisistrator previlages to install VLC Media Player, Please contact the ICT Technicians for support" ,48,"Not an Admin User?" ' Do something here if they are not a member of the group WScript.quit() End If 'Following not my script, used to determin is member of domain admins on Active Directory ' ***************************************************** 'This function checks to see if the passed group name contains the current ' user as a member. Returns True or False Function IsMember(groupName) If IsEmpty(groupListD) then Set groupListD = CreateObject("Scripting.Dictionary") groupListD.CompareMode = 1 ADSPath = EnvString("userdomain") & "/" & EnvString("username") Set userPath = GetObject("WinNT://" & ADSPath & ",user") For Each listGroup in userPath.Groups groupListD.Add listGroup.Name, "-" Next End if IsMember = CBool(groupListD.Exists(groupName)) End Function ' ***************************************************** ' ***************************************************** 'This function returns a particular environment variable's value. ' for example, if you use EnvString("username"), it would return ' the value of %username%. Function EnvString(variable) variable = "%" & variable & "%" EnvString = objShell.ExpandEnvironmentStrings(variable) End Function ' ***************************************************** 'Set oShell = WScript.CreateObject ("WScript.Shell") 'oShell.run VLCInstall 'Set oShell = Nothing 'Actions if User selected not to install VLC Case vbNo MsgBox "You have chosen not to install VLC Media Player!",48,"Not to install VLC Media Player" End Select End IF End IFEnd IF Sorry EduGeek Fourm (coding) kinda messed up the structure of the code it may be easier to download the zip file:( Edited November 15, 2016 by DPenfold
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now