Access denied to file on windows 7 for Administrator account - windows

I want to delete my git repository (.git folder) created by git on my windows 7 box. It says access denied to .git/refs/header folder.
I open a console with Administrator role, issue command "takeown /F heads /A /R", it still says "ERROR: Access is denied.", neither can i do via GUI security dialog.
Any suggestion?
Regards,
Green

An access denied error may mean the file is in use by another process and, for a GIT repository, that seems more likely than a file permissions issue.
(I'm assuming GIT is like SVN where every file in the repository is created by your own account with standard permissions. If that's not the case then I may be wrong.)
As a first step, run Process Explorer as Administrator and push Ctrl-F to open a window where you can type the filename and see which processes (if any) have that file open.
When I say "run as Administrator":
I don't just mean when logged in as Administrator. Windows 7's UAC means Administrator accounts don't run things with full admin access by default. Right-click procmon.exe and choose the "Run as Administrator" option.
I assume you're already familiar with this from running the command prompt as admin. If you just changed to an admin account, but didn't use "Run as Administrator" on the command prompt, then that could be why the takeown command failed. The command prompt should say "Administrator:" in its window title if it is properly elevated, unless UAC is off entirely.
If one or more processes are listed, confirm the full file path in the list (in case some other file on disk has a similar name).
Close any processes which have the file open. Try to close them normally if you can. As a last resort you can end-task them. If it's a process running as another user/account, it might be a service which you can stop.
(Ensure View->Show Processes for All Users is ticked, then find the process in question via the PID column. If you think it's a service, hover the mouse over it and a tooltip will appear telling you the name(s) of any services it is running.)
If you cannot find any process accessing the file, or closing them all still results in an access denied error, and you are definitely trying the deletion from an elevated command prompt, then you might want to try telling Windows to delete the file the next time it is rebooted. You can use the SysInternals MoveFile tool for that.

Related

Trying to write a batch file to open programs as an administrator

I'm trying to write a batch file that will open computer management as an administrator (on a Windows 7 64 bit system). I have done this successfully with cmd but cannot get it to work with computer management.
The command I have for cmd is:
runas /profile /env /user:username#domain cmd
After I authenticate with my pw, I'm good to go.
The commands I've tried for computer mgmt are:
runas /profile /env /user:username#domain compmgmt.msc
After I authenticate I get an error telling me "compmgmt.msc is not a valid Win32 application.
runas /profile /env /user:username#domain mmc
After I authenticate I get an error telling me "The requested operation requires elevation"
If I run the good cmd option then type in either mmc or compmgmt.msc, the program will open as admin because I'm in cmd as admin already. I'm assuming there's a way to add onto the good cmd command to autopopulate that text into cmd and run it, but I don't know what it is. I'm also open to trying other options, really I just want a tool that works. I know that I can run my batch as admin and avoid all of this but the purpose of this tool is to not have to provide my admin username.
Suggestions?
runas /user:username#domain "cmd.exe /c \"start compmgmt.msc\""
If the .msc runs correctly from cmd, start cmd under the adecuated account and, from here, start the .msc
The problem is that you cannot run an .msc plugin without calling mmc.
The correct call should be in this format:mmc.exe \location of plugin
runas /u:domain\user "mmc.exe \windows\system32\compmgmt.msc"
The start command will also work but relies on the extensions being properly entered in the registry. I usually do mmc \plugin location due to the different windows operating systems we use and the fact that usually half the plugins I want to use are not registered on the system for some reason.
better you travel to that location and then execute that file
You can write batch file which will run:
(CompMgmtLauncher.exe or CompMgmt.msc)
It'll look like
C:\Users\Admin>cd\
C:>cd Windows
C:\Windows>cd System32
C:\Windows\System32>CompMgmtLauncher.exe
C:\Windows\System32>compmgmt.msc
C:\Windows\System32>

How to use RunAs Cmd to Launch Explorer, Windows 8

any idea why this is not working?
runas.exe /user:Administrator "cmd /c explorer"
it returns:
Windows cannot find the specified file. You may not have appropriate
permissions.
the following works by itself:
cmd /c explorer
thx!
Answer found here
http://winaero.com/blog/how-to-run-explorer-as-administrator-on-windows-8-1-windows-8-and-windows-7/
"Microsoft does not allow running Explorer as administrator in Windows 8.1/8 (and in Windows 7 too). The solution to run Explorer elevated...
1- take ownership of registry key below.
Right-click, Permissions, Advanced, Owner Change
or, Use Winaero's RegOwnershipEx application, which allows you to take ownership of registry keys
HKEY_CLASSES_ROOT\AppID{CDCBCFCA-3CDC-436f-A4E2-0E02075250C2}
2- rename or delete the value named 'RunAs'.
3- now Restore Ownership (this failed for me done manually-- i could not re-add TrustedInstaller --user not found).
4- at this point, you will be able to run explorer as admin
5- this process does not cleanly exit when you close the Explorer window! You must remember to terminate it every time you elevate Explorer after you are done working in the Explorer window.
Alternate solution: use Winaero's ELE.exe app to start any program as administrator from the command line.
Usually one wants to run as an Administrator to edit a file, or get permissions to delete a file:
To get to the permissions on a file you can right click on it and select Properties. Then select Security. You will see this dialog:
Then Click on Edit and change the permissions for the relevant user (e.g Mike).
You need to have admin privileges to do this, which can be set via User Account Control.
The File Permissions window looks like this:
Edit as required.
I have admin rights but Windows 8.1 still protects some system files (such as the Android studio.exe.vmoptions) and I used the above method to give me write access to the file.
Hope this helps.
You could always open a dos prompt as Administrator then go to the directory in question then do a Explorer . then it will open the location in question as the elevated user.

Open Excel on Jenkins CI

I am working on Windows 7 (logged in as session no.1), my Jenkins CI is running as windows service in session 0.
My problem is.. I want to open an Excel file through Jenkins CI in session 0, but want to display its GUI on session 1.
I know that session 0 is isolated in Windows 7, but is it possible to run a process in session 0 and then output in another session? please help.
Edit:
Took a little trial and error, but this is what finally worked for me (Windows 7 64-bit).
Download PsTools from Microsoft site
We only need psexec.exe, but you can extract everything. Extract to some location accessible by Jenkins, preferably without spaces in the path.
Open elevated command prompt: type cmd into Start's quicksearch, right click cmd.exe, select Run as Administrator.
Type C:\path\to\psexec.exe -accepteula and press enter.
Type C:\path\to\psexec.exe -i 1 cmd and press enter. (If you see a command prompt appear, all is good, close it now)
In Job configuration, configure Execute Windows Batch command step
Write the following:
C:\path\to\psexec.exe -accepteula && C:\path\to\psexec.exe -i 1 cmd /c start C:\PROGRA~2\MICROSO~1\path\to\excel.exe
Where:
C:\path\to is your full path to psexec.exe, unless it is in your %path%
-i 1 is the session ID that you want to launch in.
C:\PROGRA~2\MICROSO~1\path\to is your full path to excel.exe without spaces. Since most Office installations are going to be under paths with spaces, like "Program Files (x86), you have to figure out the short path, or place it somewhere without spaces.
Having excel.exe under %path% and working from regular command line was not enough.
A little explanation for those that care:
psexec needs to install a services first. For that, it needs to be run from elevated command prompt for the first time. This is a one-time installation step.
To make psexec work, you need to accept the EULA prompt. This is done per session/user. So even if you run psexec -accepteula in your command prompt, it doesn't help when Jenkins service (running as Local System in session 0) tries to use it. Therefore, you have to place that into the Jenkins job, along with the command. Technically, it only needs to be there once, and can be removed afterwards, but it definitely doesn't hurt to keep it there.
I've used cmd /k and running this command from my local cmd prompt to debug. This is what made me realize I couldn't find a way to escape the spaces (tried various quoting), so had to resort to short file names. Note that short file names are not required, this is just to escape spaces.
no its not-
plus any UI interactions requires you to run Jenkins as Java web start rather than a service or you can not interact with UI elements.

Get vim to write files to Program Files in Windows

When I create and open a file with vim, i.e. "vim new.txt" it works fine in a folder like my desktop. However, when I am in "C:\Program Files (x86)\Vim\vimfiles\ftplugin\" and I try to create a file with "vim python.vim" or "vim new.txt", vim opens and appears to work fine, but after I save the file and exit vim, it does not exist in the folder. HOWEVER, if I type "vim python.vim" again to re-open the (apparently non-existent) file, vim comes up happily right where I left off in the file that doesn't exist. Can someone tell me what is going on and how to fix it?
Edit: A search of my filesystem for the nonexistent files shows them to in "C:\Users\Daniel\AppData\Local\VirtualStore\Program Files (x86)\Vim\vimfiles\ftplugin" instead of the "C:\Program Files (x86)\Vim\vimfiles\ftplugin\" from which they were created. Any ideas why, though, and how to make this not happen?
What you're experiencing is the file system redirection of the %ProgramFiles% location (the same is done for the Windows system files under %WINDIR%), because you're not running under an elevated account. Starting with Windows Vista, when User Account Control (UAC) is enabled, you cannot directly access system files and installed applications any more (for security reasons). Windows detects software installers and prompts you to elevate the account, but it doesn't detect Vim's accesses, and (for backward compatibility) redirects those accesses to the VirtualStore.
There are several ways around this:
Turn off UAC (bad idea, lower security)
Start an elevated instance of GVIM (search for gvim in the Start Menu, and select with Ctrl + Shift + Enter), and edit with that.
Avoid the problem by creating a vimfiles directory at %HOME% (C:\Users\Daniel for you) instead of $VIM/vimfiles and put your config there (see :help vimrc).

How to use runas command in windows 2008 r2 server?

I have written a batch file which will call another batch file and delete some files. For this I need to have admin rights. I tried following command...
runas /user:bala#nsc cmd
Enter the password for bala#nsc: xxxxxxx
Even though bala#nsc has admin rights command prompt is getting opened as a simple user rather than administrator.
I guess, I am missing something. Please help me.
Your results aren't what I expected, either. But I've got a few workarounds to suggest.
You could turn off User Account Control.
You could go to Start --> All Programs --> Accessories, then right-click on "Command Prompt" and choose "Run as Administrator."
You could right-click on your batch script and do the same.
You could create a shortcut to either cmd or your batch script on your Desktop, then modify the properties of that shortcut to run as Administrator.
You could add some code to your batch script to check for admin privileges and prompt for escalation if needed.
Turning off UAC would be my choice.

Resources