Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I use %SystemRoot% in a script?

Posted on 2011-02-15
1
Medium Priority
?
1,304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

721 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