Sep 19

VBSCript write to Windows Event Log

So I wrote this article back in the day about logging to a text file.
And I was asked  if there is a way to use windows logging as well.

Short answer yes, long answer yes but it’s not amazing

Very simple code

Set objShell = CREATEOBJECT("WScript.Shell")

' Constants for type of event log entry

WriteToEventLog EL_Warning, "Testing My event log message..."

Sub WriteToEventLog(sLogEID,strELMessage)

objShell.LogEvent sLogEID, strELMessage

End Sub

As you can see above I added some values there are set for the Event ID in the event logs.
Certain Event ID’s will have different Icons and the only problem I see is that the source is WSH  and seems can’t be changed.

I’ll Upload some screen shots later on

Posted in Scripting | Tagged , , , | Leave a comment
Aug 09

Execute Something / Open Folder / Do Something after Reboot – Windows RunOnce

So… many times I have issue with services not closing out or locked files and other nitty gritty’s with Windows.
Here are a few simple solutions on working with Windows RunOnce

So for you who might be reading this and saying but wait can’t I just add this to the startup? yes you can but if you add it to startup you will need to clean up after yourself and startup will run after everything else has been started….

RunOnce is defined in the Windows Registry, under the following Key


You now can create new String Values
If you want to run something or Any Application


Or to open a folder for a user


In essence you can simply split your scripts to Phase1.vbs and Phase2.vbs if you require a reboot in between or update a registry/temp file before the reboot and continue after

Just my two cents about this.. some more generic info from MS can be found here – Linky

Posted in Batch Files, Scripting | Tagged , , , , , , | Leave a comment
Jul 18

Log Inventory Of Folder Into A File Multiple Options

So you want to log a content of a folder to a comma dilimted file (or something like that) but you need more options then what DOS can give…
For example you can use the following to use the DIR command

  1. Get to the MS-DOS prompt or the Windows command line.
  2. Navigate to the directory you wish to print the contents of. If you’re new to the command line, familiarize yourself with the cd command and thedir command.
  3. Once in the directory you wish to print the contents of, type one of the below commands.
    dir > print.txt
    The above command will take the list of all the files and all of the information about the files, including size, modified date, etc., and send that output to the print.txt file in the current directory.
    dir /b > print.txt
    This command would print only the file names and not the file information of the files in the current directory.
    dir /s /b > print.txt
    This command would print only the file names of the files in the current directory and any other files in the directories in the current directory.

But the options are kinda limited to what I needed here.

So here is the idea, you run your script with an argument option – remember my guide?
So we would run our script File_Inv.vbs /C:\Windows and our output file would look like so

bfsvc.exe|65024|Application|7/13/2009 9:14:12 PM|6.1.7600.16385|C:\Windows
entrust.ini|4133|Configuration settings|12/15/2009 2:41:14 PM||C:\Windows
explorer.exe|2614784|Application|2/26/2011 1:33:07 AM|6.1.7600.16768|C:\Windows
fveupdate.exe|13824|Application|7/13/2009 9:14:20 PM|6.1.7600.16385|C:\Windows
HelpPane.exe|497152|Application|7/13/2009 9:14:21 PM|6.1.7600.16385|C:\Windows
hh.exe|15360|Application|7/13/2009 9:14:21 PM|6.1.7600.16385|C:\Windows
ina32.ini|304|Configuration settings|7/12/2012 12:23:19 PM||C:\Windows
mercury.ini|134|Configuration settings|7/16/2012 2:22:43 PM||C:\Windows
msdfmap.ini|1405|Configuration settings|6/10/2009 5:19:27 PM||C:\Windows
notepad.exe|179712|Application|7/13/2009 9:14:27 PM|6.1.7600.16385|C:\Windows
regedit.exe|398336|Application|7/13/2009 9:14:30 PM|6.1.7600.16385|C:\Windows
system.ini|219|Configuration settings|6/10/2009 5:46:28 PM||C:\Windows
twain.dll|94784|Application extension|6/10/2009 5:41:17 PM||C:\Windows
twain_32.dll|51200|Application extension|7/13/2009 9:16:16 PM||C:\Windows
twunk_16.exe|49680|Application|6/10/2009 5:41:17 PM||C:\Windows
twunk_32.exe|31232|Application|7/13/2009 9:14:42 PM||C:\Windows
vbaddin.ini|39|Configuration settings|7/18/2012 8:47:38 AM||C:\Windows
win.ini|478|Configuration settings|7/11/2012 2:36:45 PM||C:\Windows
winhelp.exe|256192|Application|6/10/2009 5:42:20 PM||C:\Windows
winhlp32.exe|9728|Application|7/13/2009 9:14:45 PM|6.1.7600.16385|C:\Windows
write.exe|9216|Application|7/13/2009 9:14:49 PM|6.1.7600.16385|C:\Windows

In my example of my output file above you can see that i’m pulling only EXE, INI and OCX files with specific content of each file

Here goes the script
At first we add our argument option to specify a folder from a command line, as well we add the option to remove the forward slash from the argument (that’s how I like it but do what’s good for you)
As well i’m going to use the machine name as part of my output file name

Const ForAppending = 8
Const ForWriting = 2
Const ForReading = 1
Set wshNetwork = WScript.CreateObject( "WScript.Network" )
set objShell = CreateObject("Wscript.Shell")
strComputer = "."
strComputerName = wshNetwork.ComputerName
Set objArgs = WScript.Arguments
'WScript.Echo WScript.Arguments.Count
For Each strArg in objArgs
'WScript.Echo strArg
RetalixArgs = strArg

'--- Check File Versions Before Upgrade

MachineType = Right(strComputerName, 3)
SiteOfMachine = Left (strComputerName, 6)
If Not RetalixArgs = Empty Then
'WScript.Echo (RetalixArgs)
RetalixArgsPath = (Replace(RetalixArgs,"/",""))
BaseFolderNameX = RetalixArgsPath
OutPutFileName = "C:\" & strComputerName & "_Data.txt"
'WScript.Echo (RetalixArgsPath)

'Do something

End if

Second part is creating and validating my file, please see that I delete it if it exists every time I use this script

End if
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(OutPutFileName)then
end if

Set objFile = objFSO.CreateTextFile(OutPutFileName)

Set objTextFile = objFSO.OpenTextFile(OutPutFileName, ForAppending, True)

Now I call the function

ViewFolders BaseFolderNameX

Here you can see that i’m specifying the type of files that I need from the folder and what data to read from them, remember to match up to the first line that you ad above so you don’t mess up excel or beyond compare :)

Sub ViewFolders(strFolder)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
Set colListOfFiles = objFolder.Files

For Each objFile in colListOfFiles
sExtension = objFSO.GetExtensionName (objFile)
If sExtension = "exe" Or sExtension = "dll" Or sExtension = "ocx" Or sExtension = "ini" Then
Set objTextFile = objFSO.OpenTextFile (OutPutFileName, ForAppending, True)
objTextFile.WriteLine(objFile.Name&"|"&objFile.Size&"|"&objFile.Type&"|"&objFile.DateLastModified&"|")& objFSO.GetFileVersion(objFile) & ("|"&objFile.ParentFolder)
'WScript.Echo (objFile.Name&"|"&objFile.Size&"|"&objFile.Type&"|"&objFile.DateLastModified&"|")& objFSO.GetFileVersion(objFile) & ("|"&objFile.ParentFolder)
End If
'Set objFolder = Nothing
'Set colListOfFiles = Nothing
End Sub

You can download a text file from my repo – Rename Local User Script (1223)


Posted in Scripting | Tagged , , , , | Leave a comment
Jan 31

VBScript Read XML File – How To???

So you have an XML file and you want to use it with VBSCript….
In this post we will review reading an XML file by knowing the TAG names, next time we will break down on opening an XML file without knowing the tags.

Let’s take a look at this xml file (if you don’t know what’s XML then go here linky).

I have multiple tags with values, if you know the XML tag

<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><YeshaiUpgrade xmlns="Yeshai Upgrade Package">
      <Notes>Just Some Notes About The Package</Notes>

First thing we need to reference the XML object

	Set xmlDoc = CreateObject("Msxml2.DOMDocument") 

now we are going to make a reference to our XML file
You can set this how ever you want but I’m going based on the fact I don’t know the path to where the file will be (this is not mandatory)

		sPackageFile = sCurPath & "\UpgradePackage.xml"

Next step is referencing each and every tag you want to pull from the XML file

		FirstPackage = XMLRead (sPackageFile,"FirstPackage")
		UpgradeType = XMLRead (sPackageFile,"UpgradeType")
		NewVersion = XMLRead (sPackageFile,"NewVersion")
		OldVersion = XMLRead (sPackageFile,"OldVersion")
		UpgradeBaseFolder = XMLRead (sPackageFile,"UpgradeBaseFolder")
		Reboot = XMLRead (sPackageFile,"Reboot")
		ExecuteEndSciprt = XMLRead (sPackageFile,"ExecuteEndSciprt")
		ShutDownServices = XMLRead (sPackageFile,"ShutDownServices")
		ShutDownXMLFile = XMLRead (sPackageFile,"ShutDownXMLFile")
		ExecuteAfterReboot = XMLRead (sPackageFile,"ExecuteAfterReboot")
		ExecuteAfterRebootScript = XMLRead (sPackageFile,"ExecuteAfterRebootScript")
		Notes = XMLRead (sPackageFile,"Notes")

Now I love functions so just for y’all I’ve added this function

Function XMLRead(XMLFileName, XMLTag)
		Set ElemList = xmlDoc.getElementsByTagName(XMLTag)
		XMLRead = ElemList.item(0).Text

End Function

After you run the process each one of the values is read from the XML file…

Quite simple :)

Posted in Scripting | Tagged , , , , , | 4 Comments
Jan 03

Running Batch Issue Windows 7 – “Security Warning – Do you want to open this file?”

If you’re reading this you know what you are looking for…

** Thanks Pavel!

So even if you disable the UAC completly when running batch files windows will prompt you if you wish to run the file

So here are your basic options
1. Right click the Batch files and select Run As Administrator
2. Create a shortcut, modifigy the properties to run as administrator
3. Here is an interesting one you can use

If, you currently get the message “Security Warning – Do you want to open this file?”, then you can ignore the above and run the following command:

ICACLS "yyy" /Setintegritylevel (OI)(CI)M

Where yyy is replaced with the path of the batch file producing the error message.
On my system (Windows 7 Pro 64-bit), the command has to be re-executed every 8 hours or it will expire, so I have the command in a batch file which is executed Daily every 8 hours by a Task Scheduler task.

You might ask why do I need this??? well I don’t know bu enjoy

Posted in Batch Files | Tagged , , , , | Leave a comment
Aug 19

Google Analytics Search Terms For My Sites

Sometime I like to follow Google Analytics to see how people reach my sites.
And funny enough it seems that I write some posts to about something specific that seem to have resolved issues with other search terms.

Here are the search terms that get on the spot

vbscript change ip address
vbscript passing arguments 
get directory path of an executing batch file 
net user rename 

And the list will go on for this an my other sites….
Here is a great example of a search term that pointed to a post I wrote about DIM in vbscript

vbscript name redifined error 

I wrote my thoughts about DIMing in a script and in my example I showed a redfined error without thinking about it.
Now it just gave me another POST to write about.

Bottom line, if you use analytics check you search terms leading to your site.

Posted in General | Tagged , , , | Leave a comment
Aug 19

Modify Text/Batch/Registry Files For Automation

So let’s say you are working with Batch Files or Regsitry files and you want to automate so sort of process to prompt a user for an input box and change values.

We have a registry file that contains the following information that we want to change.
Make sure that you set the text you want to change to strings that aren’t anywhere else in the file or else you will make changes to multiple items so don’t just change a “Y” to something else.

Windows Registry Editor Version 5.00

First we will start with a input box for SiteID, PhoneNumber and TerminalID

	set objShell = CreateObject("Wscript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")

	SiteID = InputBox("Please Enter SiteID", "Site ID","")
	PhoneNumber = InputBox("Please Enter PhoneNumber in the following format xxx-xxx-xxxx","Phone Number","xxx-xxx-xxxx")
	TerminalID = InputBox("Please Enter TerminalID","Terminal ID","")

You can add protection around the input boxes so you have to enter a minimum amount of characters or must be numeric and have a specific amount of digits if you need.
This would be easier to accomplish by specific functions but let’s talk about that some other time.

Now let’s update our registry file before we merge it or deploy it.
First we point to our registry file

File = "C:\yeshaib.reg"

Now we will open the file and read the content, look for specifc strings and replace them.

Const ForReading = 1
Set objFile = objFSO.OpenTextFile(File, ForReading)
MyString = objFile.ReadAll()

MyString = Replace(MyString, "PPP-PPP-PPPP", PhoneNumber, 1, -1, 1)
MyString = Replace(MyString, "XXXX", SiteID, 1, -1, 1)
MyString = Replace(MyString, "TID", TerminalID, 1, -1, 1)

Set objFile = objFSO.CreateTextFile( File, True)
objFile.Write MyString

Run the script and it will prompt you three times




And the Registy file will have the correct changes

Windows Registry Editor Version 5.00

Posted in Scripting | Tagged , , , | Leave a comment
May 24

Off-Topic My Second Android Application – Burn Rate Calculator Lite

Ok what’s burn rate in the project world?
Aside from financing, the term burn rate is also used in project management to determine the rate at which hours (allocated to a project) are being used, to identify when work is going out of scope, or when efficiencies are being lost. Simply put, the burn rate of any project is the rate at which the project budget is being burned (spent).
In earned value management, burn rate is calculated via the formula, 1/CPI, where CPI stands for Cost Performance Index, which is equal to Earned Value / Actual Cost.

Let’s not get into the nitty gritty of project management and calculations but more on what this app has…
Burn Rate based on Budget
Burn Rate based on Project Days
Project Budget Calculator based on CPH, HPD, CPD and Total Project Days

As well you have a list view of all PMP Formulas – Might have missed a few so let me know

Market Linky – Click Me

Original Post – Linky

Posted in Android | Leave a comment
Apr 20

A Great Windows Installer – Install Simple

So as we all know you need to deploy your software somehow….
In most cases WinZip self extractor would do but it does not look professional in any way, or for others Microsoft’s Package and Deployment wizard just creates too many file (or you just don’t use visual studio at all…).
So there are many free tools or some that cost an arm and a leg (I personally think that anything over $100 is too high for something that does not generate revenue for me).
So I was looking for a simple application that would package my software and scripts in a nice way and won’t break the bank.

I found a few open source application like NSIS that are either too robust for me with their full blown installer or too simple with their Zip2Exe plug in.

So I found Install Simple – Linky via Google and had a quick run with it.

So the main things I liked on it were
* Simplicity – easy and straight forward
* Similar look to a full installer – the installer looks like it was built with a full blown installer
* Packages – Save your packages
* Registry Control – I code everything “Registry” in my apps but it’s a nice feature
* Ability to change the look of the GUI (not much but enough)
* Uninstall feature

Some Cons
* No options for silent command line execution – I need silent installs
* Can’t change the icon of the package – Not a big one but would be a great feature!
* Can’t Execute files after install is done – Now this one is a must! even with a question during the compiling process and if after a reboot it could be added to the runounce of windows
* “Registry” pull data from the registry and utilize it with the installer

Here is a quick guide on how to use it
1. Run Install Simple
Enter you information – Band Text is in the PRO version

Click on read more to follow the guide
Read More »

Posted in Development, General | Tagged , , , | Leave a comment
Apr 08

Off-Topic My First Android Application The Stig Facts

The Stig Facts

This application thought me a lot about android development and this application will be the base for the coming guides that include Android Development, Layout, Some Design (as mine is not amazing), Database! and more

Now back to the application
The Stig is the Chuck Norris of the auto world
Just something about “The Stig”
The Stig is a character in the British motoring television show Top Gear. The character plays on the anonymity of racing drivers’ full-face helmets, with the running joke that nobody knows who, or indeed what, is inside the character’s racing suit.

Link To App On Market – Linky


Posted on – Linky

Posted in Android | Tagged , , , | Leave a comment