36807

Vbs RegEx gesucht

Hallo,

ich möchte für die weitere Verarbeitung der Daten einen Regulären Audruck unter vbs definieren.

Konkret möchte ich aus der Pfadangabe (z.B. C:\Programme\ordner\programm.exe ) den Pfad C:\Programme\ordner und den Namen der .exe Datei in Separaten Variablen zwischenspeichern. Nur leider finde ich keine passende Möglichkeit das herauszufiltern bzw. bin ich mir nicht mal sicher ob das mit vbs überhaupt realisierbar ist ?

Hintergrund der ganzen Aktion ist, dass ich anhand der laufenden Tasks die Versionsnummer vom Programm herausfinden möchte. Leider gibt es in win32_process keine Klasse mit der ich das bewerkstelligen kann. Also habe ich mir gedacht, dass ich über den win32_process ... ExecutablePath die Shell.Application ... GetDetailsOf auslese. Diese benötigt afaik aber separat den exe Namen und den Pfad.

strComputer = "."  
Set dienst = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")'  
Set abfrage = dienst.ExecQuery("Select * from Win32_Process")  

' print usable information into XML-like format   
For Each prozess In abfrage
	eigenschaften = prozess.GetOwner(strNameOfUser, strUserDomain)
	WScript.Echo "<SOFTWARES>"   
	WScript.Echo "<PUBLISHER>"& prozess.Name &"</PUBLISHER>"  
	WScript.Echo "<NAME>"& prozess.caption &"</NAME>"  
	WScript.Echo "<VERSION>N/A</VERSION>"  
	WScript.Echo "<FOLDER>" & prozess.ExecutablePath &"</FOLDER>"   
	WScript.Echo "<COMMENTS>" & "# " & prozess.CommandLine &" #" &"</COMMENTS>"  
	WScript.Echo "<FILENAME>N/A</FILENAME>"  
	WScript.Echo "<FILESIZE>N/A</FILESIZE>"  
	WScript.Echo "<SOURCE>N/A</SOURCE>"  
	WScript.Echo "<GUID>N/A</GUID>"  
	WScript.Echo "<LANGUAGE>N/A</LANGUAGE>"  
	WScript.Echo "</SOFTWARES>"  
Next
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 153348

Url: https://administrator.de/forum/vbs-regex-gesucht-153348.html

Ausgedruckt am: 08.05.2025 um 20:05 Uhr

76109
76109 19.10.2010 um 12:40:17 Uhr
Goto Top
Hallo gummistiefel!

Das geht auch per FileSystemObject. Beispiel mit 7zip.Exe
Const Path = "C:\Program Files (x86)\7-Zip\7z.exe"  

Dim Fso, File
Dim FileBaseName, FileExtensionName, FileName, FileFolder
Dim FileVersion, FileCreated, FileSize, FileType
    
Set Fso = CreateObject("Scripting.FileSystemObject")  
    
Set File = Fso.GetFile(Path)
    
FileBaseName = Fso.GetBaseName(Path)            '= "7z"  
FileExtensionName = Fso.GetExtensionName(Path)  '= "exe"  
FileName = Fso.GetFileName(Path)                '= "7z.exe"  
FileFolder = Fso.GetParentFolderName(Path)      '= "C:\Program Files (x86)\7-Zip"  
FileVersion = Fso.GetFileVersion(Path)          '= "9.10.0.0"  
FileCreated = File.DateCreated                  '= #22.12.2009 14:17:38#  
FileSize = File.Size                            '= 280064  
FileType = File.Type                            '= "Anwendung"  

Gruß Dieter
36807
36807 19.10.2010 um 14:47:31 Uhr
Goto Top
Hallo Dieter,

danke für die schnelle und kompetente Antwort. Das FileSystemObject war genau das wonach ich gesucht habe.
Leider bekomme ich es nicht hin, dass ich in Const Path die prozess.ExecutablePath einfügen kann. Für den geübten Scripter mag das sicherlicht kein Problem darstellen nur ich komme nur sehr unregelmäßig in den "Genuss" von VBS.
76109
76109 19.10.2010 um 15:24:58 Uhr
Goto Top
Hallo gummistiefel!

Lösche die Codezeile mit der Konstanten "Const Path = ...." und dann in etwa so:
'.....  
Set Fso = CreateObject("Scripting.FileSystemObject")  

'print usable information into XML-like format  
For Each prozess In abfrage
    Set File = Fso.GetFile(prozess.ExecutablePath)
    
   'FileBaseName = Fso.GetBaseName(File.Path)  
   'FileExtensionName = Fso.GetExtensionName(File.Path)  
   'FileName =  File.Name   
   'FileFolder = File.ParentFolder.Path     
   'FileVersion = Fso.GetFileVersion(File.Path)  
   'FileCreated = File.DateCreated  
   'FileSize = File.Size  
   'FileType = File.Type  

   '.....  
    WScript.Echo "<VERSION>" & Fso.GetFileVersion(File.Path) & "</VERSION>"  
    WScript.Echo "<FOLDER>" & File.ParentFolder.Path & "</FOLDER>"  
    WScript.Echo "<COMMENTS>" & "# " & prozess.CommandLine & " #" & "</COMMENTS>"  
    WScript.Echo "<FILENAME>" & File.Name & "</FILENAME>"  
    WScript.Echo "<FILESIZE>" & File.Size & "</FILESIZE>"  
   '.....  
Next

Gruß Dieter
36807
36807 19.10.2010 um 17:15:38 Uhr
Goto Top
Problem gelöst face-smile


strComputer = "."      'The . means own computer  
Set dienst = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")'  
Set abfrage = dienst.ExecQuery("Select * from Win32_Process",,48)  

' print usable information into XML-like format  


For i = 1 To 1
	For Each prozess In abfrage
		If Not prozess.ExecutablePath = "" Then              

		Path = prozess.ExecutablePath
	 	Path = "" & Path & ""  
	
		Set fso = CreateObject("scripting.filesystemobject")  
		Path =  fso.GetFileVersion (Path)
	
		WScript.Echo "<SOFTWARES>"   
		WScript.Echo "<PUBLISHER>"& prozess.Name &"</PUBLISHER>"  
		WScript.Echo "<NAME>"& prozess.caption &"</NAME>"  
		WScript.Echo "<VERSION>"& Path & "</VERSION>"  
		WScript.Echo "<FOLDER>N/A</FOLDER>"  
		WScript.Echo "<COMMENTS>" & "# " & prozess.CommandLine &" #" &"</COMMENTS>"  
		WScript.Echo "<FILENAME>N/A</FILENAME>"  
		WScript.Echo "<FILESIZE>N/A</FILESIZE>"  
		WScript.Echo "<SOURCE>N/A</SOURCE>"  
		WScript.Echo "<GUID>N/A</GUID>"  
		WScript.Echo "<LANGUAGE>N/A</LANGUAGE>"  
		WScript.Echo "</SOFTWARES>"  
		End If
	Next
Next