Jump to content

Managing Spotify installations aka nuking them from orbit


BillGiles
 Share

Recommended Posts

Spotify can be a huge bandwidth hog and we don't allow it on our systems.

Here is my method for removing the executables and replacing their parent folders with locked files that prevent future installations. (I know,evil right?) the script reads from a .csv exported from sccm that is formatted as follows: Netbios Name|File Name|File Description|File Version|File Size|Modified Date|FilePath

.

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <IE.au3>
#include 'Permissions.au3' ;available here http://www.autoitscript.com/forum/topic/134508-set-acl-permissions-udf/
Global $PingResult
$oExcel = _ExcelBookOpen(@ScriptDir&"\SMSReportResults.csv");;Open Target .csv File
_ExcelSheetActivate($oExcel,"SMSReportResults");;Define Array
$Result=_ExcelReadSheetToArray($oExcel);Close Excel File
_ExcelBookClose($oExcel)
;####################################################################################################
Func Pinger($PcName);DOES IT PING?
$PingResult = 0 ;resets to NO PING
$var1 = Ping($PcName, 500) ;performs the ping of $Data1
;MsgBox(0,$var1,$var1)
Sleep(1000) ;waits for ping to complete
If $var1 > 0 Then ;If it PINGS, then set YES
$PingResult = 1 ;SET PINGER = (1) YES
Else
$PingResult = 0 ;SET PINGER= (0) NO
EndIf
Return ($PingResult)
EndFunc   ;==>Pinger
;####################################################################################################
FileDelete(@ScriptDir&'\noping.log')
FileDelete(@ScriptDir&'\test.log')
FileDelete(@ScriptDir&'\folderdelete.bat')

For $i = 1 To Ubound($Result) -1
;$Result[$i][1] = PC Name
;$Result[$i][2] = Target file
;$Result[$i][7] = Path to Target file
Pinger($Result[$i][1]);Ping the target to see if it's online
$FileToDelete=("\\"&$Result[$i][1]&"\")&StringReplace($Result[$i][7],":\","$\")&($Result[$i][2]) ;MsgBox(0,$FileToDelete,$FileToDelete)
TraySetToolTip("Current Target: "&$FileToDelete) ;Tell interactive user what we're doing
If StringLeft($Result[$i][1],3)="MSU" Or "WPU" Then $PingResult=0 ;skip Distribution Point servers
If $PingResult = 1 Then;Is the target active?
If FileExists($FileToDelete) Then;If the file is actually present, perform the following
TraySetToolTip("Current Target: "&$FileToDelete)
Runwait(@ComSpec & " /c taskkill /s \\" & $Result[$i][1] & " /F /IM "&($Result[$i][2]), '', @SW_hide)
Sleep (3000)
FileDelete($FileToDelete);Get rid of the target file
FileWrite(@ScriptDir&"\Test.log", $I&" out of "&Ubound($Result)&@CRLF)
FileWrite(@ScriptDir&"\Test.log", $FileToDelete&@CRLF);Log the Result
$PathPreTrim=("\\"&$Result[$i][1]&"\")&StringReplace($Result[$i][7],":\","$\");modified to correctly handle drive letters other than C:\
$PathPostTrim=StringTrimRight($PathPreTrim,1)
If StringRight($PathPreTrim,8)=("Spotify\") then
$PathMinusSpotify=StringReplace($PathPreTrim,"Spotify\","");MsgBox (0,$PathMinusSpotify,$PathMinusSpotify)
FileWrite(@ScriptDir&"\FolderDelete.bat",'RMDIR "'&$PathPostTrim&'" /Q /S'&@CRLF);write batch file for directory removal
DirRemove($PathPostTrim,1)
FileCopy (@ScriptDir&"\Spotify",$PathMinusSpotify,1) ;Wipe Out directory for spotify, replace it with lockfile
;set rights
$oName=$PathMinusSpotify&"\Spotify"
$_SE_OBJECT_TYPE = $SE_FILE_OBJECT
$SetOwner = 'Administrators'
Local $aPerm[1][3]
$aPerm[0][0] = 'Administrators'
$aPerm[0][1] = 1
$aPerm[0][2] = $GENERIC_ALL
$Recurse=1
_SetObjectPermissions($oName, $aPerm, $_SE_OBJECT_TYPE, $SetOwner, 1, $Recurse)
EndIf
EndIf
Else
_FileWriteLog(@ScriptDir&'\noping.log', $Result[$i][1])
EndIfNext
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...