VBScript – redirect WSscript into any directory




Tagged Under : , , , ,

Version: 13.1a
Revision: 15 Build 16

VBScript – redirect WSscript into any directory

Introduction:
yesterday, from work, I was totally boiling! This made everyone in the department a little curious…they aren’t sure, what happened.
But, that is not the point about this article…

This article will help user and IT administrator handle “wscript output” into any directory.
So, the solution is pretty much…simple…plain stupid. All we need to do is use: “AddQuotes, StringInput and stringRun” to accomplish this process. However, this will only work on “Windows XP SP2 +”, and, to avoid confusion, please read VBScript for dummies…

Bah…here is the Script! I need to get on with my Novel. But, don’t panic and run off my blog, I am just stressed. That is all…

——————————————

Notes #1: the function “AddQuotes” takes care of the double quoting issues, by surrounding whatever input (using the “stringInput” argument of the AddQuotes function.), and redirect the commands, using the built in “Chr(34)” function.

Notes #2: for the “%compspec% /c syntax”. That is old school and it’s already shown in Microsoft KB Articles.

—Copy Source Code—

'Author: Lair360
'Version: 13,6a
'Revision: 14.1 Build 11
'---------------------------------
Set objShell = WScript.CreateObject("WScript.Shell")
'You can modify this line only. But, don't modify anything else below "StrRun".
'---------------------------------
strRun = "%comspec% /c ipconfig.exe > " & AddQuotes("C:\temp\ipconfig.txt")
'---------------------------------
objShell.Run strRun, 1, True
Function AddQuotes(strInput)
AddQuotes = Chr(34) & strInput & Chr(34)
End Function

—End Source Code—

Here is another version for you to analyze. But, don’t get too confuse about it…

—Copy Source Code—

'Author: Lair360
'Version: 13,6a
'Revision: 14.1 Build 11
'---------------------------------
On Error Resume Next
Set objShell = WScript.CreateObject("WScript.Shell")
'You can modify this line only. But, don't modify anything else below "StrRun".
'---------------------------------
strRun = "%comspec% /k c: & ipconfig /displaydns > " & AddQuotes("I:\vbs project\ipconfig.txt")
'---------------------------------
objShell.Run strRun, 1, True
Function AddQuotes(strInput)
AddQuotes = Chr(34) & strInput & Chr(34)
End Function

—End Source Code—

Copyrighted By Lair360




VBScript – reboot & shutdown computer systems




Tagged Under : , , , , ,

Version: 13.2
Revision: 44 Build 11

VBScript – reboot & shutdown computer systems

Introduction:
many users had asked me to create a VBScript, so that they can shutdown their computer, when they are in an airport or other areas. After two days, I’ve managed to complete my script. However, it’s a pain in the neck to construct one! But, that road is not for you to worry about.

I take the risk and testing. But, the rest is for you to enjoy!

1.] Download notepad++ from the original author or from another source.
——————————-

http://sourceforge.net/projects/notepad-plus/

http://filehippo.com/download_notepad/

——————————-

2.] Copy this ‘VBScript’ source code and save it as a “.vbs” extension.

VBScript – Reboot Computer Systems
—Copy Source Code—

'Version: 12.2
'Revision: 44 Build 22
'Copyrighted by Lair360
'*******************************
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")

for each OpSys in OpSysSet
OpSys.Reboot()
next

—End Source Code—

VBScript – Shutdown Computer Systems
—Copy Source Code—

'Version: 12.2
'Revision: 44 Build 22
'Copyrighted by Lair360
'*******************************
Set OpSysSet = GetObject("winmgmts:{(Shutdown)}!\\.\root\cimv2").ExecQuery _
("select * from Win32_OperatingSystem where Primary=true")

for each OpSys in OpSysSet
OpSys.Shutdown()
next

—End Source Code—

3.] Activate the script and enjoy it!

Copyright By Lair360




Eject USB – Terminate Application




Tagged Under : , , , , ,

Version: 11.1
Revision: 32 Build 15

Eject USB – Terminate Application

Introduction:
when I was working on my project and exit, I would like to eject my external drive. However, there is a problem.

If you close an application, most of the memory in that particular application is not freed, so you’ll have to terminate a process which is / are running inside your USB drive. After that, you can safely eject without rebooting your computer and wasting your time!

1.] Download notepad++ from the original author or from another source.
——————————-

http://sourceforge.net/projects/notepad-plus/

http://filehippo.com/download_notepad/

——————————-

2.] Copy this ‘VBScript’ source code and save it as “process_terminate.vbs” [without the quotes]. But, you can use other names if you want and keep the extension intact.

Advice: please put this script on your desktop or system tray.
But, don’t save this script into your external drive! If you do this, there will be conflicts and errors…

Terminate a process application & Eject USB
—Copy Source Code—

'Version: 34.1
'Revision: 44 Build 22
'Copyrighted by Lair360
'*******************************
Dim arrDrives()
intCount = 0
strComputer = "."
'*******************************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
'Finds all removable drives - USB port.
Set colDrives = objWMIService.ExecQuery _
    ("Select * From Win32_LogicalDisk Where DriveType = 2")

For Each objDrive in colDrives
	ReDim Preserve arrDrives(intCount)
	arrDrives(intCount) = objDrive.DeviceID
	intCount = intCount + 1
Next
'*******************************
'Finds all processes from a specific removable drives
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objItem in colItems
	For Each strDrive in arrDrives
		If LCase(Left(objItem.ExecutablePath, 2)) = LCase(strDrive) Then
			set objWMI = GetObject("winmgmts://" & strComputer)
			set objRootProcess = _
				objWMI.get("Win32_Process.Handle=" & objItem.ProcessId)
			KillProcessTree objRootProcess
		End If
	Next
Next
'*******************************
Sub KillProcessTree(objProcess)
	'Kills the process and any child processes
	objWQL = "Select * from Win32_Process " _
	& "where ParentProcessID=" & objProcess.Handle
	Set colResults = objWMI.ExecQuery(objWQL)
	For Each ChildProcess in colResults
		KillProcessTree childProcess
	Next
objProcess.Terminate
End Sub

—End Source Code—
Copyright 2001-2009 Lair360


4.] Execute the script!

5.] Done!




VBScript – display ipconfig properties




Tagged Under : , , ,

Version: 46.2
Revision: 70 Build 34

VBScript – display ipconfig properties

Introduction: If you are in for a rush and you want to look at “ipconfig /all” or “ipconfig /displaydns,” you can follow this guides and use it without typing in the actual commands.

1.] Download one of these notepad applications. But, if you haven’t downloaded them, please use one of the links that is provided.

2.] Copy and paste one of these codes into notepad.

************************************
DisplayDNS.
************************************

'============================
'Author: Lair360.
'Version: 16 Build 67.
'============================
On Error Resume Next 'This line will concel the error and direct to the info.
Dim objShell 'This will maintain memory usage when "WS.script.Shell" is activated.
Set objShell = CreateObject("WScript.Shell")
objShell.Run ("%comspec% /k c: & ipconfig /displaydns")
'Results are given and the cmd command-line has exit.
WScript.Quit
' End of VBScript command

************************************
Display IP configurations.
************************************

'============================
'Author: Lair360.
'Version: 16 Build 67.
'============================
On Error Resume Next 'This line will concel the error and direct to the info.
Dim objShell 'This will maintain memory usage when "WS.script.Shell" is activated.
set objshell = createobject("wscript.shell")
objshell.run("%comspec% /k c: & ipconfig /all")
'Results are given and the cmd command-line has exit.
WScript.Quit
'End of VBScript command

************************************

3.] Go to: File >> Save As.

4.] Put a specific name for the codes and input the extension at the end.
The script extension is: .vbs

Example: displayDNS.vbs

5.] Hit the save button and execute the script.