Delete files VBSCRIPT With exit codes to implement on sccm 2012 deployment

vbscript-imagen

Hi to all

Today  I’ll post a Vbscript that is able to send Info to Sccm2012 deployments on the “monitoring” space you will be able to read the messages depending of the exit code that you have used

First , you can get entire codes here

Once you have the codes , let’s begin with a simple “delete files script”, this simple script deletes a file on the  user profile

The trick is on the wscript.quit(0) where wscript.quit(Error code what you want) , will able you to handle what happened when you launch the script , nice right ? 😀

Sccm will show you on the monitoring the code what you writed on the script


Set objNetwork = CreateObject(“Wscript.Network”)
” Script shell
Set oShell = CreateObject(“WScript.Shell”)
” Filesistem object
set filesys=CreateObject(“Scripting.FileSystemObject”)

” if exist function
function folder_exist (folder)
dim returnvalue
If filesys.FolderExists(folder) Then
returnvalue = “true”
else
returnvalue = “false”
End if
folder_exist = returnvalue
End function

” get the user profile
strHomeFolder = oShell.ExpandEnvironmentStrings(“%USERPROFILE%”)
folderx = “\AppData\Local\Cisco\Unified Communications\Jabber\CSF\Contacts”
folder = strHomeFolder & folderx
” If folder doesn’t exist  I exit and wscript returns OK ,we won’t do anything

if (folder_exist(folder) = “false”) then
”error code ”
wscript.quit(2)
else
end if

” If the  folder exist i will delete and show another code

Set folderdelete = filesys.GetFolder(folder)
if (folder_exist(folder) = “true”) then
filesys.DeleteFile(folderdelete),DeleteReadOnly
filesys.DeleteFolder(folderdelete),DeleteReadOnly
end if
” checking of the delete
if (folder_exist(folder) = “false”) then
” ok
wscript.quit(0)
else
” If there is a error i will return code 1603
wscript.quit(1603)

end if


remember the other trick  : To run the script on a deployment must use the option ” RUN PROGRAM FROM DP” lal

Have a nice day !!


Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.