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

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"

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
Who is Participating?
X_layerConnect With a Mentor Commented:
Program files folder in Win7 is rather restricted. I suggest you, that you create this INI file inside users app folder (%APPDATA%).
Could you please check with your user id has admin rights ?
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.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

New_AlexAuthor Commented:
Hi guys, is it possible to do it using vbScript, because I plan to share the code freely to many people.
New_AlexAuthor Commented:
Yes. This is a good idea

Thanks matey
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.