Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBscript, Win7, FSO.CreateTextFile, Where is my Newly Created File?

Posted on 2011-10-14
6
Medium Priority
?
798 Views
Last Modified: 2012-05-12
Hi guys, I have Windows7 installed on my PC and my vbScript includes a Sub that attempts to create a new settings.ini file (with my program's settings) inside the "c:\program files\".

This is my code:

Sub CreateMyFile()

    Set oFSO = CreateObject("Scripting.FileSystemObject")
       
          sFilePath = "C:\Program Files\Vbsedit\settings.ini "
            Set FileObject = oFSO.CreateTextFile(sFilePath)
	      FileObject.WriteLine "Hello World"
	          FileObject.Close()

End Sub

Open in new window


The code does not give an error but I can not find the file "C:\Program Files\Vbsedit\settings.ini ". It is not get created.  Any ideas how I can make it work in folders like "C:\Program Files\" ???
Thank you
0
Comment
Question by:New_Alex
6 Comments
 
LVL 2

Expert Comment

by:rajvihari
ID: 36967345
Could you please check with your user id has admin rights ?
0
 
LVL 2

Expert Comment

by:rajvihari
ID: 36967357
Also check with :
Disable simple file sharing: in explorer, go to the 'Tools' menu and select 'Folder Options'. Select the 'View' tab and scroll to the bottom. Untick 'Use simple file sharing (recommended)'.

Right click on the 'Program Files' folder and select 'Properties'. Go to the 'Security' tab and select 'Advanced'. You can check the permissions of the admin account under 'Effective Permissions'.

If the admin account does not have 'full control' of the folder:

1) Check what permissions the admin user has in the 'Permissions' tab. In fact, the user name should not be present here at all. The only entries here should be for Administrators, CREATOR OWNER, System and Users. If the admin account is listed here with permissions other than 'Full control' you can either edit them to give the user full control or delete the restricting permissions all together.

2) Go to the 'Owner' tab, and verify which user or group is the owner of the folder. This should probably be set to Administrators. If not, select Administrators and apply.
0
 
LVL 1

Author Comment

by:New_Alex
ID: 36967473
Hi guys, is it possible to do it using vbScript, because I plan to share the code freely to many people.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Accepted Solution

by:
X_layer earned 2000 total points
ID: 36967545
Program files folder in Win7 is rather restricted. I suggest you, that you create this INI file inside users app folder (%APPDATA%).
0
 
LVL 1

Author Closing Comment

by:New_Alex
ID: 36967801
Yes. This is a good idea

Thanks matey
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36967806
As suggested, it is restricted, but if the script is running with admin rights, it should work.

If you run cmd.exe by right clicking, then Run As Administrator, then type
cscript C:\YourScript.vbs

Rob.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

810 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