|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Batch File temporarily utilize administrative privileges
I need to install a program as a system service on several computers on a network. But I don't want to log onto each and every computer individually to get access the system services manager. I want the regular user to install the program using a batch file that I created and shared on the network. How do I temporarily utilize my administrative access to install the program as a system service while someone is logged on under a regular user account?
|
|
#2
|
||||
|
||||
|
Using a batch file you can only use the runas feature
but with that it still will promt you for a password.... Here is a vbs script that will launch the bat file with credentials you supply.. But this is in clear text which is risky...... A user with access to the file can see the credentials.. Copy and Paste the below text into a text file and rename it with a .vbs extension Code:
On Error Resume Next dim WshShell,oArgs,FSO ' ---------------------------- ' configuration variables ' ---------------------------- ' sUser = username ' sPass = password ' sCmd = path to the program ' ---------------------------- sUser="domain\username" sPass="password" sCmd="\\your_server\your_files\your.bat" ' ---------------------------- ' don't touch below ' ---------------------------- set oArgs=wscript.Arguments set WshShell = CreateObject("WScript.Shell") set WshEnv = WshShell.Environment("Process") WinPath = WshEnv("SystemRoot")&"\System32\runas.exe" set FSO = CreateObject("Scripting.FileSystemObject") if FSO.FileExists(winpath) then 'wscript.echo winpath & " " & "verified" else wscript.echo "!! ERROR !!" & VBCRLF & "Can't find or verify " & winpath &"." & VBCRLF & "You must be running Windows 2000 for this script to work." set WshShell=Nothing set WshEnv=Nothing set oArgs=Nothing set FSO=Nothing wscript.quit end if rc = WshShell.Run("runas /user:" & sUser & " " & CHR(34) & sCmd & CHR(34), 2, FALSE) 'wscript.Sleep 1 'need to give time for window to open. WshShell.AppActivate(WinPath) 'make sure we grab the right window to send password to WshShell.SendKeys sPass & "{ENTER}" 'send the password to the waiting window. 'set WshShell=Nothing 'set oArgs=Nothing 'set WshEnv=Nothing 'set FSO=Nothing 'wscript.quit '************************ '* Usage Subroutine * '************************ Sub Usage() On Error Resume Next msg="Usage: cscript|wscript vbrunas.vbs Username Password Command" & VBCRLF & VBCRLF & "You should use the full path where necessary and put long file names or commands" & VBCRLF & "with parameters in quotes" & VBCRLF & VBCRLF &"For example:" & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog e:\scripts\admin.vbs" & VBCRLF & VBCRLF &" cscript vbrunas.vbs quilogy\jhicks luckydog " & CHR(34) &"e:\program files\scripts\admin.vbs 1stParameter 2ndParameter" & CHR(34)& VBCRLF & VBCRLF & VBCLRF & "cscript vbrunas.vbs /?|-? will display this message." wscript.echo msg wscript.quit end sub 'End of Script I wouldn't reccommend the above script... What I would do is........ launch the batch file thru AD's Group Policy and make sure the users have access to any areas the bat files needs.. Rob Last edited by Mike_Patton : March 31st, 2004 at 10:13 AM. |
|
#3
|
|||
|
|||
|
Hi Mike,
Thank you for your script, it works very well on windows 2000. However on windows xp it will still prompt for a password, and if you close the password prompt window it somehow still goes ahead with the batch file... Any idea how I could make it work on windows xp? Thanks in advance Milind Quote:
|
![]() |
| Viewing: ASP Free Forums > System Administration > Windows Scripting > Batch File temporarily utilize administrative privileges |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|