=====Determine OS version===== '========================================================================== ' ' NAME: DetectOS.vbs ' ' AUTHOR: DiGiTAL.SkReAM ' DATE : 10/26/2005 ' ' COMMENT: Populates the sOS string variable with the name of the current OS ' '========================================================================== Option Explicit Dim oShell Dim oShellExec, oStdOutputText, sText, iElement, aOS, sOS Set oShell = CreateObject("Wscript.Shell") Set oShellExec = oShell.Exec("%comspec% /c ver") Set oStdOutputText = oShellExec.StdOut Do While Not oStdOutputText.AtEndOfStream sText = oStdOutputText.ReadLine aOS = Array("Windows 95", "Windows 98", "Windows NT", "Windows 2000", "Windows XP", "Microsoft Windows [Version") For iElement = LBound(aOS) To UBound(aOS) If InStr(sText, aOS(iElement)) <> 0 Then If aOS(iElement) = "Microsoft Windows [Version" Then sOS = "Windows 2003" Else sOS = aOS(iElement) End If End If Next Loop WScript.Echo sOS Source:[[http://www.visualbasicscript.com/m28386.aspx|VisualBasicScript.com - Short, Easy way to determine OS]] \\ Or: Set objShell=WScript.CreateObject("WScript.Shell") WScript.Echo "The current operating system is: " & oShell.RegRead "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProductName") Set objShell = Nothing Source:[[http://www.pctools.com/forum/archive/index.php/t-18016.html|PC Tools Community Forum > Windows Programming Discussions > Windows Scripting Questions > Logon Script to determine OS?]] \\ =====Pingen vanuit VBScript===== Zie:[[http://www.robvanderwoude.com/vbstech_network_ping.php|Rob van der Woude's Scripting Pages - Ping Computers]] voor een voorbeeld met WMI voor Windows XP en hoger en een voorbeeld met de [[http://www.netal.com/ssr.htm|System Scripting Runtime]]. Een andere optie is: Function PingStatus(strComputer) PingStatus = "Failed" Set objShell = CreateObject("WScript.Shell") Set objWshScriptExec = objShell.Exec("%comspec% /c ping -n 3 -w 1000 " & strComputer) Set objStdOut = objWshScriptExec.StdOut Do Until objStdOut.AtEndOfStream strLine = objStdOut.ReadLine If InStr(strLine, "Reply") > 0 OR InStr(strLine, "Antwoord") > 0 Then PingStatus = "Success" End If Loop Set objStdOut = Nothing Set objWshScriptExec = Nothing Set objShell = Nothing End Function Gebaseerd op code van [[http://www.microsoft.com/technet/scriptcenter/resources/qanda/sept04/hey0914.mspx|Hey, Scripting Guy! - Why Doesn't My Ping Script Run on Windows 2000 Computers?]]. \\ =====Shortcut maken/bewerken===== Gebruik hiervoor: Set objShortcut = wshShell.CreateShortcut(strTargetPath) Vervolgens kun je een aantal properties opvragen/zetten: objShortcut.FullName objShortcut.Arguments objShortcut.WorkingDirectory objShortcut.TargetPath objShortcut.IconLocation objShortcut.Hotkey objShortcut.WindowStyle objShortcut.Description En afsluiten met een objShortcut.Save als wilt opslaan. \\ Bron:[[http://www.robvanderwoude.com/vbstech_shortcuts.php|Rob van der Woude's Scripting Pages - Shortcuts]] "The *Undocumented* Trick: use the ".CreateShortcut" method without the ".Save" method; works like a GetShortcut when the shortcut already exists!" Zie ook: \\ [[http://msdn.microsoft.com/en-us/library/xsy6k3ys(VS.85).aspx|MSDN Library - CreateShortcut Method]] \\ [[http://msdn.microsoft.com/en-us/library/f5y78918(VS.85).aspx|MSDN Library - WshShortcut Object Properties and Methods]] \\ [[http://msdn.microsoft.com/en-us/library/265a4017(VS.85).aspx|MSDN Library - WshUrlShortcut Object]] \\ =====Tellen van bepaald karakter in string===== If UBound(Split(strFolder, "\")) < 5 Then End If Gegapt van: [[http://www.computing.net/howtos/show/how-to-use-vbscript-for-string-count/173.html|Computing.net - How to use VBScript for String Count]] \\ =====Create AT job on remote computer===== Const bRunRepeatedly = True strComputer = "remotecomputername" Set objWMI = objLocator.ConnectServer ( strComputer, "\root\cimv2", strComputer & "\Administrator", "password" ) objWMI.Security_.impersonationlevel = 3 Set objSchedTask = objWMI.Get("Win32_ScheduledJob") Set colSchedTask = objWMI.ExecQuery("SELECT * FROM Win32_ScheduledJob") 'Delete extisting AT jobs with the same command to prevent creating the same job multiple times. For Each objTask in colSchedTask If objTask.Command = chr(34) & "C:\Program Files\Update\update.vbs" & chr(34) Then Set objInstance = objWMI.Get("Win32_ScheduledJob.JobID=" & objTask.JobID) objInstance.Delete Set objInstance = Nothing End If Next intResultSchedTask1 = objSchedTask.Create (chr(34) & "C:\Program Files\Update\update.vbs" & chr(34), "********150000.000000+060", bRunRepeatedly, 127) intResultSchedTask2 = objSchedTask.Create (chr(34) & "C:\Program Files\Update\update.vbs" & chr(34), "********170000.000000+060", bRunRepeatedly, 127) intResultSchedTask3 = objSchedTask.Create (chr(34) & "C:\Program Files\Update\update.vbs" & chr(34), "********210000.000000+060", bRunRepeatedly, 127) If intResultSchedTask1 = 0 AND intResultSchedTask2 = 0 AND intResultSchedTask3 = 0 Then AddTask = "Success" Else AddTask = "Failed" End If Set colSchedTask = Nothing Set objSchedTask = Nothing Set objWMI = Nothing =====Remote registry edit===== 'SetTightVNCAsk: configures TightVNC to ask the user if the remote connection is allowed where the remote connection is made from any IP address. Function SetTightVNCAsk(strComputer) SetTightVNCAsk = "Failed" Const HKEY_LOCAL_MACHINE = &H80000002 Set objWMIService = objLocator.ConnectServer ( strComputer, "\root\default", strComputer & "\" & strAcc, strPassword ) objWMIService.Security_.impersonationlevel = 3 'Line below taken from example in http://msdn.microsoft.com/en-us/library/aa393067(VS.85).aspx - Requesting WMI Data on a 64-bit Platform Set objReg = objWMIService.Get("StdRegProv") 'Code from http://msdn.microsoft.com/en-us/library/aa393600(VS.85).aspx - SetStringValue Method of the StdRegProv Class strKeyPath = "SOFTWARE\TightVNC\Server" strValueName = "IpAccessControl" strValue = "0.0.0.0-255.255.255.255:2" ' write string value to key intResult = objReg.SetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue) If intResult = 0 Then SetTightVNCAsk = "Success" Else SetTightVNCAsk = "Failed" End If Set objReg = Nothing Set objWMIService = Nothing End Function =====Check if specific Windows Update is installed===== Set objSession = CreateObject("Microsoft.Update.Session") Set objSearcher = objSession.CreateUpdateSearcher intHistoryCount = objSearcher.GetTotalHistoryCount Set colHistory = objSearcher.QueryHistory(0, intHistoryCount) strStatus = "empty" For Each objEntry in colHistory 'Operation '1 = Installation '2 = Uninstallation 'ResultCode '0 = not started. '1 = in progress. '2 = completed successfully. '3 = completed, but one or more errors occurred." '4 = failed to complete '5 = aborted If InStr(objEntry.Title, "KB958830") > 0 And objEntry.Operation = 1 And objEntry.ResultCode = 2 Then strStatus = "Found" End If Next If strStatus = "Found" Then WScript.Echo "Found update KB958830." Else WScript.Echo "Did not find KB958830." End If Set colHistory = Nothing Set objSearcher = Nothing Set objSession = Nothing Based on code from:[[http://technet.microsoft.com/en-us/library/ee692834.aspx|Microsoft TechNet - Tales from the Script - July 2005]] see also [[http://msdn.microsoft.com/en-us/library/aa387099(VS.85).aspx|msdn - Windows Update Agent API]] \\