Windows Scripting
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsSystem AdministrationWindows Scripting

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 10th, 2004, 08:18 PM
itsthescottdog itsthescottdog is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 1 itsthescottdog User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old March 31st, 2004, 01:20 AM
Mike_Patton's Avatar
Mike_Patton Mike_Patton is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: NY
Posts: 43 Mike_Patton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 32 sec
Reputation Power: 5
Send a message via AIM to Mike_Patton Send a message via Yahoo to Mike_Patton
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.

Reply With Quote
  #3  
Old January 29th, 2007, 06:21 PM
milind2778 milind2778 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 1 milind2778 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 22 sec
Reputation Power: 0
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:
Originally Posted by Mike_Patton
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

Reply With Quote
Reply

Viewing: ASP Free ForumsSystem AdministrationWindows Scripting > Batch File temporarily utilize administrative privileges


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT