WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

UAC

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Protected Directories

 Keywords:  Windows Root Program Files Windir SysWOW64 SysNative Copy Delete FileCopy FileDelete UAC Protected Directories Folders 

Question:

Hello, I am a registered user of an older version, WinBatch 2002. I have also purchased the Compiler. Version 2002 has always worked for me, so I've never needed to upgrade. However, I've run into a snag. I'd be willing to upgrade to the current version of WinBatch, but I want to be sure my problem can be handled by the new version.

I wrote a script that needs to delete/copy certain files in C:\Windows, and C:\Windows\SysWOW64. However, my version of WinBatch is unable to delete or copy files into system folders on 64-bit Windows 7. Would I be able to do file operations into system folders using WinBatch 2010?

Answer:

Yes, there have been lots of improvements in WinBatch for the latest Windows platforms. It sounds like you are dealing with a UAC problem.

The C:\Windows, and C:\Windows\SysWOW64 are special 'UAC Protected' directories on Windows 7. Usually if a script is trying to write to a UAC Protected directory, it means the script needs to be run with administrative privileges.

UAC definitely introduces some difficult scripting implications. Especially for processes that need to run elevated. Note, we have found the most consistently reliable option for WinBatch script installs is to use the Windows Task Scheduler to run an install as a logon task. Basically this causes the script to run as a service and you will not receive any UAC prompts when running from the task scheduler. You will need to familiarize yourself with the Windows Task Scheduler. Here is a link to the Windows Task Scheduler application: http://technet.microsoft.com/en-us/library/cc721871.aspx

Here is are a few links for more about UAC: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/UAC+UAC~Help.txt http://msdn.microsoft.com/en-us/library/aa905330.aspx http://msdn.microsoft.com/en-us/library/cc709691(WS.10).aspx

Now, lets assume your script is being run using an ADMIN account, then the next issue you might run into is 'File System Redirection'. WinBatch is a 32 bit application. When it is run a 64 bit Windows platform the Windows file system auto-magically redirects file operations that refer to 64 bit directories to the 32 bit equivalents. For example, the %windir%\System32 directory is reserved for 64-bit applications. Since most System DLL file names were not changed when porting to 64-bit, 32-bit applications must use a different directory as their System32 directory. WOW64 hides this difference using file system redirection. Whenever a 32-bit application,like WinBatch, attempts to access %windir%\System32, the access is redirected to a new directory, %windir%\SysWOW64. IntControl 92 can be used to disable this functionality.

Disabling file system redirection affects all file operations performed by the script, so it should be disabled only when necessary for a single call and re-enabled again immediately after the function returns. Disabling file system redirection for longer periods can prevent WinBatch from loading system DLLs, causing the it to fail.

NOTE: It is REALLY important to minimize the code run when the File System Redirection is disabled, especially when loading WIL Extenders, using COM / OLE, or doing anything that asks Windows to load any new DLLs. The problem is that while File System Redirection is disabled, your code will be looking at the wrong version of windows and will attempt to load wrong (64 instead of 32 bit) versions of modules, and usually fail, GPF, or otherwise not function properly.

32-bit applications can also access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.

Details: http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx

So assuming you are not attempting to do something that is not supported by the operating system, then you can feel confident that updating your version of WinBatch is in your best interest.


Article ID:   W18317
Filename:   Protected Directories.txt
File Created: 2014:07:18:09:51:40
Last Updated: 2014:07:18:09:51:40