====== Verwante Seiten ======
* [[infos:windows]]
* [[infos:windows:cmd]] <- Windows Komandozeile
* [[infos:linux]]
* [[infos:linux:bash]] <- Linux Shell + Komandozeile
====== Beispiel Skripts ======
===== MSG-Box =====
Option Explicit
'Init der Variabel
Dim WshShell
Dim befehl
'Erzeugung des Shell Objekts
Set WshShell = WScript.CreateObject("WScript.Shell")
msgbox "Herzlich Willkommen"
befehl = Chr(34) & "Um diese verkettete Zeichenfolge hat es Anführungszeichen" & Chr(34)
MsgBox befehl
===== (Auto-)Start von Programmen =====
Für den Autostart, einen Link im [ Startmenu ] unter '''Alle Programme''' -> '''Autostart''' anlegen, welcher auf das Skript zeigt.
Sonst, kann man auch einfach das Skript per doppelklick.
**Hinweis: ** Es können zwei Arten von Befehlen verarbeitet werden:
- Das mit den drei Anführungszeichen: Es ist ein apsoluter Pfad im System **mit Leerzeichen**. Diese Methode ist auch zu empfehlen, wenn keine Leerzeichen vorhanden sind.
- Windows Programme: Das sind Programme wie '''calc''' oder outlook, welche sich mit dem Namen rufen lassen.
- Programme im gleichen Verzeichnis: Das ist relativ heikel, da man nich immer ganz genau weiss, wo das Skript gerade Ausgeführt wird.
Option Explicit
Dim WshShell
'Erzeugung des Shell Objekts
Set WshShell = WScript.CreateObject("WScript.Shell")
'Set WshShell = CreateObject("WScript.Shell")
'Die Verzögerung in Millisekunden
WScript.Sleep 10000
'Die Befehle
'Variante 1:
WshShell.Run """C:\Program Files\Mein eigenes Programm\alert.exe""",1
WScript.Sleep 15000
'Variante 2:
WshShell.Run "calc",0
WScript.Sleep 1000
'Variante 3:
WshShell.Run "meinprogramm.exe",0
WScript.Sleep 1000
===== Internet Explorer steuern =====
option explicit
Dim ie, ausgabe, count
'ie starten
Set ie=CreateObject("InternetExplorer.Application")
'ie anzeigen
ie.visible = True
'Auf leerem Fenster anhalten
ie.navigate("about:blank")
'Info an den Benutzer
MsgBox "Das Skript läuft jetzt im Hintergrund und zählt auf 100"
'ausgabe
ausgabe = "Ausgabe im ie:
"
ie.Document.body.innerHTML = ausgabe
For count = 0 To 100 Step 1
ie.Document.body.innerHTML = ausgabe & "Zähler = " & count
WScript.Sleep 500
Next
MsgBox "ie wird jetzt beendet"
ie.quit
===== Netzwerklaufwerk erstellen, einbinden und einen Drucker hinzufügen =====
Dieser Code wurde zum Teil von hier ([[http://msdn.microsoft.com/en-us/library/h976cd1t(VS.85).aspx|MSDN]]) kopiert.
' Remote WSH Admin Sample AdminScript.vbs
'
' This sample code does a few common administrative tasks which a
' network administrator might want to do to a number of the machines
' on his or her network: it creates a public directory, populates
' it with some files and shares the directory out. It also sets
' up the machines default printer connection.
' Note that in the interests of keeping this example code small, error
' handling has been omitted. Actual production code should use
' appropriate error handling as many of these operations could fail;
' the disks could run out of space, for instance.
Option Explicit
Dim FSO
Dim Services
Dim SecDescClass
Dim SecDesc
Dim Trustee
Dim ACE
Dim Share
Dim InParam
Dim Network
Const FolderName = "C:\Public"
Const AdminServer = "\\AdminMachine"
Const ShareName = "Pubs"
Const PrinterShare = "\\CorpPrinters\PrinterShare"
' First we add a printer to this machine and make it the default.
Set Network = CreateObject("Wscript.Network")
Network.AddWindowsPrinterConnection PrinterShare
Network.SetDefaultPrinter PrinterShare
' Next we create a folder and populate it with some files.
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(FolderName) Then
FSO.CreateFolder(FolderName)
End If
Call FSO.CopyFile(AdminServer & "\Public\Images\*.*", FolderName)
' Make the folder into a share using WMI
' See the WMI SDK for information on how this code works.
Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!" & AdminServer & "\ROOT\CIMV2")
Set SecDescClass = Services.Get("Win32_SecurityDescriptor")
Set SecDesc = SecDescClass.SpawnInstance_()
Set Trustee = Services.Get("Win32_Trustee").SpawnInstance_
Trustee.Domain = Null
Trustee.Name = "EVERYONE"
Trustee.Properties_.Item("SID") = Array(1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
Set ACE = Services.Get("Win32_Ace").SpawnInstance_
ACE.Properties_.Item("AccessMask") = 2032127
ACE.Properties_.Item("AceFlags") = 3
ACE.Properties_.Item("AceType") = 0
ACE.Properties_.Item("Trustee") = Trustee
SecDesc.Properties_.Item("DACL") = Array(ACE)
Set Share = Services.Get("Win32_Share")
Set InParam = Share.Methods_("Create").InParameters.SpawnInstance_()
InParam.Properties_.Item("Access") = SecDesc
InParam.Properties_.Item("Description") = "Public Share"
InParam.Properties_.Item("Name") = ShareName
InParam.Properties_.Item("Path") = FolderName
InParam.Properties_.Item("Type") = 0
Share.ExecMethod_("Create", InParam)
' Mount the share at Z:
Network.RemoveNetworkDrive ("Z:",true,true);
Network.MapNetworkDrive ("Z:", "\\\\localhost\\" & ShareName, false,"USER","USER's-PW");
' And we're done.
===== Endlosschleife =====
Option Explicit
Dim WshShell
Dim endless
endless = 0
'Erzeugung des Shell Objekts
set WshShell = WScript.CreateObject("WScript.Shell")
Do While endless = 0
WshShell.Run "shutdown -a",0
WScript.Sleep 100
Loop
===== Links erstellen =====
'Create the shortcut for Notepad in the SendTo Folder
on error resume next
Dim SendToPath
Dim Shortcut
Dim WholePath
Set WshShell = WScript.CreateObject("WScript.Shell")
Set fs = WScript.CreateObject ("Scripting.FileSystemObject")
SendToPath = WshShell.SpecialFolders ("SendTo")
Set Shortcut = WshShell.CreateShortcut (fs.BuildPath (SendToPath, "\Notepad.lnk"))
Shortcut.TargetPath = "%windir%\system32\notepad.exe"
Shortcut.Save 'Create the shortcut