KjellTrygve.com

‘ Created 20080929 – Inge Brattaas (inge@Netpower.no) ‘Option Explicit ‘On Error Resume Next ‘ init Dim ShowErrors, QuoteChr ShowErrors = CBool(True) ‘ Show messages if errors occur? QuoteChr = Chr(34) Dim FileSysObj, WshShell, AdSysInfo, UserObj, sTHaddress, sTOaddress, sTOTaddress, sTVaddress, sTMNaddress,…

‘Option Explicit On Error Resume Next ‘ init Dim ShowErrors, QuoteChr ShowErrors = CBool(True) ‘ Show messages if errors occur? QuoteChr = Chr(34) Dim FileSysObj, WshShell, AdSysInfo, UserObj, sTHaddress, sTOaddress, sTOTaddress, sTVaddress, sTMNaddress, strUserName, strUserDomain, objGroupDict, objNetwork Set FileSysObj =…

Shortcut to desktop

On Error Resume Next Dim objNetwork, _ objShell, _ objFSO, _ objGroupDict, _ objUser, _ objGroup, _ strUsrName, _ strUserName, _ strUserDomain, _ strUserProfile Set objNetwork = WScript.CreateObject(«WScript.Network») Set objShell = WScript.CreateObject(«Wscript.shell») Set objFSO = CreateObject(«Scripting.FileSystemObject») strUserProfile = objShell.Environment(«PROCESS»)(«UserProfile») strUserName…

Grouplist.csv

Lonn,T:,\\server\lonn$ Huldt_Lillevik,P:,\\srv02\HuldtLillevik$ Data_Access,F:,\\server\data$ Projects_Group,S:,\\file01\Projects$ C352_2ETG,!!,\\server\C352_2ETG CM2320MFP,!!,\\server\CM2320MFP Bizhub_Lager,!!,\\server\Bizhub_Lager

VBS Logon with Grouplist.csv

‘—————————————————- ‘Remove all Network printers but not local printers Set WshNetwork = WScript.CreateObject(«WScript.Network») Set Printers = WshNetwork.EnumPrinterConnections For i = 0 to Printers.Count – 1 Step 2 If Left(ucase(Printers.Item(i+1)),2) = «\\» Then ‘WScript.Echo Printers.Item(i+1) ‘WSHNetwork.RemovePrinterConnection Printers.Item(i+1) End IF Next On…

ChangeDriveLabels.vbs

mDrive = «f:\» Set oShell = CreateObject(«Shell.Application») oShell.NameSpace(mDrive).Self.Name = «Felles» mDrive = «k:\» Set oShell = CreateObject(«Shell.Application») oShell.NameSpace(mDrive).Self.Name = «Administrasjon» mDrive = «t:\» Set oShell = CreateObject(«Shell.Application») oShell.NameSpace(mDrive).Self.Name = «Trafikk» mDrive = «r:\» Set oShell = CreateObject(«Shell.Application») oShell.NameSpace(mDrive).Self.Name = «Verksted»…

DecToBin

‘ Example ‘ Wscript.Echo DecToBin(27) Function DecToBin(ByVal d) If Not IsNumeric(d) Then Exit Function Dim st st = «» Do While d > 0 If d Mod 2 > 0 Then st = «1» & st Else st = «0»…

ConvertFileSize

Function ConvertFileSize(integerSize) If integerSize >= 1000000000 Then ConvertFileSize = round(integerSize / 1000000000, 2) ConvertFileSize = ConvertFileSize & » GB» ElseIf ((1000000000 > integerSize) And (integerSize >= 1000000)) Then ConvertFileSize = round(integerSize / 1000000, 2) ConvertFileSize = ConvertFileSize & » MB»…

Function GetAllTwoLetterCombinations() Dim charArr, charArr2, strOut charArr = Array(«a»,»b»,»c»,»d»,»e»,»f»,»g»,»h»,»i»,»j»,»k»,»l»,»m»,»n»,»o»,»p»,»q»,»r»,»s»,»t»,»u»,»v»,»w»,»x»,»y»,»z») charArr2 = Array(«a»,»b»,»c»,»d»,»e»,»f»,»g»,»h»,»i»,»j»,»k»,»l»,»m»,»n»,»o»,»p»,»q»,»r»,»s»,»t»,»u»,»v»,»w»,»x»,»y»,»z») Dim i, j For Each i In charArr For Each j in charArr2 strOut = strOut & i & j & vbCrLf Next Next GetAllTwoLetterCombinations = strOut End…

Copy to Delete From.vbs

Dim objFSO Dim objShell Dim strUserProfile Set objFSO = CreateObject(«Scripting.FileSystemObject») Set objShell = WScript.CreateObject(«Wscript.shell») strUserProfile = objShell.Environment(«PROCESS»)(«UserProfile») ‘Copy to and delete from DESKTOP CopyToDesktop(«\\thsrv06\economyterminalserver$\Shortcuts\Desktop\BankX.lnk») MsgBox(«Fil er kopiert til skrivebord, trykk OK for å slette filen») DeleteFromDesktop(«BankX.lnk») ‘Copy to and delete…

RegWrite

Dim WshShell Set WshShell = WScript.CreateObject(«WScript.Shell») ‘ http://msdn.microsoft.com/en-us/library/yfdfhz1b%28VS.85%29.aspx ‘ example: WshShell.RegWrite «HKCU\Software\ACME\FortuneTeller\MindReader», «Goocher!», «REG_SZ» WshShell.RegWrite

Const ForReading = 1 Dim objFSO Set objFSO = CreateObject(«Scripting.FileSystemObject») Set objTextFile = objFSO.OpenTextFile _ («d:\My Dropbox\Archive\Netpower\Certificates\temp.txt», ForReading) Do Until objTextFile.AtEndOfStream strNextLine = objTextFile.Readline arrLine = Split(strNextLine , «;») Wscript.Echo « » & vbCrLf & vbTab & « » &…

DeleteSelf

‘ Example ‘ MsgBox «Before the self delete», vbInformation, «Self Deleting Script» ‘ Call DeleteSelf() ‘ MsgBox «After the self delete», vbInformation, «Self Deleting Script» Sub DeleteSelf() Dim objFSO Set objFSO = CreateObject(«Scripting.FileSystemObject») objFSO.DeleteFile WScript.ScriptFullName Set objFSO = Nothing End…

Create Shortcut

Dim WshShell, strDesktop, oShellLink Set WshShell = WScript.CreateObject(«WScript.Shell») strDesktop = WshShell.SpecialFolders(«Desktop») set oShellLink = WshShell.CreateShortcut(strDesktop & «\Shortcut To Notepad.lnk») oShellLink.TargetPath = «Notepad.exe» oShellLink.WindowStyle = 1 oShellLink.Hotkey = «CTRL+SHIFT+N» oShellLink.IconLocation = «notepad.exe, 0» oShellLink.Description = «Shortcut To Notepad.» oShellLink.WorkingDirectory = strDesktop…

CreateURL

‘ Example ‘ CreateUrl «d:\Microsoft.url», «http://www.microsoft.com» Sub CreateUrl(pathToFile, urlAdress) Dim WshShell, oUrlLink Set WshShell = WScript.CreateObject(«WScript.Shell») Set oUrlLink = WshShell.CreateShortcut(pathToFile) oUrlLink.TargetPath = urlAdress oUrlLink.Save End Sub

CopyFile

Sub CopyFile(SourceFile, DestinationFolder, Overwrite) ‘Copy File. Note that Copy File will fail if destination has the read-only attribute set, regardless of the value of overwrite. Dim objFSO Set objFSO = CreateObject(«Scripting.FileSystemObject») If objFSO.FileExists(SourceFile) Then If Right(DestinationFolder, 1) «\» Then DestinationFolder…

WriteToFile

Sub WriteToFile(Byval strFileName, ByVal strData, Byval bAppend) Dim objFSO, objTextStream Set objFSO = CreateObject(«Scripting.FileSystemObject») ‘ 1: Read, 2: Write, 8: Append If objFSO.FileExists(strFileName) And bAppend Then Set objTextStream = objFSO.OpenTextFile(strFileName, 8) objTextStream.Write vbcrlf & strData Else Set objTextStream = objFSO.CreateTextFile(strFileName,…

ReadFromFile

Function ReadFromFile(ByVal strFileName) Dim objFSO, objTextStream Set objFSO = CreateObject(«Scripting.FileSystemObject») If Not objFSO.FileExists(strFileName) Then ReadFromFile = «[FILE NOT FOUND]» Exit Function End If objTextStream = objFSO.GetFile(strFileName).OpenAsTextStream.ReadAll ReadFromFile = objTextStream End Function

DeleteFile

Function DeleteFile(Byval strFileName) Dim objFSO, objTextStream Set objFSO = CreateObject(«Scripting.FileSystemObject») If objFSO.FileExists(strFileName) Then objFSO.DeleteFile strFileName, True DeleteFile = True Else DeleteFile = False End If End Function

MSSQL SELECT query

‘< % Dim Output Dim cn, cmd, rs, cnstring, cmdtext cnstring = "Data Source=[[SQL server Ip/Host]];Initial Catalog=[[SQL database]];Provider=SQLOLEDB.1;User ID=[[SQL user]];Password=[[SQL password]];Persist Security Info=True;" cmdtext = "[[SELECT statement]]" Set cn = CreateObject("adodb.connection") Set cmd = CreateObject("adodb.command") cn.connectionstring = cnstring cn.Open cmd.activeconnection...

Base64Decode

‘ Decodes a base-64 encoded string (BSTR type). ‘ 1999 – 2004 Antonin Foller, http://www.motobit.com ‘ 1.01 – solves problem with Access And ‘Compare Database’ (InStr) Function Base64Decode(ByVal base64String) ‘rfc1521 ‘1999 Antonin Foller, Motobit Software, http://Motobit.cz Const Base64 = «ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/»…

ldapQuery

‘ Deactivated users (uncomment to run) ‘Wscript.Echo ldapQuery(«;(&(objectCategory=User)» & _ ‘ «(userAccountControl:1.2.840.113556.1.4.803:=2));Name,distinguishedName;Subtree», «;») ‘ Active users (uncomment to run) ‘Wscript.Echo ldapQuery(«;(&(objectCategory=User)» & _ ‘ «(!userAccountControl:1.2.840.113556.1.4.803:=2));Name,distinguishedName;Subtree», «;») Function ldapQuery(query, fieldseperator) ‘ ‘ Query against LDAP database, returns fields seperated by string…

QueryActiveDirectory

‘ Example ‘ QueryActiveDirectory «cn,createTimeStamp,description,displayName», «LDAP://domain.lan/OU=Users IKT,OU=Companies,DC=domain,DC=lan», «user» ‘ ‘ Tip: Create query with Active Directory Editor from SysInternals, optionally replace oCmd.CommandText in sub Sub QueryActiveDirectory(selectedProperties, LDAPpath, objectCategory) Dim propertynames, oCn, oCmd, oRS, i propertynames = Split(selectedProperties,»,») Set oCn =…

GetPwdInfo

Sub GetPwdInfo(Byval strLDAPPathOrAuto, Byval intDomainPwdMaxExpireDays) On Error Resume Next Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D Const ONE_HUNDRED_NANOSECOND = .000000100 Const SECONDS_IN_DAY = 86400 Set objADSystemInfo = CreateObject(«ADSystemInfo») If UCase(strLDAPPathOrAuto) = «AUTO» Then Set objUser= GetObject(«LDAP://» & objADSystemInfo.UserName) Else…

GetDomainMaxPwdAge

Function GetDomainMaxPwdAge(ByVal strLDAPPathOrAuto) Const ONE_HUNDRED_NANOSECOND = .000000100 ‘ .000000100 is equal to 10^-7 Const SECONDS_IN_DAY = 86400 Dim objADSystemInfo, objDomain, objMaxPwdAge, dblMaxPwdNano, dblMaxPwdSecs, dblMaxPwdDays Set objADSystemInfo = CreateObject(«ADSystemInfo») If UCase(strLDAPPathOrAuto) = «AUTO» Then Set objDomain = GetObject(«LDAP://» & objADSystemInfo.DomainDNSName) Else…

Reboot Computer

Sub RebootComputer(Force) ‘Reboots the computer. Dim oNet, objWMIService, colOperatingSystems, objOperatingSystem shutdownParam = 2 If Force Then shutdownParam = shutdownParam + 4 Set oNet = CreateObject(«WScript.Network») Set objWMIService = GetObject(«winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\» & oNet.ComputerName & «\root\cimv2») Set colOperatingSystems = objWMIService.ExecQuery(«Select * from Win32_OperatingSystem…

Template New Script

‘ ‘ [[Name of script]] ‘ —————————————————- ‘ [[Description]] ‘ ‘ Created [[Created date]] by [[Author]] ‘ Option Explicit ‘ On Error Resume Next ‘ ::: Global variables ::: ‘ ::: Global objects ::: Dim WshShell, objFSO, WshNetwork Set WshShell…

This site is protected by WP-CopyRightPro