Solved

VBS - Set objFile = objFSO.CreateTextFile -question-

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Utilizing an array to gracefully append to a list of EmailAddresses
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 …

948 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

19 Experts available now in Live!

Get 1:1 Help Now