degnlb
Goto Top

Mit VBscript WMI-Daten in Excel schreiben

Hallo,

ich habe für mein Netzwerk ein Script geschrieben, welches Momentan für einen Wunschrecher div. Daten aus der Registry ausliest über WMI und diese Daten erfolgreich in eine Textdatei schreibt.
Ich Prüfe erst, welche Windows-Version installiert ist und hole mir anschließend die Daten (da ich noch Neuling in Sachen VB-Script bin, bitte nicht wundern wegen der Übersichtlichkeit etc ;) )
Mein Problem welches ich momentan habe ist, dass ich die Daten gerne in eine Excel-Tabelle hätte, mich aber schwer tu, dieses zu realisieren.
Desweiteren wäre ein weiterer Schritt - zu dem ich hin will-, dass das Script meinen ganzen IP-Adressraum durchsucht, die vergebenen IP-Adressen + Rechnernamen heraussucht und diese dann mit den Registry-Daten hintereinander in die Excel-Tabelle schreibt (aber das ist erstmal nicht so wichtig, vielmehr würde ich gerne erstmal hinbekommen, dass ich die Daten in Excel ausgeben kann).
Hier der "txt-Datei"-Quellcode... mit meinen Excel-versuchen verschone ich euch lieber:


option explicit

Const HKEY_LOCAL_MACHINE = &H80000002
Dim WshShell
Dim wmi_object 	
Dim TxtDatei   	
Dim oTxt 		
Dim strValue 	
Dim ma_pkey, ma_w7ulti_path, ma_w7_vkey, win_version_path, win_version_key, win_sp_key, ma_path, xp_path, xp_key, xp_sp_path
Dim AbfragePc		'Welcher PC abgefragt wird  

ma_path			 = "SOFTWARE\McAfee\DesktopProtection"				  
ma_pkey 		 = "Product"  
ma_w7ulti_path 	 = "SOFTWARE\Wow6432Node\McAfee\DesktopProtection"   
ma_w7_vkey   	 = "szProductVer"  
win_version_path = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"   
win_version_key  = "ProductName"  
win_sp_key		 = "CSDVersion"  
xp_path			 = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"  
xp_key			 = "ProductName"  
xp_sp_path		 = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"  

AbfragePc = "."  

set TxtDatei = CreateObject ("Scripting.FileSystemObject")  
set WshShell = CreateObject("WScript.Shell")   
set oTxt = TxtDatei.OpenTextFile("C:\temp\" & AbfragePc & ".txt" , 8 , true)  

set wmi_object = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _  
	AbfragePc & "\root\default:StdRegProv")  


wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_version_key, strValue	
if strValue = "Windows 7 Ultimate" then  
	wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_w7ulti_path, ma_pkey, strValue
	oTxt.WriteLine "Programm:  " & strValue  
	wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_w7ulti_path, ma_w7_vkey, strValue
	oTxt.WriteLine "Produktversion:  " & strValue  
	wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_version_key, strValue
	oTxt.WriteLine "Windowsversion -64Bit:  " & strValue  
	wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_sp_key, strValue
	oTxt.WriteLine "ServicePack:   " & strValue  
		else
			if strValue = "Microsoft Windows XP" then  
				wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_path, ma_pkey, strValue
				oTxt.WriteLine "Programm:  " & strValue  
				wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_path, ma_v_xp_key, strValue
				oTxt.WriteLine "Produktversion:  " & strValue  
				wmi_object.GetStringValue HKEY_LOCAL_MACHINE, xp_path, xp_key, strValue
				oTxt.WriteLine "Windowsversion:  " & strValue  
				wmi_object.GetStringValue HKEY_LOCAL_MACHINE, xp_sp_path, win_sp_key, strValue
				oTxt.WriteLine "ServicePack:  " & strValue  
				else
					if	strValue = "Windows 7 Professional" then  
						wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_w7ulti_path, ma_pkey, strValue
						oTxt.WriteLine "Programm:  " & strValue  
						wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_w7ulti_path, ma_w7_vkey, strValue
						oTxt.WriteLine "Produktversion:  " & strValue  
						wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_version_key, strValue
						oTxt.WriteLine "Windowsversion -64Bit:  " & strValue  
						wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_sp_key, strValue
						oTxt.WriteLine "ServicePack:   " & strValue  
					
						else
							if strValue = "Windows 7 Home Basic" then  
								on error resume next
									wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_sp_key, strValue
							if err.Number = 0 then
								wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_path, ma_pkey, strValue
								oTxt.WriteLine "Programm:  " & strValue  
								wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_path, ma_w7_vkey, strValue
								oTxt.WriteLine "Produktversion:  " & strValue  
								wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_version_key, strValue
								oTxt.WriteLine "Windowsversion -32Bit:  " & strValue  
								wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_sp_key, strValue
								oTxt.WriteLine "ServicePack:   " & strValue  
								else
									wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_path, ma_pkey, strValue
									oTxt.WriteLine "Programm:  " & strValue  
									wmi_object.GetStringValue HKEY_LOCAL_MACHINE, ma_path, ma_w7_vkey, strValue
									oTxt.WriteLine "Produktversion:  " & strValue  
									wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_version_key, strValue
									oTxt.WriteLine "Windowsversion -32Bit:  " & strValue  
									wmi_object.GetStringValue HKEY_LOCAL_MACHINE, win_version_path, win_sp_key, strValue
									oTxt.WriteLine "Kein ServicePack vorhanden!"  
									err.Clear
							end if
							else
								MsgBox "Error"  
							end if
						end if
			end if	
end if

Content-Key: 191127

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

Printed on: April 25, 2024 at 00:04 o'clock

Member: bastla
bastla Sep 12, 2012 updated at 15:58:53 (UTC)
Goto Top
Hallo degNLB und willkommen im Forum!
Mein Problem welches ich momentan habe ist, dass ich die Daten gerne in eine Excel-Tabelle hätte
Ändere einfach die Zeile 27 auf
set oTxt = TxtDatei.OpenTextFile("C:\temp\" & AbfragePc & ".csv" , 8 , true)
und die Ausgabezeilen wie etwa Zeile 36 auf
oTxt.WriteLine "Programm:;" & strValue
Grüße
bastla
Member: degNLB
degNLB Sep 13, 2012 updated at 05:26:55 (UTC)
Goto Top
ok... dass die Lösung so einfach ist, ist ja fast peinlich nach 2 Tagen suche und probieren...

Vielen Dank bastla, Du hast mir sehr geholfen.!