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

  • Best-in-Class organizations execute on a strategy that supports the multi-channel nature of customer requests. These leading organizations do not just open up their service infrastructures to accommodate new channels, but also empower their teams to deliver an effective and consistent experience regardless of the channel selected by the customer. This document will highlight the key business capabilities that support a Best-in-Class customer engagement strategy.

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds