pixelschubser
Goto Top

Übergabe von Parametern mit VBScript

Übergabe eines Parameters im minimierten Fenstern

Gestern wollte ich mit Hilfe eines Scripts Schriften installieren. Das Hauptproblem bestand darin, dass unter Windows 7 dazu Administrationsrechte benötigt werden.

Um dieses Problem zu umgehen erstellte ich eine GPO in der das VBScript ausgeführt und ein Parameter mitgegeben wurde, in dem das Adminkenntwort stand. Nun erstellte ich ein VBScript das erstmal überprüft, ob alle Schriften bereits installiert sind. Wenn nein, wurde eine zweites Script aufgerufen, dem das Passwort mitgeben wird.

Script 1:

Option explicit

' Variablendelekration  
dim oFSO, oShell, oApp, oFolderCopy, oArgs, sParameter, oFont, Bool, strFontsPath, strScriptPath

' Neue Objekte erstellen  
set oFSO = CreateObject("Scripting.FileSystemObject")   
set oShell = CreateObject("WScript.Shell")   
set oApp = CreateObject("Shell.Application")   
set oArgs = WScript.Arguments

' Variablendefinition  
Bool = false

' Pfad zu den Font-Ordner  
strFontsPath = oShell.ExpandEnvironmentStrings("%WINDIR%") & "\Fonts"   
set oFolderCopy = oApp.Namespace("\\WINSRV1\Freigabe\Fonts")   

' Überprüft ob die Schriftart bereits installiert ist  
For Each oFont In oFolderCopy.Items 

  If NOT oFSO.FileExists(strFontsPath & "\" & oFont.Name & ".TTF") Then  
    If NOT oFSO.FileExists(strFontsPath & "\" & oFont.Name & ".OTF") Then    
      Bool = true    
    End If
  End If 

Next 

If Bool = true then  
  for each sParameter in oArgs
    set oShell = Wscript.CreateObject("WScript.Shell")  
    oShell.Run "runas /user:Benutzername@domain.de ""cscript.exe \\WINSRV1\Freigabe\font.vbs"  
  
    WScript.Sleep 1000
    oShell.Sendkeys sParameter + "~"  
  next
End if

' Leert die Objekte  
Set oFolderCopy = Nothing 
Set oApp = Nothing 
Set oShell = Nothing
set oFSO = Nothing

Wscript.Quit

Script 2:

on error resume next 
  Dim oFSO, oApp, oFolderCopy, oShell 
  Dim strFontsPath, strScriptPath 

  ' Neue Objekte erstellen  
  Set oFSO = CreateObject("Scripting.FileSystemObject")   
  Set oShell = CreateObject("WScript.Shell")   
  Set oApp = CreateObject("Shell.Application")   

  ' Pfad zu diesem Script   
  strScriptPath = WScript.ScriptFullName 
  strScriptPath = left(strScriptPath,instrrev(strScriptPath,"\\WINSRV1\Freigabe"))   

  ' Pfad zum Font-Ordner  
  strFontsPath = oShell.ExpandEnvironmentStrings("%WINDIR%") & "\Fonts"   
  
  Set oFolderCopy = oApp.Namespace("\\WINSRV1\Freigabe\Fonts")   

  ' Überprüft ob die Schriftart bereits installiert ist  
  For Each oFont In oFolderCopy.Items 
    If NOT oFSO.FileExists(strFontsPath & "\" & oFont.Name & ".TTF") Then  
      If NOT oFSO.FileExists(strFontsPath & "\" & oFont.Name & ".OTF") Then    
        WScript.Echo oFont
        oApp.Namespace(strFontsPath).CopyHere oFont 
      End If
    End If 
  Next 

' Leert die Variablen  
Set oFolderCopy = Nothing 
Set oApp = Nothing 
Set oShell = Nothing

Das Ganze funktioniert auch soweit. Eine Sache ist jedoch sehr unschön. Wenn sich nun ein Benutzer anmeldet, sieht er auf jeden Fall das erste Fenster, und wenn das zweite Script auch ausgeführt wird logischerweiße auch das zweite Fenster. Nun hab ich gelesen, dass man die Fenster auch minimiert ausführen lassen kann. Das würde dann so ausschauen:

oShell.Run "runas /user:Benutzername@domain.de ""cscript.exe \\WINSRV1\Freigabe\font.vbs", 7  

Nun habe ich nur das Problem, dass das Passwort nicht mehr zu Script zwei übergeben wird. Kann mir jemand weiterhelfen?

Content-Key: 140587

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

Printed on: April 19, 2024 at 13:04 o'clock

Member: Logan000
Logan000 Apr 14, 2010 at 09:45:03 (UTC)
Goto Top
Moin Moin

Wenn Du das 1. Skript schon via GPO ausführst, dann mach das doch unter Computerkonfiguration beim Starten.
Dann solten eigentlich alle Rechte vorhanden sein und eine Kennwort übergabe nicht mehr notwendig.

Gruß L.
Member: Pixelschubser
Pixelschubser Apr 14, 2010 at 10:13:01 (UTC)
Goto Top
Ohja.. gute Idee versuch ich gleich mal aus.. Vielen Dank