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

Posted on 2011-10-14
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"

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
Question by:New_Alex
    LVL 2

    Expert Comment

    Could you please check with your user id has admin rights ?
    LVL 2

    Expert Comment

    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.
    LVL 1

    Author Comment

    Hi guys, is it possible to do it using vbScript, because I plan to share the code freely to many people.
    LVL 11

    Accepted Solution

    Program files folder in Win7 is rather restricted. I suggest you, that you create this INI file inside users app folder (%APPDATA%).
    LVL 1

    Author Closing Comment

    Yes. This is a good idea

    Thanks matey
    LVL 65

    Expert Comment

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
    This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    758 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

    14 Experts available now in Live!

    Get 1:1 Help Now