473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Collecting RSOP data in C#

Hi,

I'm trying to find out how to collect RSOP data in C#, but I haven't
been successfull yet.

Below is the code I Use in vbscript:

------------------------------------------------------------------------------------------------------------------------------
Const FL_FORCE_CREATE_NAMESPACE = 4

strComputer = "."

Set locator = CreateObject("WbemScripting.SWbemLocator")

Set connection = locator.ConnectServer _
(strComputer, "root\rsop", null, null, null, null, 0, null)

Set provider = connection.Get("RsopLoggingModeProvider")

provider.RsopCreateSession _
FL_FORCE_CREATE_NAMESPACE, Null, namespaceLocation, hResult, eInfo

Set rsopProv = locator.ConnectServer _
(strComputer, namespaceLocation & "\User", null, null, Null, Null, 0 ,
Null)

Set colItems = rsopProv.ExecQuery("Select * from RSOP_GPO")

For Each objItem in colItems
WScript.Echo objItem.Name
Next

provider.RsopDeleteSession namespaceLocation, hResult
------------------------------------------------------------------------------------------------------------------------------

Are there any examples on how to do this in C#?

Thanks,

Mario
The Netherlands

Apr 17 '07 #1
2 5461
Why not just set a reference to the WbemScripting.SWbemLocator COM
component in VS.NET and then run the same code?

You still have to have the COM component installed on whatever machine
you go to, as well as the interop wrapper that is created.

On top of that, you will probably have to pass DBNull for the "null"
values that you are using in VBScript now (Null was analagous to a database
null, while null in C# is analagous to "Nothing" in VB).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<mc*********@interpolis.nlwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
Hi,

I'm trying to find out how to collect RSOP data in C#, but I haven't
been successfull yet.

Below is the code I Use in vbscript:

------------------------------------------------------------------------------------------------------------------------------
Const FL_FORCE_CREATE_NAMESPACE = 4

strComputer = "."

Set locator = CreateObject("WbemScripting.SWbemLocator")

Set connection = locator.ConnectServer _
(strComputer, "root\rsop", null, null, null, null, 0, null)

Set provider = connection.Get("RsopLoggingModeProvider")

provider.RsopCreateSession _
FL_FORCE_CREATE_NAMESPACE, Null, namespaceLocation, hResult, eInfo

Set rsopProv = locator.ConnectServer _
(strComputer, namespaceLocation & "\User", null, null, Null, Null, 0 ,
Null)

Set colItems = rsopProv.ExecQuery("Select * from RSOP_GPO")

For Each objItem in colItems
WScript.Echo objItem.Name
Next

provider.RsopDeleteSession namespaceLocation, hResult
------------------------------------------------------------------------------------------------------------------------------

Are there any examples on how to do this in C#?

Thanks,

Mario
The Netherlands

Apr 17 '07 #2
<mc*********@interpolis.nlwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
Hi,

I'm trying to find out how to collect RSOP data in C#, but I haven't
been successfull yet.

Below is the code I Use in vbscript:

------------------------------------------------------------------------------------------------------------------------------
Const FL_FORCE_CREATE_NAMESPACE = 4

strComputer = "."

Set locator = CreateObject("WbemScripting.SWbemLocator")

Set connection = locator.ConnectServer _
(strComputer, "root\rsop", null, null, null, null, 0, null)

Set provider = connection.Get("RsopLoggingModeProvider")

provider.RsopCreateSession _
FL_FORCE_CREATE_NAMESPACE, Null, namespaceLocation, hResult, eInfo

Set rsopProv = locator.ConnectServer _
(strComputer, namespaceLocation & "\User", null, null, Null, Null, 0 ,
Null)

Set colItems = rsopProv.ExecQuery("Select * from RSOP_GPO")

For Each objItem in colItems
WScript.Echo objItem.Name
Next

provider.RsopDeleteSession namespaceLocation, hResult
------------------------------------------------------------------------------------------------------------------------------

Are there any examples on how to do this in C#?

Thanks,

Mario
The Netherlands


You'll have to use System.Management classes to access RSOP.
To give you an idea, following shows you how to create a session....

private ManagementBaseObject inputArgs = null;
private ManagementBaseObject outParams = null;
....

using(ManagementClass mc = new ManagementClass(new ManagementPath(
"root\\rsop:RsopLoggingModeProvider"),
new ObjectGetOptions(null, System.TimeSpan.MaxValue, true)))
{
inputArgs = mc.GetMethodParameters("RsopCreateSession");
inputArgs["flags"] = null;
inputArgs["UserSid"] = null;
outParams = mc.InvokeMethod("RsopCreateSession", inputArgs, null);
if(((uint)outParams.Properties["hResult"].Value) == 0)
Console.WriteLine(outParams.Properties["hResult"].Value);
....
// bind to the namespace and Delete the session when done...
.....
Willy.

Apr 17 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jorgen Grahn | last post by:
I have a set of tests in different modules: test_foo.py, test_bar.py and so on. All of these use the simplest possible internal layout: a number of classes containing test*() methods, and the good...
1
by: Tim | last post by:
I have an interesting challenge in front of me and I am not sure where to begin. I need to accomplish the following: While a user is visiting our website, I need to launch a process to...
2
by: serge calderara | last post by:
dear all, I am building an application which is collecting data from a database and display them in a windows form. My idea is to collect those data in a form that, they can be read by my...
5
by: antonyliu2002 | last post by:
I have 4 forms each on a separate page respectively form1.aspx, form2.aspx, form3.aspx, form4.aspx. On top of each of the four pages there are 4 links which link to the aforementioned 4 pages...
0
by: Antal Rutz | last post by:
Hi all, I'd like to collect snmp data from varoius network devices parallel. First I tried with my own threadpool class then I gave a try to Christopher Arndt's threadpool.py...
17
by: romixnews | last post by:
Hi, I'm facing the problem of analyzing a memory allocation dynamic and object creation dynamics of a very big C++ application with a goal of optimizing its performance and eventually also...
1
by: tommydog | last post by:
when do i write my data to the data base? i am building an image map generator. each time an image is clicked the coords and a text box contents are to be saved somehow. i am expecting upto 50...
1
by: Bob Alston | last post by:
Looking for design approach ideas for collecting data from multiple remote, standalone databases. I have built one of these in Access. Another I am told was built in Access. some others the...
2
by: lokica | last post by:
Hy! I need some help or a suggestion... I would like to collect data from a web page automatically... So, there is one page on which you select some parameters and it throws you out a table with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.