Some help with RunAs

Let users run programs with different parameters without making them admins.

Many programs cannot be run properly in any context other than the administrator account or an account with administrator privileges. Because of this, administrators often face this dilemma: Should they give their users admin privileges, in spite of the possible security hazards and headaches this may cause, or should they try to find another program that will work properly outside of the administrator context, a move which could cause...

lost productivity and possibly other problems?

It is possible to run a program from another user's context, but the way Windows 2000 and XP Professional implement this feature requires that the user know the password for the other account. This makes it difficult to run the program securely. If you create a new administrator-level account that has no local login permissions, then the program will not be able to run in the first place and that certainly defeats the purpose!

The solution involves the use of Windows Script Host to create a script that can run the program in the appropriate context and provide the password non-interactively. Here is a sample script:

set WshShell = CreateObject("WScript.Shell")
WshShell.Run "runas /user:Serdar ""e:test.bat"""
WScript.Sleep 100
WshShell.Sendkeys "password~"

In this example, the user is Serdar and the file to run is e:test.bat. (Note the use of double quotes in the WshShell.Run command to pass quotes on to the command interpreter.) The password, of course, is password, and the tilde at the end of the Sendkeys command is a carriage return. These can be customized as needed and the file should be saved with the extension .VBS.

To prevent users from reading the file directly and learning the password, the script can be encoded using Microsoft's Script Encoder tool. Be sure to rename the encoded script with a .VBE extension rather than .VBS. (Note that this will not prevent a very determined user from finding the password, but it will certainly stop someone from casually learning it.) Using permissions to prevent users from reading the file unfortunately also prevents it from being run by the VBScript interpreter.


Serdar Yegulalp is the editor of the Windows 2000 Power Users Newsletter. Check out his Windows 2000 blog for his latest advice and musings on the world of Windows network administrators – please share your thoughts as well!


This was first published in September 2003
This Content Component encountered an error

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchCloudComputing

SearchExchange

SearchSQLServer

SearchWinIT

SearchEnterpriseDesktop

SearchVirtualDesktop

Close