Click here to Skip to main content
12,999,628 members (53,621 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 28 Jul 2014

Elevated Privileges through command line in windows

Rate this:
Please Sign up or sign in to vote.
The article is about launching elevated processes through command line


The present article deals with running windows processes using elevated prevliiges.There are also many other techniques for doing the above task like;-
1)  The first technique is creating a manifest file and then adding the following  given code.


which is explained in there:

2) Another technique is impersonating a User in your program.
which is explained  in there;;en-us;Q306158

The technique which now I am going to explain is a little bit different from  the conventional methodology.A tool created by Mr J.Robbins had made it very easy to perform elevated task with  CMD.The details of tools are given in the link below:
You need to put the elevate.exe in the follwing location to make it work

Sample usage is demonstrated below
1) Without Elevate Program

2) With Elevate Program

3) And finally the result


I was working on a project in which I have to remotely mange windows firewall through an IOS device. I made a WCF webservice in which windows netshell commands are executed on my server.I donot know why impersonation and websevice manifest techniques  did not work when I executed a task therefore I adopted this technique to achive the desired results .Some of the snapshots of IOS client are given below who uses the webservice .

Using the code

The code of the wcf webservice is in c#, for ease I made small function to be executed on the server.Some of the the function which are related for executeing elevated processes are given below.

//A function which execute commands on cmd and return string output of cmd 
//the code is from msdn resources with some minor modifications      
public string  console(string command )
            string result = "";
            string output = string.Empty;
            string error = string.Empty;

            ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/c "+command);
            processStartInfo.RedirectStandardOutput = true;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.WindowStyle = ProcessWindowStyle.Normal;
            processStartInfo.UseShellExecute = false;

            Process process = Process.Start(processStartInfo);
            using (StreamReader streamReader = process.StandardOutput)
                output = streamReader.ReadToEnd();

            using (StreamReader streamReader = process.StandardError)
                error = streamReader.ReadToEnd();
            result = output;

            if (!string.IsNullOrEmpty(error))
                result = error;
            return result;
        }<span style="font-size: 9pt;">       </span>
//An example function of blocking an ip adress using commad line with elevated privileges
void blockweb(string ipadres)
string info = console("elevate netsh advfirewall firewall add rule name=\"" + System.DateTime.Today.Millisecond + "\" protocol=TCP localport=80 action=block dir=IN remoteip=" + ipadres);

//An example function which execute netstat -an command and return a json object 
string netinfo()
    string info = console("netstat -an");
    return info; 
//A sample return output is given below


Points of Interest

Server end management tool for firwall is also built which i will explin in my next article


First vesion.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Muhammad Muddasar Yamin
Software Developer
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

BugImages, images... Show me the images! Pin
Carlos190729-Jul-14 0:22
memberCarlos190729-Jul-14 0:22 
GeneralRe: Images, images... Show me the images! Pin
Muhammad Muddasar Yamin29-Jul-14 2:06
memberMuhammad Muddasar Yamin29-Jul-14 2:06 
BugRe: Images, images... Show me the images! Pin
Carlos190729-Jul-14 3:14
memberCarlos190729-Jul-14 3:14 
GeneralRe: Images, images... Show me the images! Pin
Muhammad Muddasar Yamin29-Jul-14 4:45
memberMuhammad Muddasar Yamin29-Jul-14 4:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170624.1 | Last Updated 29 Jul 2014
Article Copyright 2014 by Muhammad Muddasar Yamin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid