Click here to Skip to main content
15,914,943 members
Home / Discussions / C#
   

C#

 
AnswerRe: Listview sorting by group of items Pin
RaviRanjanKr25-Feb-11 18:40
professionalRaviRanjanKr25-Feb-11 18:40 
Questionparent/child tables and bindingsources Pin
LordZoster24-Feb-11 4:27
LordZoster24-Feb-11 4:27 
AnswerRe: parent/child tables and bindingsources Pin
PIEBALDconsult24-Feb-11 7:42
mvePIEBALDconsult24-Feb-11 7:42 
GeneralRe: parent/child tables and bindingsources Pin
LordZoster24-Feb-11 20:51
LordZoster24-Feb-11 20:51 
GeneralRe: parent/child tables and bindingsources Pin
PIEBALDconsult25-Feb-11 1:42
mvePIEBALDconsult25-Feb-11 1:42 
QuestionCoverting PowershellScript to C# code... help! Pin
Philip Lane24-Feb-11 0:15
Philip Lane24-Feb-11 0:15 
AnswerRe: Coverting PowershellScript to C# code... help! Pin
phil.o24-Feb-11 0:22
professionalphil.o24-Feb-11 0:22 
GeneralRe: Coverting PowershellScript to C# code... help! [modified] Pin
Philip Lane24-Feb-11 0:30
Philip Lane24-Feb-11 0:30 
Sorry, i didn't want people to think i wanted them to do all my work for me.... but if your offering! Wink | ;)

cls
$ErrorActionPreference = "SilentlyContinue"
$servers = Get-Content c:\Temp\servers.txt

foreach($srv in $servers)
{
	try
	{
		$ID = New-Object System.Security.Principal.NTAccount("AccountName")
		$SID = $ID.Translate([system.Security.Principal.SecurityIdentifier]).ToString()
		$WMISDDL = "A;CI;CCWP;;;" + $SID
		$WMISDDLPartialMatch = "A;\w*;\w+;;;" + $SID
		$security = Get-WmiObject -ComputerName $srv -Namespace root -Class __SystemSecurity
		$binarySD = @($null)
		$result = $security.PsBase.InvokeMethod("GetSD",$binarySD)
				
	  	write-host "`tConverting current permissions to SDDL format..."
		$converter = new-object system.management.ManagementClass Win32_SecurityDescriptorHelper
		$CurrentWMISDDL = $converter.BinarySDToSDDL($binarySD[0])

	  	write-host "`tBuilding the new permissions..."
		if (($CurrentWMISDDL.SDDL -match $WMISDDLPartialMatch) -and ($CurrentWMISDDL.SDDL -notmatch $WMISDDL))
		{
   			$NewWMISDDL = $CurrentWMISDDL.SDDL -replace $WMISDDLPartialMatch, $WMISDDL
		}
		else
		{
   			$NewWMISDDL = $CurrentWMISDDL.SDDL += "(" + $WMISDDL + ")"
		}

		# Convert SDDL back to Binary 
  		write-host `t"Converting SDDL back into binary form..."
		$WMIbinarySD = $converter.SDDLToBinarySD($NewWMISDDL)
		$WMIconvertedPermissions = ,$WMIbinarySD.BinarySD
		
		# Apply the changes
		write-host "`tApplying changes..."
		if($CurrentWMISDDL.SDDL.ToString().Contains($WMISDDL.ToString()))
		{
			write-host "`tCurrent WMI Permissions matches desired value..."
		}
		else
		{
   			$result = $security.PsBase.InvokeMethod("SetSD",$WMIconvertedPermissions) 
   			if($result='0'){write-host "`t`tApplied WMI Security complete."}		
		}
						
	}
	catch
	{
		Write-Host $Error[$Error.Count - 1].ToString()
	}
}
Write-Host "`nFinished" -ForegroundColor DarkBlue


modified on Thursday, February 24, 2011 7:29 AM

GeneralRe: Coverting PowershellScript to C# code... help! Pin
Richard MacCutchan24-Feb-11 0:55
mveRichard MacCutchan24-Feb-11 0:55 
GeneralRe: Coverting PowershellScript to C# code... help! Pin
Philip Lane24-Feb-11 1:32
Philip Lane24-Feb-11 1:32 
AnswerRe: Coverting PowershellScript to C# code... help! Pin
Eddy Vluggen24-Feb-11 0:40
professionalEddy Vluggen24-Feb-11 0:40 
GeneralRe: Coverting PowershellScript to C# code... help! Pin
Philip Lane24-Feb-11 1:59
Philip Lane24-Feb-11 1:59 
GeneralRe: Coverting PowershellScript to C# code... help! Pin
Eddy Vluggen25-Feb-11 22:51
professionalEddy Vluggen25-Feb-11 22:51 
GeneralRe: Coverting PowershellScript to C# code... help! Pin
Philip Lane1-Mar-11 2:00
Philip Lane1-Mar-11 2:00 
GeneralRe: Coverting PowershellScript to C# code... help! Pin
Eddy Vluggen1-Mar-11 3:51
professionalEddy Vluggen1-Mar-11 3:51 
GeneralRe: Coverting PowershellScript to C# code... help! Pin
Philip Lane1-Mar-11 23:42
Philip Lane1-Mar-11 23:42 
QuestionCalculate Plus Minus values from TextBox Pin
M Riaz Bashir23-Feb-11 19:10
M Riaz Bashir23-Feb-11 19:10 
AnswerRe: Calculate Plus Minus values from TextBox Pin
Anurag Gandhi23-Feb-11 20:16
professionalAnurag Gandhi23-Feb-11 20:16 
GeneralRe: Calculate Plus Minus values from TextBox Pin
M Riaz Bashir23-Feb-11 20:29
M Riaz Bashir23-Feb-11 20:29 
GeneralRe: Calculate Plus Minus values from TextBox Pin
OriginalGriff23-Feb-11 20:56
mveOriginalGriff23-Feb-11 20:56 
GeneralRe: Calculate Plus Minus values from TextBox Pin
Anurag Gandhi23-Feb-11 21:27
professionalAnurag Gandhi23-Feb-11 21:27 
GeneralRe: Calculate Plus Minus values from TextBox Pin
OriginalGriff23-Feb-11 23:07
mveOriginalGriff23-Feb-11 23:07 
GeneralRe: Calculate Plus Minus values from TextBox Pin
Pravin Patil, Mumbai23-Feb-11 22:31
Pravin Patil, Mumbai23-Feb-11 22:31 
QuestionLINQ to xml query Pin
faheemnadeem23-Feb-11 18:34
faheemnadeem23-Feb-11 18:34 
AnswerRe: LINQ to xml query Pin
#realJSOP24-Feb-11 4:55
professional#realJSOP24-Feb-11 4:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.