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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run script with elevated rights 1

Status
Not open for further replies.

DanMIS

MIS
Sep 16, 2004
189
US
I have a script to resize event logs on PC's as they log on. However, it errors when the user isn't a local admin.

Here is the script:
**************************************
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Security)}!\\" & _
strComputer & "\root\cimv2")

Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile")

For each objLogfile in colLogFiles
strLogFileName = objLogfile.Name
Set wmiSWbemObject = GetObject _
("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2:" _
& "Win32_NTEventlogFile.Name='" & strLogFileName & "'")
wmiSWbemObject.MaxFileSize = 10000000
wmiSWbemObject.OverwriteOutdated = 7
wmiSWbemObject.Put_
Next
******************************************

Is there any way to pass credentials that will allow this to run? The crucial part for me is the line that resizes the log.

I am running this as a .vbs file called from the login script.

Thank you,
Dan
 
Try to use a startup script instead of a logon script.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It did the trick. Thank you for your direction; I hadn't thought of that.

Dan
 
I just found that the Win2K machines on my network are having problems with this script. They error on the line prior to "Next". The exact error is:

An amended object cannot be put unless WBEM_FLAG_USE_AMENDED_QUALIFIERS is specified

I can think of two solutions, but cannot code either one. The first would be to check for OS and skip it if it's Win2K (this is acceptable for us), or second to run the code differently if it's Win2K.

Any ideas would be appreciated! Thank you.

Dan
 
I can't remember where I stole this code, but it will try to tell you which Windows version you're running:
Code:
	Option Explicit
	Dim oWSH
	Set oWSH=CreateObject("WScript.Shell")
	If OSver()="Windows 2000" Then
		' Do Win2K code
	Else
		' Do non-Win2K code
	End If
	WScript.Quit

Function OSver
	OSver="Unknown"
	Const OSINFO="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
	Dim iVer,iVMajor,iVMinor,sBuild,sCSD,sPlat,sVer
	sVer=CStr(oWSH.RegRead(OSINFO&"CurrentVersion"))
	sBuild=CStr(oWSH.RegRead(OSINFO&"CurrentBuildNumber"))
	sCSD=CStr(oWSH.RegRead(OSINFO&"CSDVersion"))
	iVer=CDbl(sVer)
	iVMajor=Int(iVer)
	iVMinor=Round(10*(iVer-iVMajor),0)
	sPlat=CStr(iVMajor)&"."&CStr(iVMinor)
	Select Case sPlat
	Case "4.0"
		Select Case sBuild
		Case "1381"
			OSver="Windows NT 4.0"
		End Select
	Case "4.1"
		Select Case sBuild
		Case "1998"
			OSver="Windows 98"
		Case "2222"
			OSver="Windows 98 SE"
		End Select
	Case "4.9"
		OSver="Windows ME"
	Case "5.0"
		OSver="Windows 2000"
	Case "5.1"
		OSver="Windows XP"
	Case "5.2"
		OSver="Windows Server 2003"
	Case "6.0"
		OSver="Windows Longhorn"
		Select Case sBuild
		Case "4051"
			OSver=OSver&", Preview 1"
		Case "4074"
			OSver=OSver&", Preview 2"
		End Select
	End Select
	If sCSD<>"" Then OSver=OSver&", "&sCSD
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top