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

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • A modern mobile IT strategy is no longer an option, it is an absolute business necessity. Today's most productive employees are not tied to a desk, an office, or a location. They are mobile. And your company's IT strategy has to be ready to support them with easy, reliable, 24/7 access to the business information they need, from anywhere in the world, across a broad range of communication devices. Here's how some of the nation's most progressive corporations are meeting the many needs of their mobile workers …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds