dpole86
Goto Top

Per Batch oder VBS einen schlüssel suchen und den Wert des Schlüssels ändern

Guten Abend zusammen.

Ich brauche ein Script was folgendes in folgendem pfad sucht und alles Einträge auf "0" ändert

Das wird gesucht >> 12bbebe6-58d6-4636-95bb-3217ef867c1a
unter folgendem Registry Pfad:

HKLM\System\CurrentControlset\Control\Power\User
HKLM\System\Controlset1\Control\Power\User
HKLM\System\Controlset2\Control\Power\User

Dort sollen die Einträge ACSettingIndex und DCSetting Index auf 0 gesetzt werden. Ist ein Reg Birnary

Grüße

EDIT::

habe hier einen Anfang gefunden ist allerdings für eine DVD Region.
kann mir damit jemand helfen?

Option Explicit
Const HKEY_LOCAL_MACHINE = &H80000002
Dim oReg : Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim oShell : Set oShell = CreateObject("WScript.Shell")
Dim sPath, aSub, sKey, aSubToo, sKeyToo, dwValue

' Get all keys within sPath
sPath = "SYSTEM\CurrentControlSet\"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aSub

' Loop through each key
For Each sKey In aSub
' Get all subkeys within the key 'sKey'
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath & "\" & sKey, aSubToo
For Each sKeyToo In aSubToo
' Try and get the DWORD value in Device Parameters\DefaultDvdRegion
oReg.GetDWORDValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey & "\" & sKeyToo & "\Device Parameters", "DefaultDvdRegion", dwValue
Wscript.Echo "DVDRegion of " & sPath & "\" & sKey & "\" & sKeyToo & " = " & dwValue
Next
Next

Content-Key: 219561

Url: https://administrator.de/contentid/219561

Ausgedruckt am: 29.03.2024 um 09:03 Uhr

Mitglied: colinardo
colinardo 16.10.2013 aktualisiert um 17:38:00 Uhr
Goto Top
Hi,
So einfach wird das nicht, denn die Schlüssel sind im Besitz von "SYSTEM" und selbst Administratoren werden hier nur Leserechte erteilt, du musst dann also erst die entsprechenden Ordner in Besitz nehmen dann die Werte ändern und anschließend die Rechte wieder zurücksetzen.
Das finden der Keys ist ja kein Problem.
Werde das mal evaluieren, mache das aber mit Powershell...

Grüße Uwe
Mitglied: Dpole86
Dpole86 17.10.2013 um 07:19:51 Uhr
Goto Top
Moin Uwe

Sorry aber das glaube ich nicht.
Ich kann ja auch als User über powercfg die Werte verändern.

Grüße
Mitglied: colinardo
colinardo 17.10.2013 um 08:44:26 Uhr
Goto Top
Schau doch bitte selber nach .... ich würde sowas ja nicht grundlos behaupten ! powercfg nutzt dazu Systemfunktionen um die Werte zu setzen.
Mitglied: Dpole86
Dpole86 17.10.2013 um 09:21:11 Uhr
Goto Top
Die Frage ist doch eher ob du mir das zusammenschnippseln kannst oder nicht...
Weil Suchen kann ich 1000 Stunden und Trotzdem komm ich nicht weiteR ;)

wenn du kein bock hast oder einfach nur einen schlechten tag dann sags ;)
aber komm mir nicht mit "such Selber"

weil dann brauch ich kein Administrator-Forum ...dann reicht google
Mitglied: java667
java667 17.10.2013 um 09:34:02 Uhr
Goto Top
Das ist ein Admin Forum und als Admin sollte man gelernt haben, sich das ein oder andere selbst zu erarbeiten. Wenn du also der Meinung bist, das die Aussage falsch ist, dann prüfe es nach und widerlege es. Ansonsten sollte man die Füße still halten, wenn man etwas "kostenlos" haben möchte...oder alternativ googeln...bedeutet aber Eigeninitiative und das scheint nicht so dein Ding zu sein.
Mitglied: colinardo
colinardo 17.10.2013 um 10:04:26 Uhr
Goto Top
Zitat von @Dpole86:
Die Frage ist doch eher ob du mir das zusammenschnippseln kannst oder nicht...
Weil Suchen kann ich 1000 Stunden und Trotzdem komm ich nicht weiteR ;)
so habe ich das nicht gemeint, du behauptest hier nur etwas was du nicht selber nachgeprüft hast. Ich habe mir natürlich die Keys angeschaut, und würde sowas nur schreiben wenn ich es nachgeprüft habe...
warum denn so aufbrausend, ich habe dir im anderen Thread dazu eine Lösung präsentiert die du anscheinend aus welchen Gründen auch immer abgelehnt hast.
Ich kann die hierzu ein Script bauen, habe aber gerade nicht genug Zeit um es adhoc zu liefern, vor allem weil ich meine Scripte vorher Teste bevor ich was unfertiges abliefere was auf dem ein oder anderen System nicht läuft...

Grüße Uwe
Mitglied: Dpole86
Dpole86 17.10.2013 um 10:06:00 Uhr
Goto Top
Neeeeeeeeein gar nicht .... ich kann dir ja mal meine 5 Millionen Tabs schicken die ich schon durchsucht habe ;)
Ich suche zunächst selber udn frage dann nach hilfe ;)
Aber denk was du willst...

Ach und wenn man als Admin nur Sprüche klopfen aber nicht helfen kann, dann ist man ein möchtegern admin ;)
ich habe genügend Themen geschrieben wo kein mensch geantwortet hat. somit erzählt mir nichts von "Administrator-Forum"
Im Grunde ist es eine Frechheit sich admin zu nennen wenn man nicht hilft.

Ich bin leidenschaftlicher Admin und versuche bei allem zu helfen was es geht. Aber leidenschaft ist dir wohl ein Fremdwort ;)
Mitglied: Dpole86
Dpole86 17.10.2013 um 10:08:04 Uhr
Goto Top
Hi

Ja ich habe "abgelehnt" weil ich die Methode geändert habe.
Und ich brauch kein Script was zu 100% funktioniert

basteln ist mein Hobbie und ich liebe es zu basteln ;)

Trotdzem danke dir recht herzlich face-smile
Mitglied: colinardo
colinardo 17.10.2013 aktualisiert um 12:11:39 Uhr
Goto Top
Zitat von @Dpole86:
basteln ist mein Hobbie und ich liebe es zu basteln ;)
dann bastel mal ...

Powershell-Script inklusive setzen der Zugriffsrechte der betreffenden Keys (getestet auf Win7 64bit in einer administrativen Powershell-Konsole)
function enable-privilege {
 param(
  ## Basiert auf einem Script von
  ## http:{{comment_single_line_double_slash:0}}
  [ValidateSet(
   "SeAssignPrimaryTokenPrivilege", "SeAuditPrivilege", "SeBackupPrivilege",  
   "SeChangeNotifyPrivilege", "SeCreateGlobalPrivilege", "SeCreatePagefilePrivilege",  
   "SeCreatePermanentPrivilege", "SeCreateSymbolicLinkPrivilege", "SeCreateTokenPrivilege",  
   "SeDebugPrivilege", "SeEnableDelegationPrivilege", "SeImpersonatePrivilege", "SeIncreaseBasePriorityPrivilege",  
   "SeIncreaseQuotaPrivilege", "SeIncreaseWorkingSetPrivilege", "SeLoadDriverPrivilege",  
   "SeLockMemoryPrivilege", "SeMachineAccountPrivilege", "SeManageVolumePrivilege",  
   "SeProfileSingleProcessPrivilege", "SeRelabelPrivilege", "SeRemoteShutdownPrivilege",  
   "SeRestorePrivilege", "SeSecurityPrivilege", "SeShutdownPrivilege", "SeSyncAgentPrivilege",  
   "SeSystemEnvironmentPrivilege", "SeSystemProfilePrivilege", "SeSystemtimePrivilege",  
   "SeTakeOwnershipPrivilege", "SeTcbPrivilege", "SeTimeZonePrivilege", "SeTrustedCredManAccessPrivilege",  
   "SeUndockPrivilege", "SeUnsolicitedInputPrivilege")]  
  $Privilege,
  ## The process on which to adjust the privilege. Defaults to the current process.
  $ProcessId = $pid,
  ## Switch to disable the privilege, rather than enable it.
  [Switch] $Disable
 )

 ## Taken from P/Invoke.NET with minor adjustments.
 $definition = @'  
 using System;
 using System.Runtime.InteropServices;
  
 public class AdjPriv
 {
  [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]  
  internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
   ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
  
  [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]  
  internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
  [DllImport("advapi32.dll", SetLastError = true)]  
  internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
  [StructLayout(LayoutKind.Sequential, Pack = 1)]
  internal struct TokPriv1Luid
  {
   public int Count;
   public long Luid;
   public int Attr;
  }
  
  internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
  internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
  internal const int TOKEN_QUERY = 0x00000008;
  internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
  public static bool EnablePrivilege(long processHandle, string privilege, bool disable)
  {
   bool retVal;
   TokPriv1Luid tp;
   IntPtr hproc = new IntPtr(processHandle);
   IntPtr htok = IntPtr.Zero;
   retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
   tp.Count = 1;
   tp.Luid = 0;
   if(disable)
   {
    tp.Attr = SE_PRIVILEGE_DISABLED;
   }
   else
   {
    tp.Attr = SE_PRIVILEGE_ENABLED;
   }
   retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
   retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
   return retVal;
  }
 }
'@  

 $processHandle = (Get-Process -id $ProcessId).Handle
 $type = Add-Type $definition -PassThru
 $type::EnablePrivilege($processHandle, $Privilege, $Disable)
}


enable-privilege SeTakeOwnershipPrivilege
$regpath = Get-ChildItem -Recurse -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power\User"   

foreach ($key in $regpath){
    if ($key.PSChildName -eq "12bbebe6-58d6-4636-95bb-3217ef867c1a"){  
        
        # Besitz des Keys für Administratoren übernehmen
        $path = $key.Name.replace("HKEY_LOCAL_MACHINE\","")  
        $regkey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($path,[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership)
        $acl = $regkey.GetAccessControl([System.Security.AccessControl.AccessControlSections]::None)
        $admins = [System.Security.Principal.NTAccount]"Administratoren"  
        $acl.SetOwner($admins)
        $regkey.SetAccessControl($acl)
        #----------
    
        # Administratoren volle Rechte geben
        $acl = $regkey.GetAccessControl()
        $rule = new-object System.Security.AccessControl.RegistryAccessRule("Administratoren","FullControl","Allow")  
        $acl.SetAccessRule($rule)
        $regkey.SetAccessControl($acl)
        $regkey.close()
        #---------------
    
        # Setze Werte -----
        Set-ItemProperty -Path $key.PSPath -Name "ACSettingIndex" -Value 0  
        Set-ItemProperty -Path $key.PSPath -Name "DCSettingIndex" -Value 0  
        #------------------
    
    }
}

Viel Spaß
Grüße Uwe
Mitglied: Dpole86
Dpole86 17.10.2013 um 12:23:33 Uhr
Goto Top
Hi Danke fürs Skript...

broingt mir in unserer Firmenstruktur leider nichts.

Kann mir jemand folgeden befehl in eine For-Schleife packen?

reg Query HKLM\SYSTEM\CurrentControlSet\Control\Power\User\Default\PowerSchemes /f "12bbebe6-58d6-4636-95bb-3217ef867c1a" /s

ist eine bat-datei

Nächste Frage wäre wie gebe ich den Pfad in eine Variable ?
Mitglied: java667
java667 17.10.2013 um 13:09:13 Uhr
Goto Top
Unglaublich...warum denkst du nicht mal für 5 Cent selbst nach und wirst deinem Gehalt das du bekommst gerecht?

Dreister gehst nicht mehr...
Mitglied: Dpole86
Dpole86 17.10.2013 um 13:27:16 Uhr
Goto Top
Zitat von @colinardo:
> Zitat von @Dpole86:
> basteln ist mein Hobbie und ich liebe es zu basteln ;)
dann bastel mal ...

Powershell-Script inklusive setzen der Zugriffsrechte der betreffenden Keys (getestet auf Win7 64bit in einer administrativen
Powershell-Konsole)

> function enable-privilege {
>  param(
>   ## Basiert auf einem Script von
>   ## http:{{comment_single_line_double_slash:0}}
>   [ValidateSet(
>    "SeAssignPrimaryTokenPrivilege", "SeAuditPrivilege", "SeBackupPrivilege",  
>    "SeChangeNotifyPrivilege", "SeCreateGlobalPrivilege", "SeCreatePagefilePrivilege",  
>    "SeCreatePermanentPrivilege", "SeCreateSymbolicLinkPrivilege", "SeCreateTokenPrivilege",  
>    "SeDebugPrivilege", "SeEnableDelegationPrivilege", "SeImpersonatePrivilege",  
> "SeIncreaseBasePriorityPrivilege",  
>    "SeIncreaseQuotaPrivilege", "SeIncreaseWorkingSetPrivilege", "SeLoadDriverPrivilege",  
>    "SeLockMemoryPrivilege", "SeMachineAccountPrivilege", "SeManageVolumePrivilege",  
>    "SeProfileSingleProcessPrivilege", "SeRelabelPrivilege", "SeRemoteShutdownPrivilege",  
>    "SeRestorePrivilege", "SeSecurityPrivilege", "SeShutdownPrivilege",  
> "SeSyncAgentPrivilege",  
>    "SeSystemEnvironmentPrivilege", "SeSystemProfilePrivilege", "SeSystemtimePrivilege",  
>    "SeTakeOwnershipPrivilege", "SeTcbPrivilege", "SeTimeZonePrivilege",  
> "SeTrustedCredManAccessPrivilege",  
>    "SeUndockPrivilege", "SeUnsolicitedInputPrivilege")]  
>   $Privilege,
>   ## The process on which to adjust the privilege. Defaults to the current process.
>   $ProcessId = $pid,
>   ## Switch to disable the privilege, rather than enable it.
>   [Switch] $Disable
>  )
> 
>  ## Taken from P/Invoke.NET with minor adjustments.
>  $definition = @'  
>  using System;
>  using System.Runtime.InteropServices;
>   
>  public class AdjPriv
>  {
>   [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]  
>   internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
>    ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
>   
>   [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]  
>   internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);
>   [DllImport("advapi32.dll", SetLastError = true)]  
>   internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);
>   [StructLayout(LayoutKind.Sequential, Pack = 1)]
>   internal struct TokPriv1Luid
>   {
>    public int Count;
>    public long Luid;
>    public int Attr;
>   }
>   
>   internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
>   internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
>   internal const int TOKEN_QUERY = 0x00000008;
>   internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
>   public static bool EnablePrivilege(long processHandle, string privilege, bool disable)
>   {
>    bool retVal;
>    TokPriv1Luid tp;
>    IntPtr hproc = new IntPtr(processHandle);
>    IntPtr htok = IntPtr.Zero;
>    retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
>    tp.Count = 1;
>    tp.Luid = 0;
>    if(disable)
>    {
>     tp.Attr = SE_PRIVILEGE_DISABLED;
>    }
>    else
>    {
>     tp.Attr = SE_PRIVILEGE_ENABLED;
>    }
>    retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
>    retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
>    return retVal;
>   }
>  }
> '@  
> 
>  $processHandle = (Get-Process -id $ProcessId).Handle
>  $type = Add-Type $definition -PassThru
>  $type::EnablePrivilege($processHandle, $Privilege, $Disable)
> }
> 
> 
> enable-privilege SeTakeOwnershipPrivilege
> $regpath = Get-ChildItem -Recurse -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Power\User"   
> 
> foreach ($key in $regpath){
>     if ($key.PSChildName -eq "12bbebe6-58d6-4636-95bb-3217ef867c1a"){  
>         
>         # Besitz des Keys für Administratoren übernehmen
>         $path = $key.Name.replace("HKEY_LOCAL_MACHINE\","")  
>         $regkey =
> [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($path,[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership)
>         $acl = $regkey.GetAccessControl([System.Security.AccessControl.AccessControlSections]::None)
>         $admins = [System.Security.Principal.NTAccount]"Administratoren"  
>         $acl.SetOwner($admins)
>         $regkey.SetAccessControl($acl)
>         #----------
>     
>         # Administratoren volle Rechte geben
>         $acl = $regkey.GetAccessControl()
>         $rule = new-object
> System.Security.AccessControl.RegistryAccessRule("Administratoren","FullControl","Allow")  
>         $acl.SetAccessRule($rule)
>         $regkey.SetAccessControl($acl)
>         $regkey.close()
>         #---------------
>     
>         # Setze Werte -----
>         Set-ItemProperty -Path $key.PSPath -Name "ACSettingIndex" -Value 0  
>         Set-ItemProperty -Path $key.PSPath -Name "DCSettingIndex" -Value 0  
>         #------------------
>     
>     }
> }
> 

Viel Spaß
Grüße Uwe

Ich muss mich entschuldigen der Code ist der Wahnsinn!!
allerdings kann ich ihn nicht ausführen?VBS geht nicht
Mitglied: colinardo
colinardo 17.10.2013 um 13:29:59 Uhr
Goto Top
Zitat von @Dpole86:
allerdings kann ich ihn nicht ausführen?VBS geht nicht
Bitte lesen, es ist ein "Powershell"-Script
Mitglied: Dpole86
Dpole86 17.10.2013 um 13:39:53 Uhr
Goto Top
Zitat von @colinardo:
> Zitat von @Dpole86:
> allerdings kann ich ihn nicht ausführen?VBS geht nicht
Bitte lesen, es ist ein "Powershell"-Script

Und wie kann ich das jetzt auf allen Rechnern ausführen ohne Powershell installiert zu haben?