We help IT Professionals succeed at work.
Get Started

can this macro be converted to sub procedure

183 Views
Last Modified: 2017-05-11
i got this code referred by aikimark from https://gallery.technet.microsoft.com/scriptcenter/191eb207-3a7e-4dbc-884d-5f4498440574

now i want to use this as sub procedure

so that instead of strFileToToss = "C:\Test\trash.txt"

i can use   strFileToToss("C:\Test\trash.txt")

strFileToToss = "C:\Test\trash.txt" 
 
 
Const HKEY_CURRENT_USER = &H80000001 
strComputer = "." 
 
Set fso = CreateObject("Scripting.FileSystemObject") 
 
If Not fso.FileExists(strFileToToss) Then 
   WScript.Quit 
End If 
 
If fso.GetExtensionName(strFileToToss) = "exe" Then 
   WScript.Quit 
End If 
 
strFolderParent = fso.GetParentFolderName(strFileToToss) 
strFileName = fso.GetFileName(strFileToToss) 
 
 
'   Make sure recycle bin properties are set to NOT display request for delete confirmation 
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _  
    strComputer & "\root\default:StdRegProv") 
  
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Explorer" 
strValueName = "ShellState" 
 
oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath, _ 
    strValueName,strValue 
 
strOrigBinSet = strValue(4) 
strValue(4) = 39 
 
errReturnA = oReg.SetBinaryValue _ 
   (HKEY_CURRENT_USER, strKeyPath, strValueName, strValue) 
 
 
'  Use the Shell to send the file to the recycle bin 
 
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(strFolderParent) 
Set objFolderItem = objFolder.ParseName(strFileName) 
 
objFolderItem.InvokeVerb("&Delete") 
 
 
'  Restore the User's Property settings for the Recycle Bin 
 
strValue(4) = strOrigBinSet 
errReturnB = oReg.SetBinaryValue _ 
   (HKEY_CURRENT_USER, strKeyPath, strValueName, strValue

Open in new window

Comment
Watch Question
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE