Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


vbscript to delete specific files

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,63243
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> vbscript to delete specific files
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 vbscript to delete specific files - 8/7/2008 9:22:44 AM   
  adamhaskins

 

Posts: 5
Score: 0
Joined: 8/7/2008
Status: offline
I have created a vbscript "first time scripting" which goes to a certain directory, checks if files exist, and if so deleted the files. I created this for EPOP because we have sharing license issues which requires us to delete 4 specific files in order to hand out new licenses, Anywayz, I got the script working just fine when I link it in a computer configuratiuon start up script in the GPO. However I can not apply it as a user configuration logon script for the users because they do not have access somewhere in the GPO to delete files. It may also be a epop issue. Is there anyway for me to run this script with system rights or admin rights even though a user with no rights at all is logging in? We can not give these users rights at all and these files need to be deleted each time they login for epop to work.

The next question I have is. At the start of this script I want the script to check all 4 files BEFORE they are deleted to check for when they were created and the last time they were modified. I also want a log saved in c:\TeCH BEFORE it deletes the files. This way we can look at the log if we have issues to make sure the files were deleted and to check when the old one was last modified/created

I know the naming for the two objects such as filelastmodified ect. But Im having a hard time putting it all together. Please help!! :) The script I wrote is below. Please dont laugh.


'***** Notes:****************************************************************************************'*****************
'Initial release of script is 08/1/2008
'
'Created by: Adam Haskins
'
'Purpose: Delete E-POP Cached files in C:\tech to resolve license issue.
'
'Updates:
'
'*********************************************************************************************************************************
'
Dim fso,MyFile,filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
Set fso = CreateObject("Scripting.FileSystemObject")

REM Deletes MyShortcuts.IDX
If filesys.FileExists("c:\tech\MyShortcuts.IDX") Then 
   Set MyFile = fso.GetFile("c:\tech\MyShortcuts.IDX")
MyFile.Delete
end if
REM Deletes MyShortcuts.DAT
If filesys.FileExists("c:\tech\MyShortcuts.DAT") Then
    Set MyFile = fso.GetFile("c:\tech\MyShortcuts.DAT")
MyFile.Delete
end if
REM Deletes MyIdentity.IDX
If Filesys.FileExists("c:\tech\MyIdentity.IDX") then
   Set MyFile = fso.GetFile("c:\tech\MyIdentity.IDX")
MyFile.Delete
end if
REM Deletes MyIdentity.DAT
If Filesys.FileExists("c:\tech\MyIdentity.Dat") then
   Set MyFile = fso.GetFile("c:\tech\MyIdentity.DAT")
MyFile.Delete
end if


Thanks alot,

Adam Haskins

< Message edited by adamhaskins -- 8/7/2008 9:27:29 AM >
 
 
Post #: 1
 
 RE: vbscript to delete specific files - 8/9/2008 8:35:04 PM   
  ninjamaster

 

Posts: 107
Score: 0
Joined: 1/23/2007
Status: offline
As the 4 file names are static why not load the names into an array? Now that you have them loaded in you can cycle through the array and do whatever you want with the files.

Will make you code shorter and easier.

(in reply to adamhaskins)
 
 
Post #: 2
 
 RE: vbscript to delete specific files - 8/9/2008 10:02:23 PM   
  TomRiddle


Posts: 191
Score: 4
Joined: 2/7/2008
Status: offline
quote:

because they do not have access somewhere in the GPO to delete files


Group policy is blocking your users ability to delete files or is it NTFS permissions?

Log in as one of your users and run the script, that will tell you if it is a permission issue or something else.

I have not run the script but at a glance it looks ok, I assume it works when you as an admin click on it.

(in reply to adamhaskins)
 
 
Post #: 3
 
 RE: vbscript to delete specific files - 8/10/2008 11:24:14 AM   
  adamhaskins

 

Posts: 5
Score: 0
Joined: 8/7/2008
Status: offline
Ok below is my updated script which works great as a Startup script. When I use it on the machines it does exactly what i want it to do. Thing is I need this script to run at each login instead of when the computer starts up. I made a GPO which works fine at startup, but when I try to do it as "login" it gives me a "access denied" when the script tries to delete files. So its obviously a permission issue. I work at a bigger company which has 500 users. Thing is we dont give them access to do anything besides what they need. So everything is locked down where they are not allowed to delete files or even look at any of the drives ect. All they have on there start menu are the programs they need to work effectively. I gave the users full access to the tech directory with full control rights, but the PC still isnt letting the script run. So i just assumed its something that is set it Group policy not allowed these users to delete the files. Does anyone have any idea where i could check or what I could do to give these users access to delete the files in the c:\tech directory? Any help would be appreciated.

'***** Notes:****************************************************************************************'*****************
'Initial release of script is 08/1/2008
'
'Created by: Adam Haskins
'
'Purpose: Delete E-POP Cached files in C:\tech to resolve license issue.
'
'Updates:
'
'*********************************************************************************************************************************
'
Dim MyFile, filesys, oLogFile, objName, strComp, nLogFile
Dim fso2, strText
Set filesys = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Set oLogFile= filesys.OpenTextFile("c:\tech\EPOPCLRCach.log", ForAppending, True)
Set objName = CreateObject("WScript.NetWork")
' Set computer name of PC script is running on
strComp = objname.ComputerName
Set nLogfile = filesys.OpenTextFile("Private}\Machine" & strComp & ".txt", ForAppending, True)
REM Deletes MyShortcuts.IDX
If filesys.FileExists("c:\tech\MyShortcuts.IDX") Then 
Set MyFile = filesys.GetFile("c:\tech\MyShortcuts.IDX")
oLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
nLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
MyFile.Delete
end if
REM Deletes MyShortcuts.DAT
If filesys.FileExists("c:\tech\MyShortcuts.DAT") Then
       Set MyFile = filesys.GetFile("c:\tech\MyShortcuts.DAT")
oLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
nLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
MyFile.Delete
end if
REM Deletes MyIdentity.IDX
If Filesys.FileExists("c:\tech\MyIdentity.IDX") then
Set MyFile = filesys.GetFile("c:\tech\MyIdentity.IDX")
oLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
nLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
MyFile.Delete
end if
REM Deletes MyIdentity.DAT
If Filesys.FileExists("c:\tech\MyIdentity.Dat") then
Set MyFile = filesys.GetFile("c:\tech\MyIdentity.DAT")
oLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
nLogFile.writeLine(now & ": Deleted File " & myFile.shortname & " last modified " & MyFile.DateLastModified)
MyFile.Delete
end if
oLogFile.Close

< Message edited by adamhaskins -- 8/10/2008 11:28:28 AM >

(in reply to TomRiddle)
 
 
Post #: 4
 
 RE: vbscript to delete specific files - 8/10/2008 11:39:23 AM   
  adamhaskins

 

Posts: 5
Score: 0
Joined: 8/7/2008
Status: offline
I have searched through the GP and I dont see any way to block users from deleting diles ect, which I didn't think it was possible through GP. So Im guessing it has to be thru NTFS permissions. Its just wierd because All agents are members of a group who has full access to c:\tech. Still no luck. YET lol. Im sure I can figure it out, but any help would be appreciated

(in reply to adamhaskins)
 
 
Post #: 5
 
 RE: vbscript to delete specific files - 8/10/2008 11:56:00 AM   
  adamhaskins

 

Posts: 5
Score: 0
Joined: 8/7/2008
Status: offline
I think I may have figured it out. Even though the "Everyone" grpup has full control The USERS group does not. I will be testing this tommorrow to see if it fixes the issue

(in reply to adamhaskins)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> vbscript to delete specific files Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts