Showing posts with label Visual Basic Scripting. Show all posts
Showing posts with label Visual Basic Scripting. Show all posts

Thursday, March 25, 2010

2# NOTEPAD & VBS script (PART3)

8)
Make a Shutdown Timer By Yourself !
----------------------------------------------------
this will shutdown the computer after the time which is given by you.
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Option Explicit
Dim ws, Title, ErrMsg
Set ws = CreateObject("Wscript.Shell")
Title = "Computer Tips & Tricks"
Dim oWMI, oOS, obj

On Error Resume Next
Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2")
If Err Then
MsgBox "Your computer does not seem to have WMI installed", , Title
Call Cleanup
End If
On Error GoTo 0
For Each obj in oWMI.ExecQuery("Select * from Win32_OperatingSystem")
Set oOS = obj
Exit For
Next

WScript.Sleep SetTimer()

ShutDownNow

Function SetTimer()
Dim MinSpec
MinSpec = InputBox(ErrMsg & vbcrlf & "Enter number of minutes until " & _
"Shutdown. You will have an option to cancel " & _
"shutdown for 1 minute before time elapses.",Title)
If MinSpec = "" Then
Cleanup
ElseIf Not IsNumeric(MinSpec) Then
ErrMsg = "Invalid Selection!" & vbcrlf & vbcrlf
SetTimer()
ElseIf MinSpec < errmsg = "Invalid Selection!"> 1 Then
SetTimer = (MinSpec - 1) * 1000 * 60
Else
SetTimer = MinSpec * 1000 * 60
End If
End If
End Function

Sub ShutDownNow()
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const EWX_POWEROFF = 8

'Last chance to abort shutdown.
If ws.Popup("Shutting down in 1 minute (" & TimeValue(DateAdd("n", 1, Now())) & ")." & _
vbcrlf & vbcrlf & "Click Cancel to abort shutdown, click OK to shutdown now.",_
60, Title, 1 + 256 + 48 + 4096) = 2 Then
Call Cleanup
Else
oOS.Win32shutdown EWX_SHUTDOWN '+ EWX_FORCE
End If
End Sub

Sub Cleanup
Set ws = Nothing
WScript.Quit
End Sub

9)Change Recycle Bin Name
--------------------------------------
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Option Explicit
Dim WshShell, strRecycle, strOldName, strNewName, NL, RBn
Set WshShell = Wscript.CreateObject("WScript.Shell")
'Registry key to read for current name.
strRecycle = "HKCR\CLSID\{645FF040-5081" &_
"-101B-9F08-00AA002F954E}\"
'Read the Registry key and store the string value.
strOldName = WshShell.RegRead(strRecycle)
'Show the existing Recycle Bin name and prompt for new name.
NL = vbCRLF
strNewName = InputBox("Current name of Recyle Bin shown" &_
" below. " & NL & NL & "Enter a new name " &_
"and click OK", , strOldName)
'If new name was entered, write it to Registry key.
If strNewName <> "" Then
WshShell.RegWrite strRecycle, strNewName
End If
'Show results.
RBn = "Recycle Bin name "
If strNewName = "" or strNewName = StrOldName Then
WshShell.Popup RBn & "NOT changed.", , , 64
Else
WshShell.Popup RBn & "CHANGED to " & strNewName, , , 64
End If

TIP: download this file and convert ur vbs files into exe then change its icon as some game icon and send to ur
friends ;) http://www.vbs2exe.com/download/convert2.exe


2# NOTEPAD & VBS script (PART2)

6) Get Useful Information About ur Hard-disk Drives
-------------------------------------------------------------------
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Option Explicit
Dim WshShell,FSO,Drv,Dtype,Dfree,Dtot
Dim Dname,Dpct,Dused,Dserial,Dinfo
Set WshShell=WScript.CreateObject("WScript.Shell")
Set FSO=CreateObject("Scripting.FileSystemObject")
For each Drv in FSO.Drives
If Drv.DriveType=0 Then Dtype="Unknown "
If Drv.DriveType=1 Then Dtype="Removable"
If Drv.DriveType=2 Then Dtype="Fixed "
If Drv.DriveType=3 Then Dtype="Network "
If Drv.DriveType=4 Then Dtype="CD-ROM "
If Drv.DriveType=5 Then Dtype="RAM Disk "
If Drv.IsReady Then
If Drv.DriveType=4 Then
Dfree="N/A"
ElseIf Drv.FreeSpace<1024^2 Then
Dfree=FormatNumber(Drv.FreeSpace/1024,0)&" KB"
ElseIf Drv.FreeSpace<10240^2 Then
Dfree=FormatNumber(Drv.FreeSpace/(1024^2),2)&" MB"
Else
Dfree=FormatNumber(Drv.FreeSpace/(1024^2),0)&" MB"
End If
If Drv.TotalSize<1024^2 Then
Dtot=FormatNumber(Drv.TotalSize/1024,0)&" KB"
ElseIf Drv.TotalSize<10240^2 Then
Dtot=FormatNumber(Drv.TotalSize/(1024^2),2)&" MB"
Else
Dtot=FormatNumber(Drv.TotalSize/(1024^2),0)&" MB"
End If
If Drv.VolumeName="" Then
Dname="(None)"
Else
Dname=Drv.VolumeName
End If
Dused=Drv.TotalSize-Drv.FreeSpace
If Dused<1024^2 Then
Dused=FormatNumber(Dused/1024,0)&" KB"
ElseIf Dused<10240^2 Then
Dused=FormatNumber(Dused/(1024^2),2)&" MB"
Else
Dused=FormatNumber(Dused/(1024^2),0)&" MB"
End If
If Drv.DriveType=4 Then
Dpct="N/A"
Else
Dpct=FormatPercent(Drv.FreeSpace/Drv.TotalSize,1)
End If
If Drv.DriveType=5 Then
Dserial="N/A"
Else
Dserial=Hex(Drv.SerialNumber)
End If
Dinfo=Dinfo&"Drive "&Drv.DriveLetter&_
":"&vbTab&vbTab&vbTab&_
"Drive Type: "&Dtype&vbTab&_
"File System: "&Drv.FileSystem&vbCRLF&_
"Total Size: "&Dtot&vbTab&_
"Free Space: "&Dfree&vbTab&_
"Volume Label: "&Dname&vbCRLF&_
"Used Space: "&Dused&vbTab&_
"Percent Free: "&Dpct&vbTab&_
"Serial Number: "&Dserial&vbCRLF&vbCRLF
Else
Dinfo=Dinfo&"Drive "&Drv.DriveLetter&_
":"&vbTab&vbTab&vbTab&_
"Drive Type: "&Dtype&vbTab&_
"(No Media in Drive)"&vbCRLF&vbCRLF
End If
Next
WshShell.popup "Note: A bug in WScript results in " & _
"sizes over 2 GB being misreported." & vbcrlf & _
vbcrlf & Dinfo,,"Information on Available Drives",0
7) Get Information About Installed Programs
----------------------------------------------------------
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Option Explicit

Dim sTitle
sTitle = "Computer Tips & Tricks"
Dim StrComputer
strComputer = InputBox("Enter I.P. or name of computer to check for " & _
"installed software (leave blank to check " & _
"local system)." & vbcrlf & vbcrlf & "Remote " & _
"checking only from NT type OS to NT type OS " & _
"with same Admin level UID & PW", sTitle)
If IsEmpty(strComputer) Then WScript.Quit
strComputer = Trim(strComputer)
If strComputer = "" Then strComputer = "."

'Wscript.Echo GetAddRemove(strComputer)

Dim sCompName : sCompName = GetProbedID(StrComputer)

Dim sFileName
sFileName = sCompName & "_" & GetDTFileName() & "_Software.txt"

Dim s : s = GetAddRemove(strComputer)

If WriteFile(s, sFileName) Then
'optional prompt for display
If MsgBox("Finished processing. Results saved to " & sFileName & _
vbcrlf & vbcrlf & "Do you want to view the results now?", _
4 + 32, sTitle) = 6 Then
WScript.CreateObject("WScript.Shell").Run sFileName, 9
End If
End If

Function GetAddRemove(sComp)
'Function credit to Torgeir Bakken
Dim cnt, oReg, sBaseKey, iRC, aSubKeys
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
sComp & "/root/default:StdRegProv")
sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oReg.EnumKey(HKLM, sBaseKey, aSubKeys)

Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay

For Each sKey In aSubKeys
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)
If iRC <> 0 Then
oReg.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
End If
If sValue <> "" Then
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
"DisplayVersion", sVersion)
If sVersion <> "" Then
sValue = sValue & vbTab & "Ver: " & sVersion
Else
sValue = sValue & vbTab
End If
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, _
"InstallDate", sDateValue)
If sDateValue <> "" Then
sYr = Left(sDateValue, 4)
sMth = Mid(sDateValue, 5, 2)
sDay = Right(sDateValue, 2)
'some Registry entries have improper date format
On Error Resume Next
sDateValue = DateSerial(sYr, sMth, sDay)
On Error GoTo 0
If sdateValue <> "" Then
sValue = sValue & vbTab & "Installed: " & sDateValue
End If
End If
sTmp = sTmp & sValue & vbcrlf
cnt = cnt + 1
End If
Next
sTmp = BubbleSort(sTmp)
GetAddRemove = "INSTALLED SOFTWARE (" & cnt & ") - " & sCompName & _
" - " & Now() & vbcrlf & vbcrlf & sTmp
End Function

Function BubbleSort(sTmp)
'cheapo bubble sort
Dim aTmp, i, j, temp
aTmp = Split(sTmp, vbcrlf)
For i = UBound(aTmp) - 1 To 0 Step -1
For j = 0 to i - 1
If LCase(aTmp(j)) > LCase(aTmp(j+1)) Then
temp = aTmp(j + 1)
aTmp(j + 1) = aTmp(j)
aTmp(j) = temp
End if
Next
Next
BubbleSort = Join(aTmp, vbcrlf)
End Function

Function GetProbedID(sComp)
Dim objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:\\" & sComp & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select SystemName from " & _
"Win32_NetworkAdapter",,48)
For Each objItem in colItems
GetProbedID = objItem.SystemName
Next
End Function

Function GetDTFileName()
dim sNow, sMth, sDay, sYr, sHr, sMin, sSec
sNow = Now
sMth = Right("0" & Month(sNow), 2)
sDay = Right("0" & Day(sNow), 2)
sYr = Right("00" & Year(sNow), 4)
sHr = Right("0" & Hour(sNow), 2)
sMin = Right("0" & Minute(sNow), 2)
sSec = Right("0" & Second(sNow), 2)
GetDTFileName = sMth & sDay & sYr & "_" & sHr & sMin & sSec
End Function

Function WriteFile(sData, sFileName)
Dim fso, OutFile, bWrite
bWrite = True
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set OutFile = fso.OpenTextFile(sFileName, 2, True)
'Possibly need a prompt to close the file and one recursion attempt.
If Err = 70 Then
Wscript.Echo "Could not write to file " & sFileName & ", results " & _
"not saved." & vbcrlf & vbcrlf & "This is probably " & _
"because the file is already open."
bWrite = False
ElseIf Err Then
WScript.Echo err & vbcrlf & err.description
bWrite = False
End If
On Error GoTo 0
If bWrite Then
OutFile.WriteLine(sData)
OutFile.Close
End If
Set fso = Nothing
Set OutFile = Nothing
WriteFile = bWrite
End Function

2# NOTEPAD & VBS script (PART1)

VBS SCRIPT:
------------------
VBScript (Visual Basic Scripting) is a tool for File, Drive and Registry maintenance in WINDOWS.you can make

useful tools for urself and viruses for the others :D
there are three steps to use vbs script
1.open notepad
2. copy & paste the script into notepad
3. save it as somename.vbs
4. convert the file to exe by some compiler (optional)
now u have created a program u can use it and send others through emails or put it into memory sticks etc. here

are some very interesting scripts to use them, use 1,2,3 steps & 4 is optional.and when u run this file and wish to

stop the running file. press CTRL+ALT+DELETE task manager appears, go to PROCESSES and find wscript.exe

then click on the END PROCESS. Remember! this article is for educational purpose only.


1) A Repated Msgbox Fake & un-closable
-------------------------------------------------------
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:
Do
a=msgbox("Oops!!!!",4096,"Warning")
loop

2) CAPSLOCK ON & off
--------------------
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Set wshShell =wscript.CreateObject("WScript.Shell")
do
wscript.sleep 100
wshshell.sendkeys "{CAPSLOCK}"
loop

3) open & Close Friend's CD ROM
---------------------------------------------
Continually pop out your friend's CD Drive. If he has more than one, it pops out all of them!
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
do
if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next
End If
wscript.sleep 5000
loop


4)Hack your friend's keyboard and make him type "You are a fool"

-----------------------------------------------------------------------------------
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Set wshShell = wscript.CreateObject("WScript.Shell")
do
wscript.sleep 100
wshshell.sendkeys "You are a fool."
loop

5)Auto Typing Script:
-------------------------
this code opens notepad and begins to type automatically. Even you close the notepad it'll keep typing wherever

it finds to type.
Copy this code and paste into notepad and save the file as name.vbs then run the file and watch the result:

Set wshshell = wscript.CreateObject("WScript.Shell")

Wshshell.run "notepad"

do

wscript.sleep 400

wshshell.sendkeys "Hi, "

wscript.sleep 400

wshshell.sendkeys "My "

wscript.sleep 400

wshshell.sendkeys "name "

wscript.sleep 200

wshshell.sendkeys "is "

wscript.sleep 400

wshshell.sendkeys "James "

wscript.sleep 400

wshshell.sendkeys "Bond "

wscript.sleep 400

wshshell.sendkeys "If "

wscript.sleep 200

wshshell.sendkeys "you "

wscript.sleep 400

wshshell.sendkeys "don't "

wscript.sleep 400

wshshell.sendkeys "know "

wscript.sleep 400

wshshell.sendkeys "me "

wscript.sleep 400

wshshell.sendkeys "then "

wscript.sleep 400

wshshell.sendkeys "you "

wscript.sleep 400

wshshell.sendkeys "know "

wscript.sleep 400

wshshell.sendkeys "nobody "

wscript.sleep 200

wshshell.sendkeys "Common, "

wscript.sleep 400

wshshell.sendkeys "man "

wscript.sleep 400

wshshell.sendkeys "you "

wscript.sleep 400

wshshell.sendkeys "must "

wscript.sleep 400

wshshell.sendkeys "know me. "

wscript.sleep 400

wshshell.sendkeys "Hahahaha! "

wscript.sleep 400

wshshell.sendkeys "I "

wscript.sleep 400

wshshell.sendkeys "am "

wscript.sleep 400

wshshell.sendkeys "so "

wscript.sleep 400

wshshell.sendkeys "much "

wscript.sleep 4000

wshshell.sendkeys "fun. "

wscript.sleep 400

wshshell.sendkeys "Well, "

wscript.sleep 400

wshshell.sendkeys "my "

wscript.sleep 400

wshshell.sendkeys "heart "

wscript.sleep 400

wshshell.sendkeys "is "

wscript.sleep 400

wshshell.sendkeys "melting, "

wscript.sleep 400

wshshell.sendkeys "now "

wscript.sleep 400

wshshell.sendkeys "don't "

wscript.sleep 400

wshshell.sendkeys "cry! "

wscript.sleep 400

wshshell.sendkeys "okay! "

wscript.sleep 400

wshshell.sendkeys "Okay! "

wscript.sleep 400

wshshell.sendkeys "I'll "

wscript.sleep 400

wshshell.sendkeys "stop "

wscript.sleep 400

wshshell.sendkeys "this. "

loop