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!

Scripting user policies

Status
Not open for further replies.

djalexnl

Technical User
Mar 17, 2005
7
NL
Hi scripters around the globe :)
This script shows all computer policies. How can get the policies for the user logged on??

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\computer")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPO")
For Each objItem in colItems
allgpo = allgpo & objItem.Name
Next
wscript.echo allgpo

I Tried the following scripts but the all failed to work.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop\user\USERSID")
Set colItems = objWMIService.ExecQuery("Select * from RSOP_GPO")
For Each objItem in colItems
allgpo = allgpo & objItem.Name
Next
wscript.echo allgpo

Thanx to you all in advance!

Alex

 
does this help?

("Select * from RSOP_UserPrivilegeRight")
 
Thank for your answer but I cannot get this script to work also.
 
Well again i know to get the computer policies, the problem is to get the user policies. All over the internet it is writen change root\rsop\computer to root\rsop\user. Only that does not work.
 
you might like to look at something like this?

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop")
Set objLoggingProvider = objWMIService.Get("RsopLoggingModeProvider")
Set objMethod = objLoggingProvider.Methods_("RsopCreateSession")
Set objInParam = objMethod.inParameters.SpawnInstance_()
Set objOutParam = _
objLoggingProvider.ExecMethod_("RsopCreateSession", objInParam)
 
Thanx for your answer :) but getting error 0x80041021 at several workstations. It should be possible and probably very easy but just know how to script this.
 
Why not just use GPRESULT?

I hope you find this post helpful.

Regards,

Mark
 
i found this on a MS news group. it displays some of the results of GPresult. i think it is on the right lines.
I have also seen loads of posts as you have mentioned about the user\SID stuff and i have tried it myself and gives NULL error for me as well..sorry i cant provide you with a solution at the moment, perhaps the this code is of interest

strComputer = "." ' use "." for local computer


Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")


Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop")
Set objLoggingProvider = objWMIService.Get("RsopLoggingModeProvider")
Set objMethod = objLoggingProvider.Methods_("RsopCreateSession")
Set objInParam = objMethod.inParameters.SpawnInstance_()
Set objOutParam = _
objLoggingProvider.ExecMethod_("RsopCreateSession", objInParam)


' remove the first 3 characters (\\.)
strNamspaceName = Mid(objOutParam.NameSpace, 4)


strQuery = "Select EndTime From RSOP_ExtensionStatus Where ExtensionGUID" _
& " = '{00000000-0000-0000-0000-000000000000}'"


Set objRSOPComputer = GetObject("winmgmts:\\" & strComputer _
& strNamspaceName & "\computer")
Set colItems = objRSOPComputer.ExecQuery(strQuery)
For Each objItem in colItems
dateEndTime = objItem.EndTime
Next


dtmConvertedDate.Value = dateEndTime
WScript.Echo "Last time Group Policy was applied for computer: " _
& dtmConvertedDate.GetVarDate


Set objRSOPUser = GetObject("winmgmts:\\" & strComputer & strNamspaceName _
& "\user")
Set colItems = objRSOPUser.ExecQuery(strQuery)


For Each objItem in colItems
dateEndTime = objItem.EndTime
Next


dtmConvertedDate.Value = dateEndTime
WScript.Echo "Last time Group Policy was applied for user: " _
& dtmConvertedDate.GetVarDate
 
SUPER ;-) GOT IT TO WORK!!!!
maybe it can be done easier but this one does the work!

=======================================================
Code:
strComputer = "."
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime") 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\rsop") 
Set objLoggingProvider = objWMIService.Get("RsopLoggingModeProvider") 
Set objMethod = objLoggingProvider.Methods_("RsopCreateSession") 
Set objInParam = objMethod.inParameters.SpawnInstance_() 
Set objOutParam = _ 
        objLoggingProvider.ExecMethod_("RsopCreateSession", objInParam) 
strNamspaceName = Mid(objOutParam.NameSpace, 4) 
Set objRSOPComputer = GetObject("winmgmts:\\" & strComputer _ 
        & strNamspaceName & "\computer") 
Set colItems = objRSOPComputer.ExecQuery("Select * from RSOP_GPO")
For Each objItem In colItems 
   allgpo = allgpo & objItem.Name & vbCr
Next 
Set objRSOPUser = GetObject("winmgmts:\\" & strComputer & strNamspaceName _ 
        & "\user") 
Set colItems = objRSOPUser.ExecQuery("Select * from RSOP_GPO")
For Each objItem in colItems  
    allgpo = allgpo & objItem.Name & vbCr
Next
WScript.Echo allgpo
========================================================
Thank you very much for all your help...

Greetingzzzzz!!!!!!!!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top