http://dieseyer.de • all rights reserved • © 2011 v11.4

'v4.4***************************************************
' File: autostart-run.vbs
' Autor: dieseyer@gmx.de
' dieseyer.de
'
' Programm listet die RegKeys, die Auto-Start / Auto-Run
' veranlasst
'*******************************************************

Option Explicit ' Siehe http://dieseyer.de/dse-wsh-lernen.html#OptionExpl

Dim WshShell, WSHNet, fso, ObjReg, ObjRemote, KeyX, Text, RootKey, oVal, FileOut, PC ' , FileIn ', Datei

Set WSHShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSHNet = WScript.CreateObject("WScript.Network")


If (fso.FileExists("REGOBJ.DLL")) Then ' Regobj.dll registrieren (erfordert AdminRechte)
Text = "REGSVR32.EXE " & "REGOBJ.DLL" & " /S" ' damit läßt sich besser auf die registry zugreifen
WshShell.Run (Text),,TRUE ' muß im gleichen Verzeichnis wie das Script stehen
Set ObjReg = WScript.CreateObject("RegObj.Registry")
Else
MsgBox "REGSVR32.EXE " & "REGOBJ.DLL" & " /S" & vbTab & " konnte nicht aufgerufen werden!", , WScript.ScriptName
WScript.Quit
End If

Text = "Von welchem Computer soll ermittelt werden, " & vbCRLF
Text = Text & "wer als letzter angemeldet war bzw. aktuell angemeldet ist?"

PC = wshnet.ComputerName
PC = "MeinPC"
PC = InputBox (Text, WScript.ScriptName, PC )

If PC = "" then PC = wshnet.ComputerName

' Set FileOut = fso.OpenTextFile( PC & ".txt" , 8, true) ' alte Datei fortsetzen
Set FileOut = fso.OpenTextFile( PC & ".txt" , 2, true) ' neue Datei
FileOut.WriteLine now() & " ===> " & PC

' Set ObjRemote = objReg.RemoteRegistry(wshnet.ComputerName) ' Objekt zeigt auf aktuellen PC (REGOBJ.DLL)
Set ObjRemote = objReg.RemoteRegistry( PC ) ' Objekt zeigt auf (Remote-) PC (REGOBJ.DLL)

' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices
' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce

' HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
' HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
' HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices
' HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce

' HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows


Text = "*** startet vor Kennwortabfrage - nachdem graphische Benutzeroberfläche erschienen ist "

KeyX = "\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run"
RegKeysRead KeyX, vbCRLF & Text
KeyX = "\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce"
RegKeysRead KeyX, ""
KeyX = "\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices"
RegKeysRead KeyX, ""
KeyX = "\HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce"
RegKeysRead KeyX, ""


KeyX = "\HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services"
RegKeysRead KeyX, ""

FileOut.WriteLine
FileOut.WriteLine

Text = "*** startet nach der Kennwortabfrage / nach der Anmeldung "
KeyX = "\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"
RegKeysRead KeyX, vbCRLF & Text
KeyX = "\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce"
RegKeysRead KeyX, ""
KeyX = "\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices"
RegKeysRead KeyX, ""
KeyX = "\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce"
RegKeysRead KeyX, ""



KeyX = "\HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows"
FileOut.WriteLine
FileOut.WriteLine KeyX
On Error Resume Next
Set RootKey = objRemote.RegKeyFromString(KeyX)
For Each oVal In RootKey.Values ' Auflistung Werte
If InStr( UCase( oVal.Name ), "LOAD") Then FileOut.WriteLine ( " " & oVal.Name & vbTab & " ==> " & vbTab & oVal.Value)
' If InStr( UCase( oVal.Name ), "DEVICE") Then FileOut.WriteLine ( " " & oVal.Name & vbTab & " ==> " & vbTab & oVal.Value)
If InStr( UCase( oVal.Name ), "RUN" ) Then FileOut.WriteLine ( " " & oVal.Name & vbTab & " ==> " & vbTab & oVal.Value)
Next
Set RootKey = nothing
On Error GoTo 0

Set ObjReg = nothing
WshShell.Run ("REGSVR32.EXE " & "REGOBJ.DLL" & " /U /S"),,TRUE ' REGOBJ.DLL - Registrierung aufheben


' c:\winnt\winstart.bat

If UCase( wshnet.ComputerName ) = UCase( PC )then
INIread "c:\winnt\win.ini"
INIread "c:\winnt\System.ini"
WinStart "c:\winnt\winstart.bat"
Else
If fso.FileExists( "\\" & PC & "\c$\winnt\win.ini" ) Then
INIread "\\" & PC & "\c$\winnt\win.ini"
INIread "\\" & PC & "\c$\winnt\System.ini"
WinStart "\\" & PC & "\c$\winnt\winstart.bat"
Else
FileOut.WriteLine
FileOut.WriteLine
FileOut.WriteLine "\\" & PC & "\c$\winnt\win.ini - nicht erreichbar"
FileOut.WriteLine "\\" & PC & "\c$\winnt\System.ini - nicht erreichbar"
FileOut.WriteLine "\\" & PC & "\c$\winnt\winstart.bat - nicht erreichbar"
End If
End If


FileOut.WriteLine
FileOut.WriteLine
FileOut.WriteLine now() & " ===> " & PC
FileOut.Close
Set FileOut = Nothing
Set fso = Nothing

WSHShell.Run ( PC & ".txt" )

WScript.Quit



'**************************************************************
Sub RegKeysRead ( KeyX, Text )
'**************************************************************

FileOut.WriteLine Text
FileOut.WriteLine KeyX
On Error Resume Next
Set RootKey = objRemote.RegKeyFromString(KeyX)
For Each oVal In RootKey.Values ' Auflistung Werte
FileOut.WriteLine ( " ==>|" & oVal.Value & "|<==" )
Next
Set RootKey = nothing
On Error GoTo 0
End Sub ' RegKeysRead ( KeyX, Text )
'**************************************************************


'**************************************************************
Sub INIread ( Datei )
'**************************************************************
Dim i, FileIn

FileOut.WriteLine
if not fso.FileExists( Datei ) Then
FileOut.WriteLine " " & Datei & " ==> existiert nicht!!!"
Else
FileOut.WriteLine "*** " & Datei & " - Infos:"
Set FileIn = FSO.OpenTextFile(Datei, 1 ) ' Datei zum Lesen öffnen
i=0
Do While Not (FileIn.atEndOfStream) ' wenn Datei nicht zu ende ist, weiter machen
ReDim Preserve Zeile(i)
Zeile(i) = FileIn.Readline
If Instr( UCase( Zeile(i) ), "RUN=" ) Then FileOut.WriteLine Zeile(i)
If Instr( UCase( Zeile(i) ), "LOAD=") Then FileOut.WriteLine Zeile(i)
' If Instr( UCase( Zeile(i) ), "AIFC=") Then FileOut.WriteLine Zeile(i)
i = i + 1
Loop
FileIn.Close
Set FileIn = nothing
End If

End Sub ' INIread ( Datei )
'**************************************************************


'**************************************************************
Sub WinStart ( Datei )
'**************************************************************
Dim i, FileIn

FileOut.WriteLine
if not fso.FileExists( Datei ) Then
FileOut.WriteLine " " & Datei & " ==> existiert nicht!!!"
Else
FileOut.WriteLine "*** " & Datei & " - Infos:"
Set FileIn = FSO.OpenTextFile(Datei, 1 ) ' Datei zum Lesen öffnen
i=0
Do While Not (FileIn.atEndOfStream) ' wenn Datei nicht zu ende ist, weiter machen
ReDim Preserve Zeile(i)
Zeile(i) = FileIn.Readline
FileOut.WriteLine Zeile(i)
i = i + 1
Loop
FileIn.Close
Set FileIn = nothing
End If

End Sub ' WinStart ( Datei )
'**************************************************************

http://dieseyer.de • all rights reserved • © 2011 v11.4