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>

where:

  • <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.

Downloads

Download demo project - 48 Kb


Comments

  • 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

      Reply
    Reply
  • 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
    //_strupr(szComando);
    _strupr(szPath);
    _strupr(szModo);
    _strupr(szDominio);
    _strupr(szUsuario);
    
    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;
    		else
    			return (HANDLE)NULL;
    	} // if(!bOk)

    Reply
  • 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().

    cheers
    harinath

    Reply
  • 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:
    http://www.microsoft.com/msj/0200/logon/logon.aspx

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

Top White Papers and Webcasts

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming eSeminar to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds