Start Chrome Minimized? - google-chrome

rundll32 shell32.dll,ShellExec_RunDLL "C:\...\shortcut.lnk"
rundll32 shell32.dll,ShellExec_RunDLL "C:\...\shortcut2.lnk"
That's what I've got so far running inside a batch. It starts Chrome just fine, but I want it to start minimized as I only want a page to autorun and then Chrome be closed later automatically. I don't ever want the window to be anything other than minimized.
So far I've tried /min in every location of this command that I could and none have worked. The only position where it does anything is before the directory and it seems to run the Chrome process and then kills it immediately after. Putting --no-startup-window as a parameter in the shortcut also reacts the same way.
I've tried a few other things as well like setting the shortcuts to "minimized" in the window mode, but nothing has worked so far. I could really use some help with this as I'm pretty much stuck. The solution could either be a command for a batch executable or something having to do with the actual shortcut file.
Any help would be greatly appreciated. I'd hate to have to manually minimize these two windows every day.
Here are the two shortcuts and batch file if you want to mess with them.
https://drive.google.com/uc?export=download&id=0B_KZqubEguX6N04xOVZfWVVlQUE

If you just need to run Chrome from a bat file with non full screen mode you can try to use these parameters:
--window-position=0,0 --window-size=1,1

While thinking about a solution within a batch file and coming to the conclusion that there isn't a better solution, than also described above, I've written this quick and dirty piece of code and compiled it in case that you don't have a compiler:
(You will find it also as a snippet on Gist)
Module Module1
Sub Main(ByVal Args() As String)
Try
If Args.Length = 2 Then
Dim fileName As String = Args(1)
If Not String.IsNullOrEmpty(fileName) Then
If System.IO.File.Exists(fileName) Then
Dim startInfo As New ProcessStartInfo(fileName)
Select Case Args(0).ToLower()
Case "hide"
startInfo.WindowStyle = ProcessWindowStyle.Hidden
Case "minimize"
startInfo.WindowStyle = ProcessWindowStyle.Minimized
Case Else
Console.WriteLine(Args(0) & " is unknown. Showing Window.")
startInfo.WindowStyle = ProcessWindowStyle.Normal
End Select
Process.Start(startInfo)
Else
Throw New System.IO.FileNotFoundException("The file specified was not found. (""" & fileName & """)")
End If
Else
Throw New System.ArgumentOutOfRangeException("No file specified.")
End If
Else
Throw New System.Exception("Invalid count of arguments")
End If
Catch ex As Exception 'Optional: Catch ex As System.IO.FileNotFoundException
Console.Error.WriteLine("ERROR" & vbCrLf & ex.Message)
End
End Try
End Sub
End Module
Download the compiled file: RunProcess.exe.
For those who aren't familiar with vb.net or don't want to read this bad formatted thing:
You can use it the following way:
RunProcess minimize "C:\Program Files\[...]\chrome.exe"
RunProcess hide "C:\Program Files\[...]\chrome.exe"
RunProcess show "C:\Program Files\[...]\chrome.exe"
At this point it doesn't check execute paths:
RunProcess minimize "cmd.exe" wont work. You would have to use RunProcess minimize "%systemroot%\System32\cmd.exe"
EDIT:
Also have a look at this: Start-Process -WindowStyle Hidden "chrome.exe" "www.google.com"

If you do not want them to stay open for very long you could do like this
start "C:\Portable Apps\Program Files\Google Chrome\GoogleChromePortable.exe" <somelink1>
start "C:\Portable Apps\Program Files\Google Chrome\GoogleChromePortable.exe" <somelink2>
Taskkill /F /IM GoogleChromePortable.exe
or
Taskkill /F /IM chrome.exe

Related

Creating a batch file that opens google chrome and puts input into the search box?

So I am just playing with batch files and was curious if it was possible to create a batch file that opens the google browser and without typing into the search box, a variable from my batch file gets put into the search box. Anyone know if that's possible? Thanks.
#echo off
cd c:\program files (x86)\google\application
start chrome.exe www.youtube.com
I can open the web browser, I can even change the code to store the variable, but need to know how to send that variable to the search engine. Youtube i just the website i left it at.
If you use google as search engine, try to pass the keyword like this :
#echo off
start "" chrome.exe www.google.com#q=batch
and if you want add more than a keyword just add the sign +
#echo off
start "" chrome.exe www.google.com#q=batch+vbscript+HTA
You could send raw HTTP request as follows:
start "" "c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "https://www.youtube.com/results?search_query=simon's cat"
Below is possible approach how-to make it more readable in a batch script (non-systematic approach, as e.g. site variable joins together protocol and host name). Use appropriate value of engine variable for a particular host (as it could vary for different servers):
#ECHO OFF >NUL
SETLOCAL EnableExtensions EnableDelayedExpansion
set "chromepath=c:\Program Files (x86)\Google\Chrome\Application" path to chrome
set "site=https://www.youtube.com"
set "engine=results?search_query"
set "search=simon's cat" string to search
start "" "!chromepath!\chrome.exe" "!site!/!engine!=!search!"
Delayed expansion used as any variable in above code could contain cmd poisonous characters.
If you want the simplest alternative, you can just copy the full link and paste it in:
#echo off
start chrome "youtube.com/results?search_query=funny+videos"
To open another tab, separate first address with a space and type "google.com" next to it.
If you want to open another browser like FireFox at the same time, type on a new line: start firefox "stackoverflow.com"
It'll look something like this:
#echo off
start chrome "youtube.com/results?search_query=funny+videos" "google.com"
start firefox "stackoverflow.com"
#echo off
set tmp="%*"
IF %tmp% == "" (
GOTO :query
) ELSE (
GOTO :replace
)
:replace
set url=%*
REM set url=%url: =+%
echo %url%
GOTO :search
:query
set /p url=Input search Keywords:
GOTO :search
:search
echo Search query confirmed: %*
echo Attaching to process..
tasklist /nh|findstr "chrome.exe" && start "" "chrome.exe" "? %url%"
REM tasklist /nh|findstr "chrome.exe" && start "" "chrome.exe" "www.google.com/search?q=%url%"
Here is the batch file I use for accomplishing this.
It will attach the search tab to an open process of chrome and search for %* arguments.
If you don't pass arguments, it will ask for some.
> url installing pycharm on ubuntu
There is a commented out method aswell that replaces spaces with '+', then searches with raw HTTP instead of the "? %url%" option.
Delete REM on line 12 and 25, and all of line 24 to switch
#echo off
echo Welcome to my Search Engine!
echo Type 1 Keyword to Search. Use +s instead of spaces
set/p "keyw=Keyword is "
start https://www.google.com/search?q=%keyw%&sourceid=ie7&rls=com.microsoft:en-US:IE-Address&ie=&oe=

Vim function to copy a code function to clipboard

I want to have keyboard shortcut in Vim to copy a whole function from a Powershell file to the Windows clipboard. Here is the command for it:
1) va{Vok"*y - visual mode, select {} block, visual line mode, go to selection top, include header line, yank to Windows clipboard.
But it would work only for functions without an inner {} block. Here is a valid workaround for it:
2) va{a{a{a{a{a{a{Vok"*y - the same as (1), but selecting {} block is done multiple times - would work for code blocks that have 7 inner {} braces.
But the thing is - the (1) command works fine when called from a vim function, but (2) misbehaves and selects wrong code block when called from a vim function:
function! CopyCodeBlockToClipboard ()
let cursor_pos = getpos('.')
execute "normal" 'va{a{a{a{a{a{a{Vok"*y'
call setpos('.', cursor_pos)
endfunction
" Copy code block to clipboard
map <C-q> :call CopyCodeBlockToClipboard()<CR>
What am I doing wrong here in the CopyCodeBlockToClipboard?
The (2) command works as expected when executed directly in vim.
UPDATE:
I've noticed that:
if there are more a{ then the included blocks in the function
then vim wouldn't execute V
Looks like vim handles errors differently here. Extra a{ produces some error and regular command execution just ignores it. But execution from withing a function via :normal fails and wouldn't call V (or probably any command that follows the error).
Any workaround for this?
Try this function
function! CopyCodeBlockToClipboard()
let cursor_pos = getpos('.')
let i = 1
let done = 0
while !done
call setpos('.', cursor_pos)
execute "normal" 'v' . i . 'aBVok"*y'
if mode() =~ "^[vV]"
let done = 1
else
let i = i + 1
endif
endwhile
execute "normal \<ESC>"
call setpos('.', cursor_pos)
endfunction
This preforms a execute command to select blocks until it fails to select a block larger block. ([count]aB selects [count] blocks) It seems when the selection fails we end up in visual mode. So we can use mode() to check this.
When this function exits you should be in normal mode and the cursor should be restored to where you started. And the function will be in the * register.
This macro should come close to what you want to achieve:
?Function<CR> jump to first Function before the cursor position
v enter visual mode
/{<CR> extend it to next {
% extend it to the closing }
"*y yank into the system clipboard

How to get SSIS to wait for a file to exist and/or become available

Scenario:
Package#1 creates a flat file that contains multiple messages (one per line) that is dropped in an external system's "INPUT" folder. The file is picked up by the external system and processed and the responses are written in the same format to a file in the "OUTPUT" folder. The file starts to be written while the external system is still processing messages, so it is written as foo.rsppro. When processing is complete and all response messages are written it is renamed foo.rsp.
I need to pick up that file once it is complete (i.e. after the rename) and process using Package#2, which will start immediatly following Package#1. When Package#2 starts, the external system could be in three states:
Processing the first message not yet complete and no response file written yet, in which case I need to wait for foo.rsppro to be written, then renamed to foo.rsp
Processing in progress and foo.rsppro written, in which case I need
to wait for foo.rsppro to be renamed to foo.rsp
Processing completed, foo.rsppro has been written and been renamed to foo.rsp, in which case I just need to process foo.rsp.
I have tried:
using a file in use task but that errors if the expected file isn't present when the task begins (i.e. errors for scenario 1 and 2)
using a file watcher task but that appears to ignore file renames by design, so will never handle scenario 1 or 2
Aside from building a script task, is there a custom task that will handle all three scenarios?
Edit: SSIS 2008 R2
only a script task can help in your case.
consider using FileSystemWatcher within the script if possible or have an application/windows service which can monitor file system using FileSystemWatcher and invoke your packages when the event is triggered.
humm, it seems that you can solve it by using a for each loop container on the output folder and set it to read only .rsp files. That would deal with your .rsp files.
how can scenario 1 and 2 happens if package 2 will only run after package1 is finish? As I understand, package1 renames the file so it will only end when all the files are processes and renamed
EDIT:
ok, no worry, there is a solution for everything.
How about, you create a variable on package1 called #TotalNumberOfFiles with the total number of files to be processed, then you use package one to call pacakge2 (not sure if you are doing this already, but if not is very simple, just use a execute pacakge task) and on package2 you create a "parent package variable" (this is very simple too in case you have never done it) and package 2 just start processing when there are #TotalNumberOfFiles files on the output folder with the .rsp extension?
EDIT2:
I dont know jf there is a command to get that, maybe google it, but if you dont find out you can add a foreachloop container pointing to the output directory and do something like this on a script task:
Public Sub Main()
Dts.Variables("User::filesCount").Value = Dts.Variables("User::FilesCount").Value + 1
Dts.TaskResult = ScriptResults.Success
End Sub
after it finishes counting, just compare with TotalNumberOfFiles. If equal, move to the next task, else sleep for a while and count again
Final code used as follows. Basically loops through until either the file is found or the max specified number of attempts is hit.
Imports System.Threading is required for Thread.sleep. It may not be the most processor efficient method but this is 100% dedicated hardware and the packages is are running in serial.
'loop until number of required attempts is hit or file is found
Do Until iCounter = iAttempts Or bFileFound = True
'Check if the file exists
If File.Exists(sFilename) Then
'Switch bFileFound to true
bFileFound = True
'Report that file has been found to VERIFY_Input_File_Exists_INT variable
Dts.Variables("VERIFY_Input_File_Exists_INT").Value = True
Dts.Events.FireInformation(1, "DEBUG:", sFilename & " found successfully.", "", 0, False)
Else
'sleep for specified time
Thread.Sleep(iInterval * 1000)
Dts.Events.FireInformation(1, "DEBUG:", sFilename & " not found successfully. Sleeping for " & iInterval & "* 1000", "", 0, False)
End If
'increment counter
iCounter = iCounter + 1
Loop

Ruby Shoes and MySQL: GUI freezes, should I use threads?

I'm trying to learn Shoes and decided to make a simple GUI to run a SQL-script line-by-line.
My problem is that in GUI pressing the button, which executes my function, freezes the GUI for the time it takes the function to execute the script.
With long scripts this might take several minutes.
Someone had a similar problem (http://www.stackoverflow.com/questions/958662/shoes-and-heavy-operation-in-separate-thread) and the suggestion was just to put intensive stuff under a Thread: if I copy the math-code from previously mentioned thread and replace my mysql-code the GUI works without freezing, so that probably hints to a problem with how I'm using the mysql-adapter?
Below is a simplified version of the code:
problem.rb:
# copy the mysql-gem if not in gem-folder already
Shoes.setup do
gem 'mysql'
end
require "mysql"
# the function that does the mysql stuff
def someFunction
con = Mysql::real_connect("myserver", "user", "pass", "db")
scriptFile = File.open("myfile.sql", "r")
script = scriptFile.read
scriptFile.close
result = []
script.each_line do |line|
result << con.query(line)
end
return result
end
# the Shoes app with the Thread
Shoes.app do
stack do
button "Execute someFunction" do
Thread.start do
result = someFunction
para "Done!"
end
end
end
stack do
button "Can't click me when GUI is frozen" do
alert "GUI wasn't frozen?"
end
end
end
I think the problem arises from scheduling which is done by ruby, not by the operating system. Probably just a special case with shoes + mysql.
As a workaround i'd suggest you spawn a separate process for the script and use socket or file based communication between the processes.

How do I create a simple Octave distributable without installing Octave

The Octave documentation on this subject is both intimidating and sparse.
I did not know where else to document the solution I found, so I am posting here. I apologize if that's inappropriate, but I want to help the next guy.
The following solution is for a simple windows distributable.
Use Case:
A solution is developed in Octave 3.2.4, and needs to be distributed to end-users with few computer skills. Installing and explaining Octave is impossible, the solution must be "one-click" or "brain-dead-simple."
Known Issues:
imread fails in 3.2.4 because file_in_path.m is wrong. You will need to update the file file_in_path.m to the following (just replace it):
function name=file_in_path(p,file)
idx=[1 findstr(p,pathsep) length(p)+1];
for i=1:length(idx)-1
if idx(i+1)-idx(i)<=1
dir=strcat(pwd,"/");
else
dir=p(idx(i)+1:idx(i+1)-1);
end
name = fullfile(dir, file);
fid = fopen(name,"r");
if fid >= 0
fclose(fid);
return
end
end
fid = fopen(file,"r");
if fid >= 0,
fclose(fid);
name=file;
return
end
name=[];
Solution: Create a distributable exe using mkoctfile, and package this exe with the core Octave files, and other .oct and .m files as necessary.
Step 1: Create a stand-alone executable.
You can see code that works here:
http://www.gnu.org/software/octave/doc/interpreter/Standalone-Programs.html
Particularly the file "embedded.cc".
I have simplified that file as follows:
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
int
main (int argc, char *argvc[])
{
string_vector argv (2);
argv(0) = "embedded";
argv(1) = "-q";
octave_main (2, argv.c_str_vec(), 1);
octave_value_list in = octave_value (argvc[1]);
octave_value_list out = feval ("your_custom_m_file", in);
if (!error_state && out.length () > 0)
{
}
else
{
std::cout << "invalid\n";
}
return 0;
}
Build this file with the command
mkoctfile --link-stand-alone embedded.cc -o embedded
It may throw warnings, but as long as it throws no errors, you should be fine. The file embedded.exe will be built, and can be run. The only issue is that it will lack all the goodies that make octave awesome. You will have to provide those.
Step 2: Create a distribution folder
You will need to create a copy of many of the Octave files. I suggest a directory specifically for this. At a minimum, you will need a copy of all or most of the DLLs in \bin. Additionally, place your distributable executable in this directory.
Step 3: Other files whack-a-mole
You will now need to find out what other files will be necessary to run your .m script. You can simplify this step by copying \oct\i686-pc-mingw32*.oct and \share\octave\3.2.4\m\*\*.m to the distribution directory, although this will be overkill, and will not actually prevent the whack-a-mole step.
Now, you must play whack-a-mole or the time-honored tradition of "where my includes be at, yo?"
Open a cmd prompt and navigate to your distribution folder.
Get rid of any useful PATH strings. Your customers won't have them.
Attempt to run the program embedded.exe. You will get an error such as the following:
embedded.exe
error: `max' undefined near line 83 column 22
error: evaluating argument list element number 1
error: evaluating argument list element number 1
error: called from:
error: T:\sms\Development\research\c2\disttest\strcat.m at line 83, column 3
error: T:\sms\Development\research\c2\disttest\file_in_path.m at line 5, column 10
error: T:\sms\Development\research\c2\disttest\imread.m at line 50, column 6
A Search in your Octave installation for "max". It will either be a .oct or a .m file. In this case, it is a .oct file, max.oct. Copy it to your distribution directory.
B You search for something obvious like "min", and get no results. This is because the Loadable Function "min" is in the .oct file "max.oct". Make a copy of max.oct, and rename it to min.oct. It will work now. How do you know where the functions are? I'm not sure. Most of them are in obvious places like "max.oct" for min, and "fft2.oct" for "ifft2.oct". Good luck with all that.
Repeat until your executable runs.
Just to add that if you want to run a script instead of an m function, then the line of the embedded.cc:
octave_value_list out = feval ("your_custom_m_file", in);
should be:
octave_value_list out = feval ("your_custom_m_script");
Also use 'which' to find where the missing functions are packed. For example for the min function:
octave:22> which min
min is a function from the file C:\Octave\Octave3.6.2_gcc4.6.2\lib\octave\3.6.2\oct\i686-pc-mingw32\max.oct
Something I found when linking my custom m file into an Octave standalone:
Needed #include <octave/toplev.h>
Replace return 0; (as above) with clean_up_and_exit(0);
Without these steps my program repeatedly crashed on exit.
Run mkoctfile --link-stand-alone embedded.cc -o embedded
from the octave solution and not from a batch file.
Just saved you half day (-;
In the above solution in bullet 4 B:
B You search for something obvious like "min", and get no results.
This is because the Loadable Function "min" is in the .oct file
"max.oct". Make a copy of max.oct, and rename it to min.oct. It will
work now.
This might not work if some function is being called from #folder function.m and also to avoid unnecessary duplicated files, just add the following code somewhere in your m file outside #folder
autoload ("min", "max.oct");
Likewise, it can be removed via
autoload ("min", "max.oct", "remove");
Ensure that the path to max.oct is provided here.
The above understanding is based on a file PKG_ADD and PKG_DEL in the communications package located at \Octave-4.0.1\lib\octave\packages\communications-1.2.1\i686-w64-mingw32-api-v50+\
Check out Stratego Octave Compiler.
(I've not tested it yet, but plan to do so in the next few days.)
I had that very same requirement (one-click, brain-dead-simple), so I made a setup that contained only curl.exe, the batch file below, an exe which was a .bat in disguise (simply calling the batch file below) and the .vbs script below (not writen by me). And of course my m-file.
This will download Octave 4.2.1 as a portable program (32 bit, otherwise we'dd have to download again if the system turns out to be 32 bit), unpack using the vbs script, move the contents to the same folder as the batch file and run it in GUI mode. Every next time the same script is called, it will only check if octave.bat is still there.
Of course this results in a huge waste of disk space, downloading the 280MB zip, which unpacks to over 1GB (which I make even worse by not deleting the zip afterwards), and you're stuck with a cmd window that is not easy to hide.
But it does offer the simplest solution I could find. It is also less likely to break in the future (either with an update of your own, or an update from Octave). Some glorious day, mkoktfile will actually be easy to use and will solve dependencies on its own, but until that day this remains the least headache-inducing solution I could find. And aspirins are more expensive than someone else's disk space.
::this file will test if the octave portable is downloaded and unpacked
#ECHO OFF
SET my_m_file=your_mfile.m
SET name_of_this_script=run_me.bat
::if the file exists, skip to the actual running.
IF EXIST "octave.bat" goto OctaveIsExtracted
IF EXIST "octave-4.2.1-w32.zip" goto OctaveIsDownloaded
ECHO The runtime (Octave portable 4.2.1) will now be downloaded.
ECHO This may take a long time, as it is about 280MB.
ECHO .
ECHO If this download restarts multiple times, you can manually download the octave-4.2.1-w32.zip from the GNU website. Make sure to unpack the contents.
::if this errors, you can uncomment the line with archive.org (which doesn't report total size during download)
curl http://ftp.gnu.org/gnu/octave/windows/octave-4.2.1-w32.zip > octave-4.2.1-w32.zip
::curl http://web.archive.org/web/20170827205614/https://ftp.gnu.org/gnu/octave/windows/octave-4.2.1-w32.zip > octave-4.2.1-w32.zip
:OctaveIsDownloaded
::check to see if the file size is the correct size to assume a successful download
::if the file size is incorrect, delete the file, restart this script to attempt a new download
::file size should be 293570269 bytes
call :filesize octave-4.2.1-w32.zip
IF /I "%size%" GEQ "293560000" goto OctaveIsDownloadedSuccessfully
del octave-4.2.1-w32.zip
::start new instance and exit and release this one
start %name_of_this_script%
exit
:OctaveIsDownloadedSuccessfully
IF EXIST "octave.bat" goto OctaveIsExtracted
::unzip and move those contents to the current folder
ECHO Unzipping octave portable, this may take a moment.
cscript //B j_unzip.vbs octave-4.2.1-w32.zip
SET src_folder=octave-4.2.1
SET tar_folder=%cd%
for /f %%a IN ('dir "%src_folder%" /b') do move %src_folder%\%%a %tar_folder%
pause
:OctaveIsExtracted
octave.bat %my_m_file%
goto :eof
:filesize
set size=%~z1
exit /b 0
And j_unzip.vbs
' j_unzip.vbs
'
' UnZip a file script
'
' By Justin Godden 2010
'
' It's a mess, I know!!!
'
' Dim ArgObj, var1, var2
Set ArgObj = WScript.Arguments
If (Wscript.Arguments.Count > 0) Then
var1 = ArgObj(0)
Else
var1 = ""
End if
If var1 = "" then
strFileZIP = "example.zip"
Else
strFileZIP = var1
End if
'The location of the zip file.
REM Set WshShell = CreateObject("Wscript.Shell")
REM CurDir = WshShell.ExpandEnvironmentStrings("%%cd%%")
Dim sCurPath
sCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
strZipFile = sCurPath & "\" & strFileZIP
'The folder the contents should be extracted to.
outFolder = sCurPath
'original line: outFolder = sCurPath & "\"
WScript.Echo ( "Extracting file " & strFileZIP)
Set objShell = CreateObject( "Shell.Application" )
Set objSource = objShell.NameSpace(strZipFile).Items()
Set objTarget = objShell.NameSpace(outFolder)
intOptions = 256
objTarget.CopyHere objSource, intOptions
WScript.Echo ( "Extracted." )