Solved

VBS - Set objFile = objFSO.CreateTextFile -question-

Posted on 2011-02-22
5
1,531 Views
Last Modified: 2012-05-11
Hi,

The following code creates the STRfootprintQT1 file on the C:\ root

Set objFile = objFSO.CreateTextFile(strFootprintQT1, True)

Is there any way to change this code so that the STRfootprintQT1 is created under the user %appdata% and placed on folder named FOOTPRINT.

The folder FOOTPRINT does not exist and it will need to be created the first time the script runs.
Set objShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

strFootprintQT1 = strAppData & "\QUICKTIMEQTPlayer.dat"
strFootprintQT2 = strAppData & "\QUICKTIMEQTP.dat"
strUserDir = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")


If objFSO.FileExists(strFileQT) = True Then
	If objFSO.FileExists(strFootprintQT1) = False Then
		objFSO.CopyFile strRegFileQT1, strAppData & "\Apple Computer\QuickTime\"
		Set objFile = objFSO.CreateTextFile(strFootprintQT1, True)

Open in new window

0
Comment
Question by:llarava
  • 2
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Looks to me as though the appdat needs to be be moved up a few lines then add a test for folder creation

Chris
Set objShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")
strFootprintQT1 = strAppData & "\QUICKTIMEQTPlayer.dat"
strFootprintQT2 = strAppData & "\QUICKTIMEQTP.dat"
strUserDir = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

if not objFSO.folderexists(strFootprintQT1) then
    objFSO.createfolder(strFootprintQT1)
end if

If objFSO.FileExists(strFileQT) = True Then
	If objFSO.FileExists(strFootprintQT1) = False Then
		objFSO.CopyFile strRegFileQT1, strAppData & "\Apple Computer\QuickTime\"
		Set objFile = objFSO.CreateTextFile(strFootprintQT1, True)

Open in new window

0
 
LVL 12

Expert Comment

by:prashanthd
Comment Utility
Hi,

try the following code
Set objShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Dim strAppData

strUserDir = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")
fp_folder=strAppData &"\FOOTPRINT"

If objfso.FolderExists() Then
	'WScript.Echo "Footprint folder already exists"
Else
	objfso.CreateFolder(fp_folder)
End If

strFootprintQT1 = fp_folder & "\QUICKTIMEQTPlayer.dat"
strFootprintQT2 = fp_folder & "\QUICKTIMEQTP.dat"

If objFSO.FileExists(strFileQT) = True Then
	If objFSO.FileExists(strFootprintQT1) = False Then
		objFSO.CopyFile strRegFileQT1, strAppData & "\Apple Computer\QuickTime\"
		Set objFile = objFSO.CreateTextFile(strFootprintQT1, True)

Open in new window

0
 
LVL 59

Expert Comment

by:Chris Bottomley
Comment Utility
Overlooked the footprint itself!

Chris
et objShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")
strFootprintQT1 = strAppData & "\footprint" & "\QUICKTIMEQTPlayer.dat"
strFootprintQT2 = strAppData & "\QUICKTIMEQTP.dat"
strUserDir = objShell.ExpandEnvironmentStrings("%USERPROFILE%")

if not objFSO.folderexists(strappdata & "\footprint") then
    objFSO.createfolder(strappdata & "\footprint")
end if

If objFSO.FileExists(strFileQT) = True Then
	If objFSO.FileExists(strFootprintQT1) = False Then
		objFSO.CopyFile strRegFileQT1, strAppData & "\Apple Computer\QuickTime\"
		Set objFile = objFSO.CreateTextFile(strFootprintQT1, True)

Open in new window

0
 

Author Comment

by:llarava
Comment Utility
Here is the code that I am using. I am having problems merging the code that you have specified above to mine.

The goal is to change the Set objFile = objFSO.CreateTextFile(strFootprintQT1, True) so that the STRfootprintQT1 and STRfootprintQT12 is created under the user %appdata% and placed on folder named FOOTPRINT.

The folder FOOTPRINT does not exist and it will need to be created the first time the script runs only if the If objFSO.FileExists(strFileQT) = True (the application exists)

Can you please help.  
Set objShell = CreateObject("WScript.Shell") 
Set objFSO = CreateObject("Scripting.FileSystemObject") 

strFileQT = "C:\Program Files\QuickTime\QuickTimePlayer.exe" 
strRegFileQT1 = "\\dc1\SYSVOL\syracuse.local\scripts\QTPlayerSession.xml"
strFootprintQT1 = strAppData & "\QUICKTIMEQTPlayer.dat"
strRegFileQT2 = "\\dc1\SYSVOL\syracuse.local\scripts\QuickTime.qtp"
strFootprintQT2 = strAppData & "\QUICKTIMEQTP.dat"
strUserDir = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")


If objFSO.FileExists(strFileQT) = True Then
	If objFSO.FileExists(strFootprintQT1) = False Then
		objFSO.CopyFile strRegFileQT1, strAppData & "\Apple Computer\QuickTime\"
		Set objFile = objFSO.CreateTextFile(strFootprintQT1, True) 
		objFile.Close 
	End If

	If objFSO.FileExists(strFootprintQT2) = False Then
		objFSO.CopyFile strRegFileQT2, strUserDir & "\Local Settings\Application Data\Apple Computer\QuickTime\"
		Set objFile = objFSO.CreateTextFile(strFootprintQT2, True) 
		objFile.Close  
	End if 
End If

Open in new window

0
 
LVL 12

Accepted Solution

by:
prashanthd earned 300 total points
Comment Utility
Try this code..

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

strFileQT = "C:\Program Files\QuickTime\QuickTimePlayer.exe"
strRegFileQT1 = "\\dc1\SYSVOL\syracuse.local\scripts\QTPlayerSession.xml"
strRegFileQT2 = "\\dc1\SYSVOL\syracuse.local\scripts\QuickTime.qtp"
strUserDir = objShell.ExpandEnvironmentStrings("%USERPROFILE%")
strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")

fp_folder=strAppData &"\FOOTPRINT"
If objfso.FolderExists() Then
      'WScript.Echo "Footprint folder already exists"
Else
      objfso.CreateFolder(fp_folder)
End If
strFootprintQT1 = fp_folder & "\QUICKTIMEQTPlayer.dat"
strFootprintQT2 = fp_folder & "\QUICKTIMEQTP.dat"


If objFSO.FileExists(strFileQT) = True Then
      If objFSO.FileExists(strFootprintQT1) = False Then
            objFSO.CopyFile strRegFileQT1, strAppData & "\Apple Computer\QuickTime\"
            Set objFile = objFSO.CreateTextFile(strFootprintQT1, True)
            objFile.Close
      End If

      If objFSO.FileExists(strFootprintQT2) = False Then
            objFSO.CopyFile strRegFileQT2, strUserDir & "\Local Settings\Application Data\Apple Computer\QuickTime\"
            Set objFile = objFSO.CreateTextFile(strFootprintQT2, True)
            objFile.Close  
      End if
End If
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to count occurrences of each item in an array.

763 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

7 Experts available now in Live!

Get 1:1 Help Now