Category Archives: VBS

Simple VBScript to restart all VMware services

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\”&strComputer&”\root\cimv2”)
Set colListOfServices = objWMIService.ExecQuery(“Select * from win32_Service where Name Like ‘VM%'”)
IntSleep = 15000
For Each objService in colListOfServices
If UCase(Left(objService.name, 1)) > “N” then
objService.StopService()
WScript.Sleep intSleep
objService.StartService()
strMsg = strMsg & vbCr & objService.name & ” Restarted.”
End If
Next

Wscript.Echo strMsg

Sure you can tweak and modify it as you see fit 🙂

Advertisements

Tip : Regex tester / builder.

And even the title is catchy 🙂

Trying to read all the regexp complexity behind a “Email” is a hard thing… Well thank god we have tooling 😀

http://www.ultrapico.com/Expresso.htm

When working with, C#, PHP, VB, OCS (SIP) and others this tool might be a blessing!

Hope it helps you too 😀

Compare File contence using VBScript.

Ever had the need to compare a file using VBS? You might wonder why you might need something like that? For instance. You have all your coperate templates on your network, but you want to upload these to your portable clients so they always have access to these templates. To keep these clients up-to-date you only want to upload these template each time a version file is changed on the network.

To do this you need to compare the contence of that file. Here is a script that will enable you to do just that.

Set Fso = WScript.CreateObject(“Scripting.FileSystemObject”)

CopyTemplates = “NotSet”
If Fso.FileExists(“C:\office\version.txt”) then
set objFile1 = Fso.opentextfile(“C:\AMIS-Huisstijl\office\versie.txt”,1)
Else
CopyTemplates = “True”
End If
If Fso.FileExists(“F:\office\version.txt”) then
set objFile2 = Fso.opentextfile(“F:\AMIS-Huisstijl\office\versie.txt”,1)
Else
CopyTemplates = “True”
End If
If CopyTemplates = “NotSet” Then
arrFile1 = split(objFile1.ReadAll,vbNewLine)
arrFile2 = split(objFile2.ReadAll,vbNewLine)
objFile1.close
objFile2.close
If ubound(arrFile1) ubound(arrFile2) then
intLineCount = ubound(arrFile2)
strError = strFile2 & ” is bigger than ” & strFile1
Else
intLineCount = ubound(arrFile2)
End if
for i = 0 to intLineCount
if not arrFile1(i) = arrFile2(i) then
exit for
end if
next
If i < (intLineCount + 1) then
CopyTemplates = “True”
Elseif strError “” then
CopyTemplates = “True”
Else
CopyTemplates = “False”
End If
WScript.Echo “Copy Templates = ” & CopyTemplates
End If