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

x
?
Solved

VBS - Set objFile = objFSO.CreateTextFile -question-

Posted on 2011-02-22
5
Medium Priority
?
1,604 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 1200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

722 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