From 08daf6e5443ac21daf9bf026cd2e29cba044fbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 18 Jan 2021 16:54:33 +0100 Subject: programs.explorer: Open cmd as user with new RunAsUser function I usually run the script as administrator, but this creates friction when logged into Windows as a non-administrator. For example, mounted SMB shares are not available in the administrator's cmd window. --- tt.programs.explorer.ahk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tt.programs.explorer.ahk') diff --git a/tt.programs.explorer.ahk b/tt.programs.explorer.ahk index 3bebd6d..dead96c 100644 --- a/tt.programs.explorer.ahk +++ b/tt.programs.explorer.ahk @@ -32,6 +32,12 @@ ExplorerPath() return Explorer().Document.Folder.Self.path } +RunAsUser(cmd*) +{ + global ShellApp + return ShellApp.Windows.FindWindowSW(0, 0, 8, 0, 1).Document.Application.ShellExecute(cmd*) +} + ;; -> body ;; Explorer/Desktop hotkeys --------------------------------------------------- @@ -45,7 +51,7 @@ ExplorerPath() ; Open new window/command prompt ^n::Run, % "explorer /n,""" ExplorerPath() """" -^p::Run, % "cmd /k cd /d """ ExplorerPath() """" +^p::RunAsUser("cmd", "/k cd /d """ ExplorerPath() """") +^p:: path := ExplorerPath() -- cgit v1.2.3