Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I use %SystemRoot% in a script?

Posted on 2011-02-15
1
Medium Priority
?
1,306 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 71

Accepted Solution

by:
Qlemo earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2

877 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