[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 728
  • Last Modified:

Error Creating a folder under Program Files in command prompt or script

When I am looged into a Windows 7 PC as a Domain Administrator, I can create a folder under C:\Program Files using the Windows Explorer interface.

However, when I try and create a folder in a Command prompt under C:\Program Files, I get "Access Denied". I also get an access denied error when creating a folder under C:\Program Files using a Powershell or VB Script.

How do I overcome this problem? I specifically want to be able to create a directory using Powershell

e.g.    New-Item "C:\Program Files\BGInfo" -type directory
0
APAGroup
Asked:
APAGroup
  • 3
  • 3
  • 2
  • +1
1 Solution
 
kortinaCommented:
You might find that UAC (User Account Control) is getting you.

Try run a command prompt as administrator. Not just running cmd, you need to click Start, Accessories, Command Prompt. Right Click and choose "Run as Administrator"

When the command prompt runs the title should say "Administrator:Command Prompt"

Then try run your powershell script or use mkdir to create your folder.

Likewise, your powershell environment might not be starting as admin.
0
 
APAGroupAuthor Commented:
Hi Kortina
You are right. If I log into Windows 7 as a standard user and right click on the Command Prompt and select "Run as Administrator" and put in the domain administrator credentials, I can create the folder.
However, that still leaves me with the problem of how to start my scripting environment programatically as Admin.
 
0
 
beanrodCommented:
runas /user:"Domain\administrator"  cmd
will open a cmd prompt or substitute cmd for the program or call your batch scipt...
runas /? will give you the full options
The problem is it will still prompt for a password
You could try this free program that behaves similaly to runas with an encrypted password
http://www.commandline.co.uk/sanur/ 
Good luck
0
Technology Partners: 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!

 
McKnifeCommented:
I think beanrod meant to link runasspc as sanur does not even use encryption. But both don't elevate.
--
It is a bad practice to write into program files - avoid it if possible.
Are you trying to create a script that your clients will use?
0
 
beanrodCommented:
This will only be relevant if you want BGINFO in a Domain envronment works on all versions of Windows I've tested...
If you want you to use Group Policy you could create a "log on" script. At my workplace I have implemented a VB startup script that loads bginfo from a serverlocation rather than a local location.
I have customised settings and need not deploy the physical install. In a multi Domain Controller envirnoment simply put it in the SYSVOL share and it will pick the DC based on a least cost route. So if it is for BGINFO if "Authenticated Users" have Read & Execute permissions you get a nice BGINFO background. Very handy when you can't remember peoples names. :)

Create a document and rename it to "Scirptname.vbs"
Copy and paste below code and change the directories as you see fit...
The CCsettings.bgi is a saved file of custom config settings for BGinfo.

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "\\Servername\Netlogon\BGinfo\BGinfo.exe \\ServerName\Netlogon\BGinfo\CCSettings.bgi /accepteula /timer:0", 1, True
0
 
McKnifeCommented:
wrong thread?
0
 
beanrodCommented:
To MCKnife, Umm well he did mention BGinfo so I thought perhaps he needed the elevated priveledges to have local copies of BGinfo. You are right will probably no good APAGroup but thought I would share just on the off chance that it may help. Thanks for pointing out that SANUR wouldn't work must be getting tired, I typically use "Start-Up" scripts not to be confused with "logon scripts" to get elevated rights as they run in the system context but that is going off on another tangent.
0
 
kortinaCommented:
You could try the suggestion here:
http://stackoverflow.com/questions/1566969/showing-the-uac-prompt-in-powershell-if-the-action-requires-elevation

I havent used it myself.

Depending on how you plan to run your powershell script you could always right click on the script and choose run as admin.
0
 
APAGroupAuthor Commented:
I need to run the script unattended during the setup of the environment.
These links seem like they might hold the solution.
http://www.peterprovost.org/blog/post/Powershell-Sudo-(sort-of)-for-Vista-UAC.aspx
http://www.peterprovost.org/blog/post/Shifting-Powershell-Arrays.aspx
 
0
 
APAGroupAuthor Commented:
I am away for a Christmas break but will be back onto this issue in the New Year.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now