Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete file remote workstations

Status
Not open for further replies.

SysAdmin3000

Technical User
Aug 15, 2006
15
US
I am new to the scripting world and I need a script that will delete a file on each workstation. I have been trying to figure it out but...err..ahhh...I am lost as heck....

strComputer = "."
Win32_Directory.Name='%systemroot%\system32\drivers\etc'
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
objFile = hosts


For Each objFile
objFile.Delete

I know I need to replace the "." with the string of workstations.

I tried to set the path to %systemroot% as some machines have there root windir in different locations.

The file I need to delete is the hosts file in that directory.

I am trying to figure this out by reading over the MS scripting site and thought I should stop by here as well.

thanks in advance,
sysadmin3000
 
Why not add a login script to do it?

Code:
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Windir = WshShell.ExpandEnvironmentStrings("%WinDir%")
If oFSO.FileExists(Windir & "\System32\Drivers\Etc\Hosts") Then
	oFSO.DeleteFile(Windir & "\System32\Drivers\Etc\Hosts")
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
I have a login script already. I thought that this would be a simple, hopefully, script it would be a good place to start learning.

I have several login scripts and GPO's running. Trying to replicate what some of them do via vbscript gives me the ability to compare the 2 and more understanding.



Thanks Mark


 
And for removal of system file I'd use a startup script instead of a login script ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top