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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds