Link to home
Start Free TrialLog in
Avatar of a1doors1
a1doors1

asked on

How can I use %SystemRoot% in a script?

Uncle!  I'm not a programmer and someone else wrote this originally.  It's a script that runs weekly to do clean-up on our computers (this is just one section) Most of the machines are "clean" installs of WinXP... but... I have a few that are upgrades.  Therefore, the upgrade machines have "WINNT" as the SystemRoot name.  The script will, obviously, not run on these machines since the code references the path "C:\Windows....".  Is there a way to return the %SystemRoot% name and use it in the path shown in the code below.  Finding a way would add a few years to my lifetime as I have been searching for weeks.
Sub sbDefrag()
	set WshShell = CreateObject("WScript.Shell")
	Dim WshShell, Result, objFSO, objNetwork

	Result = WshShell.Popup("Weekly Computer Maintenance Is Being Preformed Please Do Not Log onto this Machine!  The I.T. Department.", 10, "Title", 65)

If result = 1 or Result = -1 THEN	
	set WshShell = CreateObject("WScript.Shell")

	'Runs a clean up on the C: Drive	
	WshShell.Run "cleanmgr /sagerun:100"
	WScript.Sleep 5000

	'Cleans out the WIndows XP Prefetch directory
	Const DeleteReadOnly = True
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	objFSO.DeleteFile("C:\WINDOWS\Prefetch\*.*"), DeleteReadOnly
	objFSO.DeleteFile("C:\WINDOWS\Prefetch\*"), DeleteReadOnly

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial