How to close specific Chrome profile that was opened with cmd/bat? - google-chrome

I need to close all windows of a specific Chrome profile. Suppose I execute:
chrome.exe -remote-debugging-port=4000 --user-data-dir=F://chrome
in cmd/bat to open a new Chrome profile. I need to close this specific Chrome profile from cmd/bat.
I have tried this:
taskkill /IM chrome.exe -remote-debugging-port=4000 --user-data-dir=F://chrome
but it's not working.

You can accomplish this using the batch file below:
for /f "tokens=3 delims=," %%a in ('wmic process where "caption='chrome.exe'" get processID^,commandline /format:csv ^| FIND "-remote-debugging-port=4000 --user-data-dir=F://chrome"') do set _pid=%%a
taskkill /f /pid %_pid% /t
Explanation
wmic process where "caption='chrome.exe'" get processID^,commandline /format:csv lists all chrome.exe processes with the command line used to launch them and the process ID that we will use to kill it.
Piping (|) this into FIND "-remote-debugging-port=4000 --user-data-dir=F://chrome" will return only the chrome.exe process started with the command you used.
for /f "tokens=3 delims=," %%a in ("...") do set _pid=%%a will set the _pid environment variable to the process ID of the process we want to kill.
The wmic command combined with the find command should only give us a single result. If you used the command multiple times, then this will only find the process ID of the last process in the list.
taskkill /f /pid %_pid% /t:
/f forces the task to end, because otherwise Chrome will remain open.
/pid %_pid% will supply the process ID we got in the for loop.
/t tells taskkill to kill the entire process tree.
Since every Chrome tab and extension runs in its own process, we want to make sure these get killed as well.

Related

Batch file to find chrome installed path dynamically

I need to check for the chrome browser in any Windows system by running a .bat file. The batch file should be able to check if Chrome browser is installed in the system. if its installed want to store the path in a variable and use that.I am creating chrome kiosk app..so need to find the chrome path dynamically.Please help me
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --kiosk --fullscreen --incognito "website url"
After our discussion in chat, we found that if chrome is not installed, it will not launch. therefore simply use:
start "" "chrome" --kiosk --fullscreen --incognito "https://www.netflix.com/"
We need to ensure that all other chrome windows are closed as it will not open kiosk mode if chrome is already open.
That means if chrome is not found by default using start it is not installed.
Older tries:
This batch file is assuming chrome is installed correctly:
for /F "delims=" %%a in ('where chrome') do (
start "" "%%a" --kiosk --fullscreen --incognito "website url"
)
pause
Once you confirmed that it is working, simply remove echo from the last line to actually perform the start.
The next option, seeing as where might not work is too search for the file.
pushd C:
cd\
for /F "delims=" %%a IN ('dir /b /a-d /s chrome.exe') do (
start "" "%%a" --kiosk --fullscreen --incognito "https://www.netflix.com/in/"
)
pause
The simple solution is:
start "" chrome.exe --kiosk --fullscreen --incognito "website url"
It is necessary to specify an empty title with "" or command START interprets the first double quoted string as optional title string. Run in a command prompt window start /? for help on this command and its options.
The reason for starting successfully Chrome without full path and without its folder path being included in environment variable PATH is explained in answer on Where is START searching for executables?
chrome.exe is (usually) registered correct according to guidelines of Microsoft for Application Registration. So START is capable finding the path of Chrome application itself.
Solution with first checking if Chrome is installed and registered at all:
#echo off
%SystemRoot%\System32\reg.exe query "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe" >nul 2>&1
if not errorlevel 1 start "" chrome.exe --kiosk --fullscreen --incognito "website url"

Batch File to start chrome:chrome and update

I am trying to write a batch file to force Google Chrome to Update. If I use the following it is close however the batch file below takes out the : and shows a This Site Can't Be Reached notification:
#echo on
start chrome.exe \chrome://chrome
pause
If I had a batch file to open chrome:chrome in a startup page that would be helpful as well.
You could use the profile manager and create a user/profile with chrome://chrome as the start page. Or manually/per batch create a copy of the preferences file in "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default" and switch between two versions of the file.
The following batch will just create a backup with datetime appended to the name to start with.
#Echo off
:: GetISODT
for /f "tokens=1-3 delims=.+-" %%A in (
'wmic os get LocalDateTime^|findstr ^^[0-9]'
) do Set _DT=%%A
Pushd "%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default"
copy Preferences Preferences_%_DT%
start chrome

Windows Batch Script for 2 Cases

I use the following .bat script
set varSearch="C:\Users\User1\Desktop\Test-folder\*.crypt8"
for /f %%i in ('dir %varSearch% /B ') do set varSearch= %%i
WhatsAppViewer.exe -decrypt8 %myName% key exp.db
sqlite3.exe exp.db<command.txt
cd C:\xampp\mysql\bin
mysql -u admin -p1234 < query.txt
The basic function is to find a file thats ending with .crypt8, decrypt it, save as csv and import to mysql. Its working correctly
But i need some extra features
Case1
The folder contains more than 1 file, and every file has to be processed, but only once
Case 2
Everyday at least one file gets added. It would be superb if the .bat could be scheduled as a task, and run every night and just process the new added files.
Does anybody has a solution for this?
Case 2
The forfiles command processes groups of files based on date. This does files made today only.
forfiles /d 0 /m *.crypt8 /c "cmd /c echo #fname in #path"
Case 1
Your code has errors, it may work but not under all conditions.
The easist way is to put the sequence of commands in a batchfile for a file (%1) which is passed on command line, and use forfiles to call it.

Separate session for each window

I am trying to create an extension where each window of chrome has its own session. We used incognito earlier, but the problem is that while the main window and the incognito window have separate sessions, the session is shared between the various incognito windows.
Is there any way of configuring chrome to use a separate session every time an incognito window is opened?
Your goal will be start a Chrome instance with a new user data directory. The cookies will be isolated in each instance.
In the extension to implement a way to reach the same goal as this command on cmd:
chrome.exe --user-data-dir="C:\temp\user1"
I had a similar problem where i want to use google chrome for browsing and debugging for work and chrome is pretty original when it comes to sessions. I wrote this small batch script to duplicate the default profile, clear session information and then use the new profile. Old duplicate profiles are also cleared before the new ones are created. The result is a new session with all the old profile stuff.
#echo off
rem folder prefix for the new profile folder
set folderNameStart=profile_
rem generate and format the date creating the new folder name
For /f "tokens=1-6 delims=/ " %%a in ('date /t') do (set mydate=%%c%%b%%a)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
set folderName=%folderNameStart%%mydate%%mytime%%random%
rem set the profile path and the folder destination as well as the directory to
delete
set profilePath="C:\Documents and
Settings\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default"
set profileDestination="C:\Documents and
Settings\%USERNAME%\AppData\Local\Google\Chrome\User Data\"%folderName%
set profileLocation="C:\Documents and
Settings\%USERNAME%\AppData\Local\Google\Chrome\User Data\"
rem iterate through directory and delete all the existing profile folders
CD %profileLocation%
echo %profileLocation%
for /D /r %%G in ("%folderNameStart%*") do rmdir /q /s "%%G"
rem this will copy the old profile directory
echo D | xcopy %profilePath% %profileDestination%
rem delete the session storage and its contents if its exist
rmdir /q /s "C:\Documents and Settings\%USERNAME%\AppData\Local\Google\Chrome\User
Data\%folderName%\Session Storage"
rem start google chrome with the new profile folder
start "Chrome" "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="%folderName%"
To make it work need to know difference between open "new window" in chrome, if there no difference then no way to do it in that case. Another way if know what difference when use incognito mode and use it to add in chrome "Open tab in new window pofile 1".

Delete all instances of acad.lsp on C:\ except for

I'm using the following code to delete all instances of Acad.lsp found on my C:\ drive but I want to make one exception, which is C:\Autocad 2010\Support.
How can I achieve this?
del "C:\ICT\acad.lsp" /q /a /s
From a command line you could use the batch file for command (I'm assuming that you're using a Windows command prompt or similar here). This is a powerful command that will let you loop through a set of "things" - with the right options, these "things" may be files.
The following command, when run in the C:\ICT directory, should do what you want:
for /F "usebackq" %a in (`dir /s /b acad.lsp ^| find /v "C:\Autocad 2010\Support"`) do #echo %a
Note that I'm using #echo here so that you can test that the results are as you expect before you change the #echo to del.
If you wanted to put this into a batch file, you should change %a to %%a.
A little explanation on what's happening:
for /F "usebackq" %a in (...) runs the command that is between the back-quotes, and runs the command following the do on each item that results. The command in my example above does a recursive dir for the file acad.lsp, and puts that through the find command to remove the one you want to keep. The remaining files are the ones that you will want to delete.