Solved

VBS - Set objFile = objFSO.CreateTextFile -question-

Posted on 2011-02-22
5
1,553 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
ID: 34952101
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
ID: 34952140
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
ID: 34952185
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
ID: 34954774
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
ID: 34957810
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

770 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