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 , , , , , | 5 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
Feb 11

Changing Computers IP Addresses with VBScript

So now that we changed the machine name and user names we might need to change some IP’s….

As you can see below you will need to specify the IP’s somehow (hard coded right now) with a MSGBOX, Registry read, text file, Machine name etc


	const HKLM   = &H80000002
	Set WshShell = CreateObject("WScript.Shell")
        Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set oNetwork = CreateObject("WScript.Network")
	strCurrentComputerName = oNetwork.ComputerName

	'Setup IP's you want to implament, you can add logic for MSGBOX etc.		
		strComputer = "."
		IPAddress = ""
		dGateway = ""
		arrIPAddress = Array(IPAddress)
		arrSubnetMask = Array("")
		arrGateway = Array(dGateway)
		arrDNSServers = Array("")
		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
		For Each objNetAdapter in colNetAdapters
		     errEnableStatic = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
		     errGateways = objNetAdapter.SetGateways(arrGateway)
		     intSetDNSServers = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
		If intSetDNSServers = 0 Then
		    MSGBOX("Server IPs set to: IPAddress = " & IPAddress)
			MSGBOX("Error setting server info.")
	 	End If
Posted in Scripting | Tagged , , , , | 4 Comments
Feb 10

Rename Machine Name with VBS

So… we renamed a user name with VBS here – Linky but now we need to change the machine name.
How simple is that? very

As you can see below specify a machine name under
strNewName = “InRimServer”
So “InRimServer” is the hard coded name of the script but you can change this with a MSGBOX or pull the value from other locations….
And initiate a reboot in the end of the script (or manually afterwards)


	const HKLM   = &H80000002
	Set WshShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set oNetwork = CreateObject("WScript.Network")
	strCurrentComputerName = oNetwork.ComputerName
 	strNewName = "InRimServer"
	strKeyPath   = "System\CurrentControlSet\Control\ComputerName\ComputerName"
	set objReg = GetObject("winmgmts:\\" & strCurrentComputerName & "\root\default:StdRegProv")
	intRC = objReg.SetStringValue(HKLM, strKeyPath, "ComputerName", strNewName)
	if intRC <> 0 Then
		MSGBOX("Error setting ComputerName value: " & intRC)
		MSGBOX("Successfully set ComputerName value to " & strNewName)
	end if
	strKeyPath   = "System\CurrentControlSet\Services\Tcpip\Parameters"
	intRC = objReg.SetStringValue(HKLM, strKeyPath, "NV Hostname", strNewName)
	if intRC <> 0 Then
		MsgBox("Error setting NV Hostname value: " & intRC)
		MsgBox("Successfully set NV Hostname value to " & strNewName)
	end if
 	'Remove the comments if you want an auto reboot
' 	MsgBox("Rebooting system...")
' 	WScript.Echo "Rebooting system..."
'	Set OpSysSet = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}//" & strComputer).ExecQuery("select * from Win32_OperatingSystem where Primary=true")
'    for each OpSys in OpSysSet
'        OpSys.Reboot()
'    Next    

Posted in Scripting | Tagged , | 1 Comment
Feb 01

Rename Users with VBScript

This question came through the red phone line (well email)…. (and there were two questions but I’ll save the other for a different post….)
And it’s quite simple but we are going to cheat here and use a net user command.

So we need to determine a few things well just one thing, Is the user name constant name or does it change?

So this is how my script would look like
I’m going to look at this as if the user is a constant user (name does not change)

' Set some objects
    Set WshShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

'get our constant user name from the system (change the UserNameHere)
Set colItems = objWMIService.ExecQuery ("Select * from Win32_UserAccount Where Name = 'UserNameHere'")	
	For Each objItem in colItems
	  objItem.Rename "NewUserNameHere"
'change the user name
 WshShell.Run "cmd /c net user UserNameHere /fullname: NewUserNameHere", 1, true 

Kinda simple, but what happens if you don’t know the user name and simply want to change the user name?
I don’t think this is a good idea but lets say we just want to add some characters to the user…

So we are going to add a few lines and change a few lines…

' Set some objects
    Set WshShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
'set and get the current user account
    Set objNetwork = CreateObject("WScript.Network")
    strUserName = objNetwork.UserName

'get our constant user name from the system remember we got the current user before

Set colItems = objWMIService.ExecQuery ("Select * from Win32_UserAccount Where Name = '" & strUserName & "'")	
	For Each objItem in colItems
	  objItem.Rename strUserName & "Tech"
'change the user name
 WshShell.Run "cmd /c net user "& strUserName &" /fullname: """ & strUserName & "Tech""", 1, true 
MsgBox "cmd /c net user "& strUserName &" /fullname: " & strUserName & "Tech"

Don’t forget to add some protection and logging, and if you need to change your auto login etc…
As well you might not need the MsgBox and you will need to reboot.

Posted in Development, Scripting | Tagged , , , | 1 Comment