WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

UAC

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determine if Application is Elevated

 Keywords: Elevated Privileges Admin Administrator

Question:

My Winbatch script functions, in part, by talking to a running instance of GoldMine Software via DDE. I recently found out that if GoldMine was launched using the right-click | As Administrator option, my script won't talk to it, unless I also run it As Administrator.

Question: Is there a way for my script to "interrogate" the currently running instance of GoldMine to find out whether it's running with elevated privileges? That way I could at least let the end-user know why it's failing; maybe avoid one more support call.

Answer:

The brute force approach would be to attempt to have the restricted process do something to the elevated process that restricted processes are not normally permitted to do.

The FCL's "System.Diagnostics.Process" class comes to mind as a strait forward way to do this but it does require having a version of WinBatch with CLR support. If you do have a version with CLR support you could simple use the "Process" class to attempt to access the elevated process's "Handle" property. If your script is running as a restricted user and the targeted script is running as a full privileged admin, this will result in an COM/CLR exception error. Trap that error then you can inform the user that that they need elevated admin privileges to proceed.

If you don't have CLR support, you may be able to do something similar with WMI or perhaps there is an even easier test.

A very lightly tested rough example that may work as a starting point.

; COM version
strAppName = "cmd.exe"
objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
colProcesses = objWMIService.ExecQuery( "Select * from Win32_Process Where Name = '%strAppName%'")
ForEach objProcess in colProcesses
    strCommandLine = objProcess.CommandLine
    if  StrLen(strCommandLine) == 0 then Pause(strName, "Is elevated but this script is not")
next

Article ID:   W18311
Filename:   Determine if Application is Elevated.txt
File Created: 2014:03:04:09:41:54
Last Updated: 2014:03:04:09:41:54