Solved

How can I use %SystemRoot% in a script?

Posted on 2011-02-15
1
1,295 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 68

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

13 Experts available now in Live!

Get 1:1 Help Now