I would definitely recommend converting to PowerShell (It's easier, in my opinion) and has heaps of cmd-lets to help with things like this.
In this case we assume Google Chrome has 2 install paths, and therefore this is the main variable we need to account for. Using the Test-Path option we can dictate 2 UNC paths for the potential option.
Here is a script that uses the "Test-Path" we can test if Google Chrome exists in Program Files (x86), and if not, we assign the value of LocalAppData.
Here it is:
$ConfirmGoogleChrome = (Test-Path "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
$Process = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
function OpenChromeFullScreen {
If ($ConfirmGoogleChrome -eq $True) {
start $Process --start-fullscreen --app="https://www.netflix.com"
}
else {
$Process = "%localappdata%\google\chrome\application\chrome.exe"
start $Process --start-fullscreen --app="https://www.netflix.com"
}
}
OpenChromeFullScreen
Note that PowerShell was enabled by default in Windows Vista (I believe) and onwards, and requires the Net Framework to operate - which should be enabled on most moderns OS installs.
Update
Due to the comments stating this may not be as robust as required (as we cannot assume C:\
is the OS install path), I've done a little "improvement":
# Variables for the HomeDrive (OS Install Path)
# Inclusive of the path to AppData
$OSInstallPath = $env:HOMEDRIVE
$OSLocalAppData = $env:LOCALAPPDATA
# Performs Checks on the end path
$ChromeProgramFiles = (Test-Path "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")
$ChromeLocalAppData = (Test-Path "$OSLocalAppData\google\chrome\application\chrome.exe")
# Variable for Google Chrome Path
# We default this to Program Files
$GoogleChrome = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
# Function to set the paths
Function ConfirmSetPaths {
If ($ChromeProgramFiles -eq $False) {
$GoogleChrome = "$OSLocalAppData\google\chrome\application\chrome.exe"
}
}
ConfirmSetPaths
Start "$GoogleChrome" --start-fullscreen --app="https://www.netflix.com"
Essentially we create variables ("$OSInstappPath
" and "$OSLocalAppData
" which are system linked variables) for the install path on your PC (as the UNC path may change depending on who runs it.
Then we make an additional 2 variables for the two paths where chrome.exe
may exist. The function ConfirmSetPaths
will test if chrome.exe
exists at the "default" path on the PC (in this instance we used "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
").
If it does exist here, it starts the program. If not, it changes the variable for $GoogleChrome
to be the Local App Data folder, and then executes from here.
Changes:
- Now uses
$env
variables to dictate the OS Install Path;
program files
or per user in%localappdata%
. You can also query registry keys for its installation location. Searching the drive for it will be terribly inefficient. – Appleoddity Jan 11 '18 at 5:23