Special runas Utility for Windows NT and Windows 2000

Environment: Visual C++, Windows NT, and Windows 2000

The runasv program offers execution commands for every user running Windows NT and Windows 2000.

This program allows the execution of every command with the user specified. The runserv.exe program runs as a service (with localsystem user) and listens by using Windows sockets (port 8000) as a server application. When it receives some information through this port, it works with this information, formatting it, and it obtains the command to execute the user and password, and the execution mode. Then, it uses the LogonUser API function to change the user to the user specified and execute the command. When this command finishes, it sends the reply to the client application. The runasv.exe program runs as a client application by using Windows sockets and sends the request through port 8000. It formats the input parameters, builds a message, and sends this message to the server application (runserv.exe) that runs as a system service. Then, it waits for the reply.

It is similar to the runas utility for Windows 2000, but adds two important functions:

  • It enables you to incorporate passwords as input parameters. In this case, it doesn't ask for a password. You can use this utility in batch processes without stoping the process.
  • You can execute commands in remote machines by specifying the machine name or IP address as an input parameter.

There is no utility similar to runas in Windows NT; these programs can be useful with this operating system.

To use these programs:

runserv <Option>

where <Option>:

  • -c: Creates service runserv.
  • -b: Deletes service runserv.
runasv <Command> [-h] <Machine> <User> <Password>


  • <Command>: command to execute.
  • [-h]: specify hide execution (optional).
  • <Machine>: name or IP address of execution machine (if you don't specify this parameter, the execution will be local).
  • <User>: user for executing (you can specify the domain, too).
  • <Password>: user's password.

If you don't specify a user and password, the application will ask for them. Example:

runasv "net stop PrManager" \DomainTest\administrator vvvpass

These programs can be interesting for two reasons:

  • Its practical use is for doing several tasks as administrator with users without privileges (you don't need to logoff and a issue a new logon with an administrator user), especially with Windows NT.
  • It is a complete example of Windows sockets, services, and processes management.

These programs were compiled and linked with Microsoft Visual C++ 6.0.


Download demo project - 48 Kb


  • Problem

    Posted by JKEATS on 04/27/2004 07:36am

    I imagine that for runasv to run, runserv must first be running. With the following script:
    %0\..\runserv -c
    %0\..\runasv "regedit /S OutlookXP\OutlookImmerAntwortSenden.reg" \kurz_fuerth\Service password
    ECHO "Outlook XP Lesebestaetigung mit Immer eine Antwort senden gesetzt"
    %0\..\runserv -b
    ... I got back an error: error 1073 in CreateService().
    What have I done wrong? (daniel.mccullough@kurz.de)

    • The parameter is incorrect. (Machine DVDVD).

      Posted by deeznuts on 06/11/2004 08:36pm

      cant understand what i'm doing wrong ? i have runserv.exe running ... with the -c flag... but it doesnt take my machinename parameter.. any idea whats wrong ? santiso33@hotmail.com thanks alot

  • Great utility

    Posted by stubwang on 02/27/2004 05:41pm

    I search through Internet and try several runas like tools. This is only one I can use to avoid the annoying Windows NT user privilege problem. But there is a bug in the code.
    1) function service_main in runserv.c
    // I comments out _strupr(szComando) because sometime, the command line parameters is case-sensitive
    2) function LaunchApp in runserv.c
    In the last few lines of the function, I modify the return pi.hProcess to following code, because I like the tools can tell me whether the application failed or not.
    		if (exitCode == 0)
    			return pi.hProcess;
    			return (HANDLE)NULL;
    	} // if(!bOk)

  • Good one.

    Posted by Legacy on 05/09/2003 12:00am

    Originally posted by: harinath

    Though simple concept only, your application looks good.
    It helped in using CreateProcessAsUser().


  • If you add use-profile support and loh-on type choice...

    Posted by Legacy on 05/08/2003 12:00am

    Originally posted by: Zhefu Zhang

    refer Keith Brown's article here:

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Anthony Christie, the Chief Marketing Officer for Level Communications, is responsible for customer experience, worldwide marketing and product management. In this informative asset, he shares his insights into why a private network connection to cloud-bases applications is the right decision for your enterprise. Download now to find out more.

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date