How can this procedure be done with ahk script
If I press Ctrl+Q
It opens chrome.
Selects Mayank Profile, enter image description here, opens www.google.com and www.yahoo.com in it.
As of now Mayank chrome is running, then Selects Julia profile and opens www.gmail.com and www.yahoomail.com.
As of now Now Three chrome will be opening right, One the chrome that is launched firstly, Mayank secondly, Julia the third. As I have to work with these two chromes(2nd and 3rd)
It closes the first chrome.
and I end up having only two chromes opened and julia is activated which contains www.gmail.com and www.yahoomail.com as shown in the picture.
enter image description here
Note: All this happens if I press Ctrl+Q
You can set a flag for chrome.exe when you launch it, so that it starts in a specific profile. An example of the command is this:
chrome.exe --profile-directory="Default" https://stackoverflow.com
The above code will launch this site, while using the profile-directory "Default" which is the default profile for Chrome. You can substitute "Default" with any other profile-directory. However, the name for the directory is not the same as the one set in the profile inside of the browser. All manually created profile-directories are named Profile # where # is a digit increasing from 1 for each created profile.
For example, I have created the following two profiles:
The default path for the Profiles is:
C:\Users\<user>\AppData\Local\Google\Chrome\User Data\
Looking in the folder I can find two folders named:
Profile 1\
Profile 2\
To make it easier to determine what user corresponds with which folder, you can open the file Preferences inside of each of those folders. Inside of that JSON-File, you can search for the key "name": which will contain the name you've set inside of the GUI.
After you've determined what folders are for the profile you want, then we can create the hotkey we're after:
^q::
Run, chrome.exe --profile-directory="Default" https://stackoverflow.com/
Run, chrome.exe --profile-directory="Profile 1" https://superuser.com/
Run, chrome.exe --profile-directory="Profile 2" https://www.google.com/ https://www.duckduckgo.com/
Related
I'll take a batch or powershell solution, but I need to launch Edge to a specific url in kiosk mode and not having much luck. The following sees the kiosk parameter as part of the url string. This method of launching the app doesn't appear to accept parameters
start "" "shell:AppsFolder\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge" --Kiosk http://website.com
In powershell but it keeps telling me the application was not found, enter a valid appname or AUMID. But that is the correct aumid and its recognized by the batch file.
set-assignedAccess -UserName "kiosk" -AppName "Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge --kiosk http://website.com"
Though similar this is not a duplicate of How to set up Microsoft Edge Chromium in kiosk mode with silent printing?
They reference edge from program files and mine is not located there. Above has been the only way I've been able to reference it successfully from batch.
I want to be able to press . in any folder that I'm in File Explorer and open Visual Studio Code on that folder. It is the same effect as right-clicking and clicking "Open with Code". Pressing . is just like I could do on the GitHub website.
It might not be officially possible, but are there any workarounds to make it work?
The biggest issue is getting the current location from windows explorer. This requires some reverse engineering to get the memory address where windows explorer stores the location. If for any reason this address changes, you will need to find it again.
Besides that, windows supports global keyboard hooks. So you'd like to set up a global keyboard hook for your . key. The windows API also provides methods to get the active window. So whenever the . key is pressed, you can check that the active window is an explorer window. Then you'd read the current folder from the explorer window's memory. After that you've got everyting you need to start visual studio code.
This is very hacky, but I guess it's the only choice you have. Topics to research are:
Keyloggers - These for instance use the global hooks I mentioned
Generic reverse engineering - To find the address of the current location in windows explorer
Edit: Autohotkey post about how to get the windows explorer location. If that works as people claim, autohotkey can also be used to register a hook for the . key and launch VS code.
Thank you #AdrAs and #SarvinR for the answers. I used Sarvin's solution for a while, while trying to google and make sense of Adr's solution. Sarvin's solution is very useful if you're not trying to download any external programs, but if you want the true solution to this question, I finally managed it here:
Download AutoHotKey. It's good if you're familiar with it. AHK basically creates hotkeys (or shortcuts) like Adr described.
(If you have an existing ahk that you use, you can skip these steps and copy the code block down below)
Create a new AutoHotKey script by right-clicking on your desktop or anywhere in file explorer (we're gonna move it later so it doesn't matter). Name it whatever you want. I'm going to call it MyScript.ahk for this answer (I actually used david.ahk for myself).
Now, open command prompt (win + r, cmd, enter) and look for where VSCode is by typing where code. It will probably give you two lines. Take note of one of the lines (I chose the top one).
Right-click the ahk script file that you just created and choose Edit Script (or you can open it with notepad++ or VSCode or any editor of your choice, it's just a normal text file). Delete everything and paste this in:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
GetActiveExplorerPath()
{
explorerHwnd := WinActive("ahk_class CabinetWClass")
if (explorerHwnd)
{
for window in ComObjCreate("Shell.Application").Windows
{
if (window.hwnd==explorerHwnd)
{
return window.Document.Folder.Self.Path
}
}
}
}
#IfWinActive ahk_exe Explorer.exe
.::
path := GetActiveExplorerPath()
run, "C:\Users\david\AppData\Local\Programs\Microsoft VS Code\bin\code" "%path%"
return
On the second last line, replace the VSCode location with what you just saw in cmd. You most likely have to just change the username from david to your name.
Now, save the file try opening it (double click the ahk). If it works, a green H icon should appear on your tray without any errors. Go into any file directory in Windows File Explorer and hit . like you would normally do in GitHub. (Do Not do this in large directories like your root C:. There will be too many files for VSCode to load). It should work like expected, and if it doesn't, you did something wrong (I did the exact same thing like I just described and it works).
Now, of course, you would want to run this script on startup. Copy/Move the .ahk file into C:\Windows\System32. It will ask you for administrator permissions, so click yes. Open the registry editor (win + r, regedit, enter). Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. On the right side pane, right click on the empty space then create a new String Value with any name (I used davidAHK) and set its value to your ahk file that you just copied/moved with quotes ("C:\Windows\System32\david.ahk" for my case). Close the Registry Editor and safely restart your computer. The ahk script should run on start up and you should be able to click . in any directory in file explorer to open VSCode.
Again, thank you #AdrAs and #SarvinR for your help!
I have an trick for this
Create vs.bat and write this code in that
#echo off
code %cd%
And Move this file to C:/Windows/System32/
Now All Set.
If you type vs on the address bar of explorer your vs code with current folder will open
open VSCode -> command+shift+p -> Enter shell command – > click the prompt "shell command: install 'code' command in path"
open directory -> code .
I wanted launch VS Code with the open folder OR the selected files, using AHK v2, and I wanted it to be plug & play for other users. Here's the result:
#Requires AutoHotkey v2.0
; This is the key combo.
#!.::
{
; Is the current window an Explorer window?
if (WinGetClass("A") == "CabinetWClass") {
; Cache the current clipboard contents.
clipboard := A_Clipboard
; Clear the clipboard & copy selected files.
A_Clipboard := ""
Send "^c"
ClipWait(0.5)
; If no files are selected...
if (A_Clipboard == "") {
; Get the current window's ID.
hwnd := WinGetID("A")
; Find the current window's COM object.
for window in ComObject("Shell.Application").Windows{
if (window && window.hwnd && window.hwnd == hwnd)
; Get the current folder's path.
path := window.Document.Folder.Self.Path
}
}
else {
; Quote & space-concatenate selected files.
path := '"' . StrReplace(A_Clipboard, "`n", '" "') . '"'
}
; Restore the clipboard.
A_Clipboard := clipboard
; Run code.
exe := '"' . StrReplace(A_AppData, "Roaming", "Local\Programs\Microsoft VS Code\code") . '"'
Run(exe . " " . path)
}
}
Works like a charm, and it's a piece of cake to install & run on your machine! Instructions at the repo.
This is how I can successfully open only the VS-Code app:
^!h::If !FileExist(code := StrReplace(A_AppData, "Roaming", "Local\Programs\Microsoft VS Code\Code.exe"))
MsgBox, 48, Error, File not found.\n`n%code%`
Run, %code%
return
However, here is my issue:
I use Stardock Groupy on my computer. Groupy groups any open window on your computer into tabs; an Explorer window, application, etc. You can group specific folders and files and save them as a custom group, which Groupy will save as a ".groupy" file. The file runs by selecting it within the Groupy "Saved Groups" dropdown, or you can double-click the ".groupy" file.
I have a custom ".groupy" file that opens (and groups into tabs) an Excel file and a text file that runs via VS-code. When I open my group, two things open successfully and get grouped into tabs: Excel and VS-Code.
Three ways successfully open both Excel and VS-Code into a tabbed group:
Within Groupy's dropdown
Double-clicking the ".groupy" file
Running the following command in cmd:
%AppData%\Groupy\CROSS_EXCEL_VS.groupy
I want to run this ".groupy" file via AHK, but when I do, the file runs, but only the Excel file opens. No matter how I try to run the .groupy file via AHK, VS-Code doesn't run at all.
Here are the various ways I've tried:
001:
run, %A_AppData%\Groupy\CROSS_EXCEL_VS.groupy
002:
If !FileExist(groupy := A_AppData "\Groupy\CROSS_EXCEL_VS.groupy")
MsgBox, 48, Error, File not found.\n`n%groupy%`
Run, %groupy%
003:
Run "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
004:
Run, C:\Program Files (x86)\Stardock\Groupy\Groupy32.exe
, "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
005:
run cmd /k "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
006:
commands="C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy"
runwait, %comspec% /c %commands%
007:
run C:\Windows\System32\cmd.exe /C "C:\Users\ztwer\AppData\Roaming\Groupy\CROSS_EXCEL_VS.groupy",,hide
What can the problem be?
Found a way. I set C:\Program Files\AutoHotkey\AutoHotkey.exe compatibility setting to "Run this program as an administrator" and all works fine.
I want to add user-data-dir argument to google chrome whenever its launched.
I made following changes for it:
Changed registry key HKCR:\ChromeHTML\shell\open\command to "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir=C:\Users\user\testdir --single-argument %1'
Set Argument --user-data-dir=C:\Users\user\testdir --single-argument %1 to shortcut file C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Google Chrome.lnk
However, I see that chrome is running without the new user-data-dir. I don't know using which shortcut chrome was opened.
How can I make this change permanent (preferably using powershell) so that whichever shortcut chrome is opened, it takes the user-data-dir argument?
I am not able to find how to make it permanent but able to get the arguments applied by a workaround. Search for all the shortcuts by following command.
Get-CimInstance Win32_ShortcutFile | select Name, FileName, CreationDate, LastAccessed, Drive, Path, FileType
Set arguments in the intended shortcuts as given in the second step in the question.
Have any idea using powershell how to enable and disable "Alloww active content to run in files on my computer" in IE properties..
This worked for me !
When the HTML page is loaded from local machine (local file path), the ActiveX control can be blocked by the Local Machine Lockdown feature. You should be able to workaround it by adding a mark-of-web
(<!-- saved from url=(0014)about:internet -->) at the beginning of your HTML page.
You can achieve the same from registry Key. First create the registry key iexplore.exe (Dword)
in the path HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN
If you set the value to 1 the 'Allow active content to run in files on my computer' will be unchecked.
If you set the value to 0 the 'Allow active content to run in files on my computer' will be checked.