Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Elavate Privs in a script

Status
Not open for further replies.

twooly

MIS
Feb 22, 2004
122
US
Does anyone know how I can elevate some parts in a script to run as an admin. IE rebooting a remote machine and connecting to a remote registry. Below are the two things I need to do but need them to run as an admin

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strRemotePC & "\root\default:StdRegProv")

strReboot = strDriveLetter & "\bin\shutdown.exe \\" & strRemotePC & " /R /C"
objShell.Run strReboot,0,True

Thanks
 
if you execute the script below while logged in with Admin priviledges you can remotely reboot a machine.

Code:
'==========================================================================
'
' NAME: RebootWS.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
'
' Creation Date 9/18/2002
' Modification 10/7/2002 Added support for confirmation box
' Usage- Double click and enter a machine name or IP address to reboot machine


On Error Resume Next
mname = InputBox("Enter Machine Name", "Reboot Machine")
If Len(mname) = 0 Then Wscript.Quit

if Msgbox("Are you sure you want to reboot machine " & mname, vbYesNo, "Reboot Machine") = vbYes then

		Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & mname).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
		for each OpSys in OpSysSet
			OpSys.Reboot()
 		next
end if

And this version will let you feed it a list of machines to be rebooted.

Code:
'==========================================================================
'
' NAME: RebootWSfromList.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 7/6/2004
'
' COMMENT: <comment>
'
'==========================================================================

On Error Resume Next

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")
'open the data file
Set oTextStream = oFSO.OpenTextFile("wslist.txt")
'make an array from the data file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close
For Each strComputer In RemotePC
	Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(RemoteShutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
		for each OpSys in OpSysSet
			OpSys.Reboot()
 		next
Next

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
I wish it was that easy. I can't give admin rights to these people. This is part of a migration to XP. I am basicly being asked to do the impossible.

Thanks
 
You could use RUNAS and then script the passing of the password in an encoded script.

Another option would be to use a web page to run the script. Instead of using Iuser_Machinename give the site the admin ID. Your users would never see the password that way and the script code I gave you above would execute as admin.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top