Solved

How can I use %SystemRoot% in a script?

Posted on 2011-02-15
1
1,299 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:a1doors1
1 Comment
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 34902835
One way is to use something along
   root = WshShell.ExpandEnvironmentStrings("%systemroot%")
and then
   objFSO.DeleteFile(root & "\Prefetch\*.*"), DeleteReadOnly
aso.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now