Archive for June, 2007

Create an Internet shortcut

To create a shortcut to an url you can do as follows

set oUrlLink = WshShell.CreateShortcut(strDesktop & "\Microsoft Web Site.url")
oUrlLink.TargetPath = "http://www.yahoo.com"
oUrlLink.Save

Create a Desktop shortcut using WSH

If you want to create a shortcut programatically use the code below. Found somewhere on net

'Create a Desktop ShortCut
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\Shortcut To Notepad.lnk")
oShellLink.TargetPath = "Notepad.exe" 'WScript.ScriptFullName
oShellLink.WindowStyle = 1
oShellLink.Hotkey = "CTRL+SHIFT+N"
oShellLink.IconLocation = "notepad.exe, 0"
oShellLink.Description = "Shortcut To Notepad."
oShellLink.WorkingDirectory = strDesktop
oShellLink.Save

Get the name of the host/ computer


Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Domain = " & WshNetwork.UserDomain
WScript.Echo "Computer Name = " & WshNetwork.ComputerName
WScript.Echo "User Name = " & WshNetwork.UserName

Read a Text File and print line by line


Option Explicit
Dim gpsFile
Dim gpsFileLines
Dim eGpsLine

Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oWS : Set oWS = CreateObject("WScript.Shell")
gpsFile = "c:\yourtextfile.txt"

With oFSO.GetFile(gpsFile)
'Get all Lines
gpsFileLines = Split(.OpenAsTextStream(1, 0).Read(.Size), vbcrlf)
End With

For Each eGpsLine in gpsFileLines
'Print all lines on by one
Wscript.Echo eGpsLine & vbcrlf
Next
Wscript.Quit

Get Processor and OS info

We can get the Processor and OS info like this using the Environment method

Set WshShell = WScript.CreateObject(“WScript.Shell”)
Set WshSysEnv = WshShell.Environment(“SYSTEM”)
WScript.Echo “NUMBER OF PROCESSORS : ” & WshSysEnv(“NUMBER_OF_PROCESSORS”)
WScript.Echo “PROCESSOR ARCHITECTURE : ” & WshSysEnv(“PROCESSOR_ARCHITECTURE”)
WScript.Echo “PROCESSOR IDENTIFIER : ” & WshSysEnv(“PROCESSOR_IDENTIFIER”)
WScript.Echo “OS : ” & WshSysEnv(“OS”)

Get Windows Environment Info

To get the Environment info like Compsec, PAth, pathext windows folder and temporary folder location we can do like this


Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WScript.Echo "COMSPEC (Executable file for the command prompt ) : " &_
 WshSysEnv("COMSPEC")

WScript.Echo "PATH : " & WshSysEnv("PATH")
WScript.Echo "PATHEXT : " & WshSysEnv("PATHEXT")

WScript.Echo "WINDIR : " & WshSysEnv("WINDIR")
WScript.Echo "TEMP : " & WshSysEnv("TEMP")
Feedback Form