basti19885 10 Geschrieben 17. Mai 2011 Melden Teilen Geschrieben 17. Mai 2011 Hallo ich hab hier ein script gefunden, mit dem man die Registry "HKU" durchlaufen kann. Unter Xp geht das auch alles ohne Probleme. Unter win7 (x64) fliegt der bei Zeile 26 Zeichen 1 mit folgender Meldung raus: Ungültiger Prozeduraufruf oder ungültiges Argument: 'Left' Ich hab nicht also viel Plan von VBS, wär ganz nett wenn da mal jemand drüber guggen könnte. Danke! SetAllUsersRegKey.vbs 'Example: SetAllUsersRegKey "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1\1A00" "0000000" "REG_DWORD" Dim oShell, sCommand, oUserRegDic, oSubFolder, sKey, oReg, sSubKey, aRegKeys(), iKeys, aDesktopKeys, oFSO, oExec, oStdOut, sLine, iErrorLevel Dim sKeyName,sData,sType args = WScript.Arguments.Count If args < 2 then WScript.Echo "usage:" & vbCrlf & "SetAllUsersRegKey.vbs " &Chr(34) & "KeyName" & Chr(34) & " " & Chr(34) &"Value" & Chr(34) & " " & Chr(34) & "Type" & Chr(34) WScript.Quit end If sKeyName = WScript.Arguments.Item(0) sData = WScript.Arguments.Item(1) sType = WScript.Arguments.Item(2) iKeys = 0 Set oShell = CreateObject("Wscript.Shell") sCommand = "%comspec% /c " & oShell.ExpandEnvironmentStrings("%WINDIR%") & "\System32\Reg.exe " oShell.RegWrite "HKCU\" & sKeyName,sData,sType Set oUserRegDic = CreateObject("Scripting.Dictionary") Set oFSO = CreateObject("Scripting.FileSystemObject") For Each oSubFolder In oFSO.GetFolder(Left(oShell.SpecialFolders(0),InStr(oShell.SpecialFolders(0),"\All ")-1)).Subfolders 'Look into the users special folder and get a list of all subfolders (existing users) On Error Resume Next '"disable" error handeling oUserRegDic.Add oSubFolder,oSubFolder.Name On Error GoTo 0 ' "enable" error handeling Next For Each sKey In oUserRegDic.Keys 'Slam all user regdata into HKU for editing later oShell.Run sCommand & "LOAD " & Chr(34) & "HKU\" & oUserRegDic.Item(sKey) & Chr(34) & " " & chr(34) & sKey & "\NTUser.dat" & Chr(34),0,True Next Set oExec = oShell.Exec("reg query HKU") Do While oExec.Status = 0 'holds the script until comand has finished. WScript.Sleep 100 Loop Set oStdOut = oExec.StdOut Do Until oStdOut.AtEndOfStream 'Populates aRegKeys with all sub keys in HKU sLine = Trim(oStdOut.ReadLine) If Len(sLine) > 1 Then 'Thows out empty line Select Case sLine Case "! REG.EXE VERSION 3.0" 'do nothing / remove uneeded data Case "HKEY_USERS" 'do nothing / remove uneeded data Case Else If Not oStdOut.AtEndOfStream then 'prevents extra array element ReDim Preserve aRegKeys(iKeys + 1) end if aRegKeys(iKeys) = sLine iKeys = iKeys + 1 End Select End If Loop For Each sSubkey In aRegKeys Set oExec = oShell.Exec("reg query " & Chr(34) & sSubkey & "\Control Panel\Desktop" & Chr(34)) Do While oExec.Status = 0 'holds the script until comand has finished. WScript.Sleep 100 Loop iErrorLevel = oExec.ExitCode If iErrorLevel = 0 then' if the reg query is sucsessful the key belongs to a user oShell.RegWrite sSubkey & "\" & sKeyName,sData,sType 'do the reg edit End if Next For Each sKey In oUserRegDic.Keys 'Clean up user regdata entered earlier oShell.Run sCommand & "UNLOAD " & Chr(34) & "HKU\" & oUserRegDic.Item(sKey) & Chr(34),0,True Next Zitieren Link zu diesem Kommentar
NilsK 2.934 Geschrieben 17. Mai 2011 Melden Teilen Geschrieben 17. Mai 2011 Moin, wenn "Left" als ungültig bemängelt wird, liegt das meistens an dem Versuch, einen leeren String auszuwerten oder auf eine Variable zuzugreifen, in der gar keine Stringdaten vorliegen. Im konkreten Fall könnte es z.B. an fehlenden Berechtigungen liegen. Gruß, Nils Zitieren Link zu diesem Kommentar
basti19885 10 Geschrieben 18. Mai 2011 Autor Melden Teilen Geschrieben 18. Mai 2011 Danke für den Tip. Es lag an der geänderten Ordner Struktur ab Vista(?). Anbei dir Überarbeitete Version, vielleicht kann das ja jemand gebrauchen. 'Example: SetAllUsersRegKey "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1\1A00" "0000000" "REG_DWORD" 'Example > Win Vista .. : SetAllUsersRegKey "Software\Microsoft\Windows\CurrentVersion\Internet Settings\EnableHttp1_1" "0000001" "REG_DWORD" Option Explicit Dim oShell, sCommand, oUserRegDic, oSubFolder, sKey, oReg, sSubKey, aRegKeys(), iKeys, aDesktopKeys, oFSO, oExec, oStdOut, sLine, iErrorLevel, dtmConvertedDate Dim args, strComputer, objWMIService, colOperatingSystems, objOperatingSystem, sKeyName, sData, sType, OSVer, sMyFolder args = WScript.Arguments.Count If args < 2 then WScript.Echo "usage:" & vbCrlf & "SetAllUsersRegKey.vbs " &Chr(34) & "KeyName" & Chr(34) & " " & Chr(34) &"Value" & Chr(34) & " " & Chr(34) & "Type" & Chr(34) WScript.Quit end If ' get OS Version ' OS > XP = Other Path Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime") strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems OSVer = Left(objOperatingSystem.Version,1) Next if (OSVer < 6) Then ' OS is XP or lower sMyFolder = "\All " Else sMyFolder = "\Public" End If sKeyName = WScript.Arguments.Item(0) 'RegKey to Edit sData = WScript.Arguments.Item(1) 'New Value sType = WScript.Arguments.Item(2) 'Value Type iKeys = 0 Set oShell = CreateObject("Wscript.Shell") sCommand = "%comspec% /c " & oShell.ExpandEnvironmentStrings("%WINDIR%") & "\System32\Reg.exe " oShell.RegWrite "HKCU\" & sKeyName,sData,sType Set oUserRegDic = CreateObject("Scripting.Dictionary") Set oFSO = CreateObject("Scripting.FileSystemObject") For Each oSubFolder In oFSO.GetFolder(Left(oShell.SpecialFolders(0),InStr(oShell.SpecialFolders(0),sMyFolder)-1)).Subfolders 'Look into the users special folder and get a list of all subfolders (existing users) On Error Resume Next '"disable" error handeling oUserRegDic.Add oSubFolder,oSubFolder.Name On Error GoTo 0 ' "enable" error handeling Next For Each sKey In oUserRegDic.Keys 'Slam all user regdata into HKU for editing later oShell.Run sCommand & "LOAD " & Chr(34) & "HKU\" & oUserRegDic.Item(sKey) & Chr(34) & " " & chr(34) & sKey & "\NTUser.dat" & Chr(34),0,True Next Set oExec = oShell.Exec("reg query HKU") Do While oExec.Status = 0 'holds the script until comand has finished. WScript.Sleep 100 Loop Set oStdOut = oExec.StdOut Do Until oStdOut.AtEndOfStream 'Populates aRegKeys with all sub keys in HKU sLine = Trim(oStdOut.ReadLine) If Len(sLine) > 1 Then 'Thows out empty line Select Case sLine Case "! REG.EXE VERSION 3.0" 'do nothing / remove uneeded data Case "HKEY_USERS" 'do nothing / remove uneeded data Case Else If Not oStdOut.AtEndOfStream then 'prevents extra array element ReDim Preserve aRegKeys(iKeys + 1) end if aRegKeys(iKeys) = sLine iKeys = iKeys + 1 End Select End If Loop For Each sSubkey In aRegKeys Set oExec = oShell.Exec("reg query " & Chr(34) & sSubkey & "\Control Panel\Desktop" & Chr(34)) Do While oExec.Status = 0 'holds the script until comand has finished. WScript.Sleep 100 Loop iErrorLevel = oExec.ExitCode If iErrorLevel = 0 then' if the reg query is sucsessful the key belongs to a user oShell.RegWrite sSubkey & "\" & sKeyName,sData,sType 'do the reg edit End if Next For Each sKey In oUserRegDic.Keys 'Clean up user regdata entered earlier oShell.Run sCommand & "UNLOAD " & Chr(34) & "HKU\" & oUserRegDic.Item(sKey) & Chr(34),0,True Next WScript.Quit Zitieren Link zu diesem Kommentar
basti19885 10 Geschrieben 18. Mai 2011 Autor Melden Teilen Geschrieben 18. Mai 2011 'Example: DelAllUsersRegKey.vbs "Software\Microsoft\Windows\CurrentVersion\Internet Settings\EnableHttp1_1" Option Explicit Dim oShell, sCommand, oUserRegDic, oSubFolder, sKey, oReg, sSubKey, aRegKeys(), iKeys, aDesktopKeys, oFSO, oExec, oStdOut, sLine, iErrorLevel, dtmConvertedDate Dim args, strComputer, objWMIService, colOperatingSystems, objOperatingSystem, sKeyName, sData, sType, OSVer, sMyFolder, iErrorLevel2 args = WScript.Arguments.Count If args < 1 then WScript.Echo "usage:" & vbCrlf & "DelAllUsersRegKey.vbs " &Chr(34) & "KeyName" & Chr(34) WScript.Quit end If sKeyName = WScript.Arguments.Item(0) sData = "0000000" sType = "REG_DWORD" ' get OS Version ' OS > XP = Other Path Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime") strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems OSVer = Left(objOperatingSystem.Version,1) Next if (OSVer < 6) Then ' OS is XP or lower sMyFolder = "\All " Else sMyFolder = "\Public" End If iKeys = 0 Set oShell = CreateObject("Wscript.Shell") sCommand = "%comspec% /c " & oShell.ExpandEnvironmentStrings("%WINDIR%") & "\System32\Reg.exe " oShell.RegWrite "HKCU\" & sKeyName,sData,sType Set oUserRegDic = CreateObject("Scripting.Dictionary") Set oFSO = CreateObject("Scripting.FileSystemObject") For Each oSubFolder In oFSO.GetFolder(Left(oShell.SpecialFolders(0),InStr(oShell.SpecialFolders(0),sMyFolder)-1)).Subfolders 'Look into the users special folder and get a list of all subfolders (existing users) On Error Resume Next '"disable" error handeling oUserRegDic.Add oSubFolder,oSubFolder.Name On Error GoTo 0 ' "enable" error handeling Next For Each sKey In oUserRegDic.Keys 'Slam all user regdata into HKU for editing later oShell.Run sCommand & "LOAD " & Chr(34) & "HKU\" & oUserRegDic.Item(sKey) & Chr(34) & " " & chr(34) & sKey & "\NTUser.dat" & Chr(34),0,True Next Set oExec = oShell.Exec("reg query HKU") Do While oExec.Status = 0 'holds the script until comand has finished. WScript.Sleep 100 Loop Set oStdOut = oExec.StdOut Do Until oStdOut.AtEndOfStream 'Populates aRegKeys with all sub keys in HKU sLine = Trim(oStdOut.ReadLine) If Len(sLine) > 1 Then 'Thows out empty line Select Case sLine Case "! REG.EXE VERSION 3.0" 'do nothing / remove uneeded data Case "HKEY_USERS" 'do nothing / remove uneeded data Case Else If Not oStdOut.AtEndOfStream then 'prevents extra array element ReDim Preserve aRegKeys(iKeys + 1) end if aRegKeys(iKeys) = sLine iKeys = iKeys + 1 End Select End If Loop For Each sSubkey In aRegKeys Set oExec = oShell.Exec("reg query " & Chr(34) & sSubkey & "\Control Panel\Desktop" & Chr(34)) Do While oExec.Status = 0 'holds the script until comand has finished. WScript.Sleep 100 Loop iErrorLevel = oExec.ExitCode On Error Resume Next oShell.RegRead sSubkey & "\" & sKeyName iErrorLevel2 = Err Err.clear If iErrorLevel = 0 and iErrorLevel2 = 0 then' if the reg query is sucsessful the key belongs to a user oShell.RegDelete sSubkey & "\" & sKeyName 'do the reg edit End if Next For Each sKey In oUserRegDic.Keys 'Clean up user regdata entered earlier oShell.Run sCommand & "UNLOAD " & Chr(34) & "HKU\" & oUserRegDic.Item(sKey) & Chr(34),0,True Next WScript.Quit Zitieren Link zu diesem Kommentar
Empfohlene Beiträge
Schreibe einen Kommentar
Du kannst jetzt antworten und Dich später registrieren. Falls Du bereits ein Mitglied bist, logge Dich jetzt ein.