RSS

Tag Archives: vbscript

VBScript to list shares and permissions in Windows OS

I thought that this would be an easy script to find, but surprising there are no complete script to be found. I found the following powershell script in the respository

http://gallery.technet.microsoft.com/scriptcenter/List-Share-Permissions-83f8c419

It works and lists the shares, but it does not product the path of the share!

Found another helpful posts for VBScript version here:

http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/55acaaf8-efc5-4432-8ac7-b37eed81defd/

It works but for some reasons the security permissions are not correct

The closest I find is this:

http://www.visualbasicscript.com/Enumerating-Share-Permissions-not-NTFS-m58860.aspx

Works well BUT it again does not list the path of share. Why in the world would I not want to know where a share path is? Read the rest of this entry »

 
3 Comments

Posted by on February 27, 2013 in Scripts, VBScripts, Windows

 

Tags:

VBScript to grab server names from a list of HP Blade enclosures

Challenge: How to get all blade’s server names (iLO name really) from a list of Enclosure’s IP address? This so far works only for HP Blade C series enclosure

set objArg = WScript.Arguments
if objArg.Count >= 4 then

  set WshShell = WScript.CreateObject("WScript.Shell")

  Encl_IP = objArg(0)
  Encl_Name = objArg(1)
  LogonID = objArg(2)
  LogonPWD = objArg(3)

  WshShell.run "telnet.exe -f .\" & Encl_Name & "_" _
   & Encl_IP & ".log " & Encl_IP
  WScript.Sleep 2000

  wshShell.AppActivate ("telnet.exe " & objArg(0))
  WshShell.SendKeys LogonID
  WshShell.SendKeys ("{Enter}")
  WScript.Sleep 1000

  wshShell.AppActivate ("telnet.exe " & objArg(0))
  WshShell.SendKeys LogonPWD
  WshShell.SendKeys ("{Enter}")
  WScript.Sleep 1000

  wshShell.AppActivate ("telnet.exe " & objArg(0))
  WshShell.SendKeys "SHOW SERVER LIST"
  WshShell.SendKeys("{Enter}")
  WScript.Sleep 1500

  wshShell.AppActivate ("telnet.exe " & objArg(0))
  WshShell.SendKeys "exit"
  WshShell.SendKeys ("{Enter}")
  WScript.Sleep 1500

  wshShell.AppActivate ("telnet.exe " & objArg(0))
  WshShell.SendKeys ("{Enter}")

  Set fso = CreateObject("Scripting.FileSystemObject")
  set f = fso.OpenTextFile(".\" & Encl_Name & "_" & Encl_IP & ".log")

  Is_SOL = false  'Is start of line?
  SvrInfo = ""
  do while not f.AtEndOfStream
    t = f.readline
    if instr(t,"Bay iLO Name ") > 0 then
      t = f.readline
      t = f.readline
      Is_SOL = true
    elseif instr(t,"Totals:") > 0 then
      Is_SOL = false
      exit do
    end if

    if Is_SOL then  'grab server name from current line
      t = mid(t,5,29) & vbTab & Encl_Name & vbTab & Encl_IP
      SvrInfo = t & vbCrLf & SvrInfo
    end if

  loop

  f.close

  set f1 = fso.OpenTextFile(".\ServerList.log",8,true)
  f1.Writeline SvrInfo
  f1.close

else

  Wscript.echo " "
  Wscript.echo "<encl. IP> <encl. name>  "
  Wscript.echo " "
  Wscript.echo "Log file for telnet session = <encl. name>_log.log"

end if
 
Leave a comment

Posted by on August 1, 2012 in Scripts, VBScripts

 

Tags: ,

VBScript: Convert/Split seconds to days, hours, minutes and seconds

This function converts the number of seconds to its day, hour, min and sec components. It returns a comma-delimited string in format “day,hour,min,sec”. You can use the split() function to extract it into an array, example, MyTime = split(SplitSec(449786), “,”)

Function SplitSec(pNumSec)
  Dim d, h, m, s
  Dim h1, m1

  d = int(pNumSec/86400)
  h1 = pNumSec - (d * 86400)
  h = int(h1/3600)
  m1 = h1 - (h * 3600)
  m = int(m1/60)
  s = m1 - (m * 60)

  SplitSec = cStr(d) & "," & cStr(h) & "," & cStr(m) & "," & cStr(s)
End Function
 
Leave a comment

Posted by on August 3, 2011 in Scripts

 

Tags:

VBScript: comparing two files using dictionary object

Here is a VBScript function to compare 2 files and get the changes between them. The function will return a multi-line string with what was added, modified and deleted between the old and new file.

This function was initially developed for me to compare changes between an old and new input file in my script. I need to know which server was added or removed and which server had its parameters modified. The input files is a delimited file using “~” as a delimiter and contains 2 values in each line: “server name” & “parameter”. Read the rest of this entry »

 
Leave a comment

Posted by on May 6, 2011 in Scripts, VBScripts

 

Tags:

Rightfax COM API using VBScript

This is something that you hardly can find on the internet nor off the rightfax vendor site. The main reason is that most of the programming is done by programmers using C or VB.Net or some programming framework. But as an administrator of RightFax servers, sometimes its good that I can fire up vbscripts to automate some reporting on my end. Read the rest of this entry »

 
13 Comments

Posted by on June 30, 2010 in VBScripts, Windows

 

Tags: ,

VBscript: Grabbing subfolders recursively

I was working on a script that needs me to grab a list of subfolders recursive off the user data area and found that vbscript language does not natively support a recursive function in its filesystemobject. So the first thing is to ask Mr. google who studiously brought up the pages I required. Obviously the Microsoft Scripting Center has the most referenced samples for this function.

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Scripts")
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
  Wscript.Echo Subfolder.Path
  ShowSubFolders Subfolder
Next
End Sub

Sure this is a quick and easy sample, but most of the time, when we are looking for solution, we actually want to do something with the folders! I have seen many examples of how functions can be used and most of them are just simple and mostly useless immediately. Basically, if I want to display all subfolders in a folder, I don’t need to use vbscript, just “dir /b /s /a:d” will give me the same results! Read the rest of this entry »

 
Leave a comment

Posted by on May 4, 2010 in Scripts, VBScripts

 

Tags:

VBScript: nth Day of the month

Recently I needed a function to calculate the nth day of the month, that is, first sunday, 2nd thursday, last friday, etc. I thought such functions would be easy to find in the internet, however, I couldn’t find a complete function and so decided to write one:

Apologise for the formatting, wordpress don’t like programming codes in their blogs Read the rest of this entry »

 
3 Comments

Posted by on December 24, 2008 in Scripts, VBScripts

 

Tags:

VBScript: Faking the include directive

VBScript does not provide any include directive that is common in many other languages. Luckily, the language provides a pseudo-include statement, EXECUTEGLOBAL and EXECUTE, which we can use to fake the include directive.

Why do we need to do that in our scripts? Well, very often, we want to distribute a standard set of codes, for example, templated functions and procedures. You want to ensure that all your scripts are running from the same versions. If those functions are included inside the vbscript, then it will be impossible to control your standard functions’ version.

A real life example: I have a report class which is used by various Start of Day (SOD) scripts to provide a summary text file about their status. I don’t want to copy the codes into each script and have to update every script everytime I add or update the function of the class. Includes come in handy in this case. Read the rest of this entry »

 
Leave a comment

Posted by on March 31, 2008 in Scripts, VBScripts

 

Tags:

VBScript: If InStr(MyText, SearchText) then…

One thing I never liked about VB as a language is that it is too flexible as a programming language, although I am a rather full-fledged VBScript scripter. The flexiblity also introduces bad programming practices.

One of the allowed syntax in VBScript is…

If InStr(MyText, SearchText) then (do something)…

If you look the function for InStr(), it actually returns a position number or 0 (or null). In VB, this is legal, because the IF statement sees a 0 as false and I guess a postive number as true. This gives the appearence that InStr() returns a boolean, when this is not true.

Just because this can be done in VB, does not make it a good programming practice. This is just both lazy and bad practise, in my opinion.

The more correct statement should be:

If InStr(MyText, SearchText) > 0 then (do something)…

This will undeniably tell you what kind of values InStr() returns… a number

 
16 Comments

Posted by on November 20, 2007 in Scripts, VBScripts

 

Tags:

Windows networking script: Set show icon for all NICs

In the Internet, there is a number of examples of how to set an individual NIC to show icon in notification area, but you cannot find one if you want to set ALL the NICs by default. This is a required for my work and, hence, modified some of the scripts on the net and using WMI registry class to do the task.

You can download the VBS (please rename doc to vbs) script here

ShowIcon VBS Script

The WriteToLog() is my own function (show you some other days), you can replace it with WScript.echo.

Also note, I stopped indent after some levels so that it does not wrap around too much

‘==========================================
Sub SetShowIconValue
‘==========================================

Const HKLM = &H80000002

Dim ServerName
Dim objReg

Dim CtrlNetworkKeyPath
Dim arrAdapterGUIDs, AdapterGUID
Dim AdapterGUIDConnKeyPath
Dim AdapterNameValue
Dim AdapterNameStringValue
Dim ShowIconDWORDValue

ServerName = “.”

‘Don’t want any errors here to kill the program
On error resume next

Set objReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” & _
ServerName & “\root\default:StdRegProv”)

‘This path is fixed in Windows

CtrlNetworkKeyPath = “SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}”

‘grab all the subkeys, i.e. the Adapter GUIDs

objReg.EnumKey HKLM, CtrlNetworkKeyPath, arrAdapterGUIDs

for each AdapterGUID in arrAdapterGUIDs

if InStr(AdapterGUID, “{“) > 0 then ‘look for keys that looks like a GUID

AdapterGUIDConnKeyPath = CtrlNetworkKeyPath & “\” & AdapterGUID & “\Connection”

AdapterNameStringValue = “”

objReg.GetStringValue

HKLM,AdapterGUIDConnKeyPath,”Name”,AdapterNameStringValue

if AdapterNameStringValue <> “” then

WriteToLog “Looking at registry path: ” & AdapterGUIDConnKeyPath
WriteToLog “Network Name: ” & AdapterNameStringValue

‘Just set all NICs regardless of their status, no harm done

objReg.SetDWORDValue HKLM,AdapterGUIDConnKeyPath,”ShowIcon”,1

if Err.Number = 0 then
WriteToLog “Show Icon value is set to: 1”

else
WriteToLog “Error ” & CStr(Err.Number) & ” while trying to check ShowIcon value, ” & Err.Description
end if

else

WriteToLog “Cannot get name for network adapter GUID:” & AdapterGUIDConnKeyPath

end if

end if

next

On error goto 0

End Sub

 
9 Comments

Posted by on June 29, 2007 in Scripts, VBScripts

 

Tags: ,