jakehimton
jakehimton

Reputation: 101

Require program to run as admin

How can I check if my program is running as an administrator on a Windows 7 system, using C?

In batch I could do something along the lines of:

whoami /groups | findstr /b /c:"Mandatory Label\High Mandatory Level" | findstr /c:"Enabled group" > nul: && set IS_ELEVATED=1
    if %IS_ELEVATED%==0 (
        set /p _="You need to run Utilis as administrator, run with admin cmd. Press enter to exit..
    )

This will check if the current user is an administrator or not. How can I achieve the same concept in C?

Upvotes: 0

Views: 87

Answers (1)

Weather Vane
Weather Vane

Reputation: 34585

I suggest that if you set the executable's properties and permissions, so that it can only be run by administrator, that could solve the problem.

Upvotes: 1

Related Questions