Solved

VBS - Set objFile = objFSO.CreateTextFile -question-

Posted on 2011-02-22
5
1,579 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
[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
  • 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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.
The viewer will learn how to count occurrences of each item in an array.
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 …

729 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