i made a zip file containing a google chrome extension pack and made it "public" via a download link (lets say its http://someaddress.com/extension.zip).
Then, i looked a lot on stackoverflow and found multiple approaches to add this extension as "automatically" as possible (without publishing it on the google store).
I came up with this BATCH file:
#echo off
setlocal
cd /d %~dp0
set dwURI="http://someaddress.com/extension.zip"
set tpZIP="%temp%\extension.zip"
call :DownloadFile %dwURI% %tpZIP%
call :UnZipFile "%AppData%" %tpZIP%
del "%temp%\extension.zip"
taskkill /f /im "chrome.exe"
start chrome --load-extension="%AppData%\extension"
start "%AppData%\extension"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\unzip.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If Not fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
:DownloadFile <URL> <DownloadTo>
bitsadmin /transfer mydownloadjob /download /priority FOREGROUND %1 %2
cls
To actually "install" the extension the command ended up beeing this one line start chrome --load-extension="%AppData%\extension" that sets the extension unpacked path to load.
My problem: it only loads the extension on that particular call. If i close chrome and open it again it's not there, it doesn't "auto load".
If i go to the appdata folder and install the unpacked extension on google chrome enableing the developer option and seeking that folder it stays "installed".
Is there a "--install-extension:" command on google chrome that i cannot find, or is there another way to order it do install it?
Related
I have to start a Web Application with a batch file in the Chrome Browser with a predefined process ID so i can kill that specific Chrome Window later with another batch file. Is there any way to to this?
By typing this command on the CMD console you can see how to create a process :
wmic process call create /?
And this too : How to terminate a Process :
wmic process call terminate /?
So, you can give a try for this batch file :
#echo off
set "targetfile=C:\Program Files\Google\Chrome\Application\chrome.exe"
set targetfile=%targetfile:\=\\%
#for /f "tokens=2 delims==; " %%# in ('wmic PROCESS CALL CREATE "%targetfile%" ^|findstr /I "ProcessId"') do set "PID=%%#"
echo The Process is created with PID=%PID%
pause
wmic process where ProcessId="%PID%" call terminate
REM Taskkill /PID %PID%
pause
And you can create a Subroutine named : :Create_Process <TargetFile> <PID> in order to call it like this :
#echo off
Title Start chrome process with a defined process ID
set "TargetFile=C:\Program Files\Google\Chrome\Application\chrome.exe"
Call :Create_Process "%TargetFile%" PID
echo The Process is created with PID=%PID%
pause
wmic process where ProcessId="%PID%" Call Terminate
REM Taskkill /PID %PID%
pause
Exit
::-----------------------------------------------------------------
:Create_Process <TargetFile> <PID>
Set "TargetFile=%~1"
Set TargetFile=%TargetFile:\=\\%
#for /f "tokens=2 delims==; " %%# in (
'wmic PROCESS CALL CREATE "%TargetFile%" ^|findstr /I "ProcessId"'
) do set "%2=%%#"
Exit /B
::-----------------------------------------------------------------
I want to launch a particular URL in chrome every day at the same time. How can I achieve this using command line?
There are two ways to do this. The first being from a single command line. You will want to create a new task in Task Scheduler and have it run a command at a desired time. If you wish to use a different browser that supports command lines, be sure to use _ for any spaces in the directory path.
Command line:
SchTasks /Create /SC DAILY /TN "New_Task" /TR "start "C:\Program_Files_(x86)\Google\Chrome\Application\chrome.exe" www.stackoverflow.com" /ST 09:00
The second option is to use a batch file you store somewhere and it will be called to using the SchTasks. Simply create the site1.bat and place it somewhere safe example C:\Windows\My Tasks.
From Batch:
#ECHO OFF
#set Task_Name=Task1
#Set Time=09:00
#set Site=www.stackoverflow.com
schtasks /query /TN "%Task_Name%" >NUL 2>&1
IF %ERRORLEVEL% EQU 0 (goto :EXISTS) ELSE (goto :CREATE)
:CREATE
Set Folder=%~dp0
Set Name=%~nx0
Echo Task does not already exist, creating it now.
SchTasks /Create /SC DAILY /TN "%Task_Name%" /TR "%Folder%%Name%" /ST %Time%
goto :eof
:EXISTS
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %Site%
goto :eof
I have an application that is to be deployed to 1000+ Windows machines. Each machine is in a remote office and is given a Node ID 1-35 and a Branch ID eg. 001122 (unique to each office). I have the install running silently but at one point it asks you to enter the Node ID and Branch ID. I am using the below code in a batch file to allow the engineer running the install to enter the details manually but this is very time consuming and we would prefer to have no user interaction.
We have all the hostnames, IPs, Node ID and Branch ID in one CSV.
My question is, is it possible for the bat file (or another scripting language) to check the IP address or hostname of the pc locate this in the CSV and to parse in the Node ID and Branch ID found in the corresponding rows. How might I go about changing set /p to look at a csv. I am not a coder so am unsure of how to go about reading in a CSV.
Sample of batch file used:
#echo off
setlocal
(set /p NodeId=Enter Node ID:)
(set /p GroupId=Enter Branch ID:)
:: Check that parameter is passed in
if %GroupId%.==. echo WS Group Id required as parameter & GoTo :END
if %NodeId%.==. echo WS Node Id required as parameter & GoTo :END
if %NodeId% GTR 31 echo WS Node Id should be less than 32 & GoTo :END
set GroupId=%GroupId%
set NodeId=%NodeId%
echo Installing Workstation Group=%GroupId% and Node=%NodeId%
Assuming a CSV like the following:
Hostname,IP,NodeID,BranchID
Chef,192.168.0.10,1-35,001122
Secretary,192.168.0.12,1-38,001122
Test,192.168.0.24,1-40,00112
...
this should work:
for /f "tokens=1-4 delims=," %%a in ('type file.csv ^|find /i "%computername%" ') do (
echo Installing Workstation %%a, Group=%%d, Node=%%c with Address %%b
set groupID=%%d
set nodeID=%%c
)
the error is after the
del "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
Here's the source code:
CLS
SET backuptime=%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2%-%TIME:~0,2%-%TIME:~3,2%
echo %backuptime%
echo Running dump ...
set 7zip_path=
"C:\xampp\mysql\bin\mysqldump.exe" --host="localhost" --port="3306" --user="jakedean" --password="jakedean" -Q --result-file="C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql" jakedean
echo Zipping ...
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.zip" "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
echo Deleting the SQL file ...
del "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
timeout /t 5
echo Done!
#pause
and here's a print screen of the cmd prompt after executing...
I've tried everything from changing files names, shortening the directory, changing the non caps but nothing has worked... :/
Your problem is that the %backuptime% variable is generating slashes, you should find a way to remove them, since windows doesn't allow files with a slash in it's name. That's what's bugging your command.
List of unsupported characters:
Check the file name in the directory before you attempt to delete it.
I fixed this by replacing the
SET backuptime=%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2%-%TIME:~0,2%-%TIME:~3,2%
with
SET backuptime=%TIME:~0,2%-%TIME:~3,2%
The date was adding a / which isn't allowed in file names which caused the error. Also the date wasn't setting the correct data, it kept setting 01-02...
The whole .bat file now looks like this
#echo off
CLS
SET backuptime=%TIME:~0,2%-%TIME:~3,2%
echo %backuptime%
echo Running dump ...
set 7zip_path=
"C:\xampp\mysql\bin\mysqldump.exe" --host="localhost" --port="3306" --user="jakedean" --password="jakedean" -Q --result-file="C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql" jakedean
echo Zipping ...
"C:\Program Files\7-Zip\7z.exe" a -tzip "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.zip" "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
echo Deleting the SQL file ...
del "C:\backupforalldbs\tpsdatabase\bk_%backuptime%.sql"
timeout /t 5
echo Done!
As part of a console application, I'd like to hit a URL in Chrome without showing the browser window. Is this possible?
I'm already using /B with the command prompt:
start "" /B "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "google.com"
You need vbscript to hide a window.
Set WshShell = WScript.CreateObject("WScript.Shell")
msgbox FormatNumber(WshShell.Run("cmd /k dir c:\windows\*.*", 0, false))
Something like
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run wscript.Arguments(0), 0, false
in a vbs file. Use
C:\Users\User>"C:\Users\User\Desktop\RunHidden.vbs" "notepad"