WMI and UAC problem

Get help with using AutoHotkey and its commands and hotkeys
potscrubber
Posts: 13
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

WMI and UAC problem

05 May 2019, 21:57

Hello All

I've been wrestling with a small issue for a while, tinkering and searching for hints hasn't revealed the answer. Maybe someone can educate me directly? :)

I use the following function often to check for the presence of several different processes (and versions).

Code: Select all

CheckProcess()
{
  local Result
  for process in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_Process WHERE Name LIKE 'SAMPLI%' AND ExecutablePath LIKE '%Magix%' OR Name LIKE 'SEQUOI%' AND ExecutablePath LIKE '%Magix%'")
  {      
      Result := true
      return, %Result%
  }
}

In Win 10 x64 (UAC Off), this function will only return true for processes running standard (limited) elevation. This is not the case in Win 7 Pro (UAC Off). In Win 10, to return true for elevated process running as admin, I have to start the script elevated with this handy snippet I found below.

Code: Select all

full_command_line := DllCall("GetCommandLine", "str")  
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
	try
	{
	  if A_IsCompiled
		Run *RunAs "%A_ScriptFullPath%" /restart
	  else
		Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
	}
	ExitApp
}

But I don't really like to run the script as admin, especially for my users. Is there any other solution to detect elevated process with WMI from a standard elevation script? I've also tried using the following but it didn't work, and I don't really understand what the impersonation business means.

Code: Select all

strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")

Any assistance greatly appreciated, thanks!
User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: WMI and UAC problem

07 May 2019, 00:44

try this
https://autohotkey.com/docs/Variables.htm#Args

Code: Select all

if (A_Args[1])
{
    if Not A_IsAdmin AND A_OSVersion <> WIN_XP
    {
        prosses := """" A_ScriptFullPath """ " A_Args[1]
        Run *RunAs %prosses%
        ExitApp
    }
}
:wave: There is always more than one way to solve a problem. ;)
potscrubber
Posts: 13
Joined: 09 Sep 2017, 01:51
Location: Aotearoa
Contact:

Re: WMI and UAC problem

07 May 2019, 06:07

YoucefHam, I appreciate your reply, but this looks like another way to run the script as admin, and no solution to my OP query with regards to WMI only seeing non-elevated processes unless the script itself is elevated?
thanks

Return to “Ask For Help”

Who is online

Users browsing this forum: a1987zz, addala, Aggronaught, elvo11, Google [Bot], keylo, mikeyww and 72 guests