|
Answer» I believe I have this finished, but I just want to make sure that I didn't make any stupid mistakes that are not easy for me to spot, as I don't really know vbs. thanks for looking and I hope I did everything correctly.
CODE: [Select]Const ForReading = 1
strComputer = "." i=0 'Set the Path to the source files here. 'It is very important as it will carefully delete inside the windows and program files directories
Set locationPath = ""
'That is the only VARIABLE that needs to be set Set fso = CreateObject("Scripting.FileSystemObject") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set f = fso.OpenTextFile("H:\gameLocations\gameList.txt", ForReading)
Do Until f.AtEndOfStream = True retString = f.ReadLine fname = Split(retstring, ".")(0) fext = Split(retString, ".")(1) sName = Split(retString, ":")(1) Set colFiles = objWMIService.ExecQuery _ ("Select * From CIM_DataFile Where FileName = '" & fname & "'" & " and Extension = " & "'" & fext & "'" & "") 'WScript.Echo "Searching for " & retstring For Each objFile in colFiles If InStr(1, objFile.Caption, "c:\windows") > 0 Then WScript.Echo retstring & " Found In Windows...Carefully Deleting" 'Here is the start of my delete script searchFileString = locationPath & sName & ".txt" If fso.FileExists(searchFileString) Then WScript.Echo searchFileString Set d = fso.OpenTextFile(searchFileString, ForReading) Do Until d.AtEndOfStream = True folderName = d.ReadLine folderPath = objFile.Path & folderName strFolder = objFile.Drive & folderPath fileName = fso.GetFile(strFolder) WScript.Echo fileName 'fileName.Delete 'Here is the end of my test script. Loop Else Wscript.Echo "File " & searchFileString & " does not exist, skipping" End If i=i+1 Else If InStr(1, objFile.Caption, "c:\program files") > 0 Then WScript.Echo retstring & " Found In Program Files...Carefully Deleting" 'Here is the start of my delete script searchFileString = locationPath & sName & ".txt" If fso.FileExists(searchFileString) Then WScript.Echo searchFileString Set d = fso.OpenTextFile(searchFileString, ForReading) Do Until d.AtEndOfStream = True folderName = d.ReadLine folderPath = objFile.Path & folderName strFolder = objFile.Drive & folderPath fileName = fso.GetFile(strFolder) WScript.Echo fileName 'fileName.Delete 'Here is the end of my test script. Loop Else Wscript.Echo "File " & searchFileString & " does not exist, skipping" End If i=i+1 Else WScript.Echo retstring & " Found In " & objFile.Drive & objFile.Path WScript.Echo "Removing Files/Folder " & objFile.Drive & objFile.Path strFolder = Left(objFile.Drive & objFile.Path, Len(objFile.Drive & objFile.Path) - 1) WScript.Echo "Maybe I will code something to delete all the individual files?" fso.DeleteFolder strFolder, True End If End If Next Loop If i > 0 Then msgbox "Alert!, Found something in the windows directory or the program files." & Chr(13) & Chr(13) & "You might want to reimage the computer to take care of the problem. Should of been taken care of, but there was a chance of possible CORRUPTION of that folder" Else msgbox "Success, Computer is clean." End If f.Close Better than any human, the VBScript interpreter will be more than happy to point out your errors.
fso.deletefolder is a powerful and destructive method. Not only will it delete a folder and all it's subfolders, but also the files within. Personally I would temporarily replace that instruction with wscript.echo statements and watch how the file runs.
Only after you're completely satisfied with your results, should fso.deletefolder be activated. FYI, file and folders deleted in VBScript do NOT make a pit stop in the recycle bin. Backing up your system might be prudent.
Good luck.
Not quite sure what the code blocks 'Here is the start of my delete script are doing but when you activate the command 'fileName.Delete, the correct format is fso.DeleteFile filename, Trueit currently has the WScript.Echo in place.
And yes, I do understand that when you delete the file, it goes into oblivion. But this script is going to be used in a major school system and only having to reimage like 1 out of every 15 or 30 computers isn't bad compared to the original plan which was reimage each computerElse WScript.Echo retstring & " Found In " & objFile.Drive & objFile.Path WScript.Echo "Removing Files/Folder " & objFile.Drive & objFile.Path strFolder = Left(objFile.Drive & objFile.Path, Len(objFile.Drive & objFile.Path) - 1) WScript.Echo "Maybe I will code something to delete all the individual files?" fso.DeleteFolder strFolder, True
The highlighted line was the one I was referring to.
Quote But this script is going to be used in a major school system and only having to reimage like 1 out of every 15 or 30 computers isn't bad compared to the original plan which was reimage each computer
If the alternative to the script is a re-imaging, then go for it! If it fails, you do the re-image, tweak the script and move on. If it works you'll be a hero.
Good luck.
Just curious, but aren't there ways to prevent students from installing software on school computers?its not really installing, what they are doing is copying files over, then logging off. Once that is done everybody can play the game, except it can't be deleted as the owner has "changed" according to Novell and the only ones who can delete the files are administrators and most don't have the time to go and clean each computer. So this way, they can log in on an entire lab, run this script and call it a day.
But to make their life more difficult, I am going to ask if they want to SHOW the owner of a file. Now I am running this test
Code: [Select]if (showName == "yes") OR showName == 'y' OR showName == 'Y') Then WScript.Echo "Yes" Else If (showName == "no") OR showName == 'n' OR showName == 'N') Then WScript.Echo "No" End If
But there is a syntax ERROR and I am not sure. It says like 14 (first line shown) column 15 which is the second = sign. Now I could probably open a new topic, but its the same general concept here. I made a mistake and am not sure what it is.
and that line that you highlighted was from your original code. I left that part intact. I trust that part.At first I thought I was looking at batch code.
Code: [Select]If (showName = "yes" OR showName = "y" OR showName = "Y") Then WScript.Echo "Yes" Else If (showName = "no" OR showName = "n" OR showName = "N") Then WScript.Echo "No" End If End If The code aligns better in an editor than in the forum. ya i learned, fixed my program on my own and turned it in. Thanks for your help my "boss" i say that loosely was really pleased with how it works. I added a question in the batch that says display file owner and it works like a charm.
|